Module: Taxonomix::InstanceMethods
- Defined in:
- app/models/taxonomix.rb
Instance Method Summary collapse
- #add_current_location? ⇒ Boolean
- #add_current_organization? ⇒ Boolean
- #add_current_taxonomy?(taxonomy) ⇒ Boolean
- #set_current_taxonomy ⇒ Object
Instance Method Details
#add_current_location? ⇒ Boolean
50 51 52 |
# File 'app/models/taxonomix.rb', line 50 def add_current_location? add_current_taxonomy?(:location) end |
#add_current_organization? ⇒ Boolean
46 47 48 |
# File 'app/models/taxonomix.rb', line 46 def add_current_organization? add_current_taxonomy?(:organization) end |
#add_current_taxonomy?(taxonomy) ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/taxonomix.rb', line 54 def add_current_taxonomy?(taxonomy) klass, association = case taxonomy when :organization [Organization, :organizations] when :location [Location, :locations] else raise ArgumentError, "unknown taxonomy #{taxonomy}" end current_taxonomy = klass.current Taxonomy.enabled?(taxonomy) && current_taxonomy && !self.send(association).include?(current_taxonomy) end |
#set_current_taxonomy ⇒ Object
39 40 41 42 43 44 |
# File 'app/models/taxonomix.rb', line 39 def set_current_taxonomy if self.new_record? && self.errors.empty? self.locations << Location.current if add_current_location? self.organizations << Organization.current if add_current_organization? end end |