Created
September 6, 2012 22:16
-
-
Save ivanacostarubio/3660809 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Lead | |
| @@filter_options = ["followup","skype", "documents", "estimate"] | |
| @@all_options = ["followup","skype", "documents", "won", "lost", "estimate"] | |
| validates :status, :inclusion => { :in => @@all_options} | |
| validates_presence_of :status, :name_project, :name_client, :url_project | |
| def self.filter_options | |
| @@filter_options | |
| end | |
| def self.filter_all_options | |
| @@all_options | |
| end | |
| def self.filter_by_status(status) | |
| where(:status => status) | |
| end | |
| def self.sorted_by_status | |
| Lead.filter_options.each do |status| | |
| instance_variable_set("@" + status, Lead.where(:status => status)) | |
| end | |
| all = Array.new | |
| Lead.filter_options.each do |status| | |
| local = instance_variable_get("@" + status) | |
| all += local.to_a | |
| end | |
| all | |
| end | |
| def self.all_sorted_by_status | |
| Lead.filter_all_options.each do |status| | |
| instance_variable_set("@" + status, Lead.where(:status => status)) | |
| end | |
| all = Array.new | |
| Lead.filter_all_options.each do |status| | |
| local = instance_variable_get("@" + status) | |
| all += local.to_a | |
| end | |
| all | |
| end | |
| end | |
| VS | |
| class Lead | |
| @@all_options = ["followup","skype", "documents", "won", "lost", "estimate"] | |
| def self.sorted_by_status | |
| self.abstract_sorted(index_filter) | |
| end | |
| def self.all_sorted_by_status | |
| self.abstract_sorted(filter_all_opctions) | |
| end | |
| def self.abstract_sorted(collection) | |
| all = Array.new | |
| collection.each do |status| | |
| instance_variable_set("@" + status, Lead.where(:status => status)) | |
| end | |
| collection.each do |status| | |
| local = instance_variable_get("@" + status) | |
| all += local.to_a | |
| end | |
| all | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment