Class: Selections::Selection
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Selections::Selection
- Defined in:
- app/models/selections/selection.rb
Constant Summary collapse
- VERSION =
"0.1"
- HIDDEN_POSITION =
999888777
Class Method Summary collapse
Instance Method Summary collapse
- #archived ⇒ Object
- #archived=(archived_set) ⇒ Object
- #auto_gen_system_code ⇒ Object
- #check_defaults ⇒ Object
- #disable_system_code_change ⇒ Object
- #position ⇒ Object
- #position=(value) ⇒ Object
- #siblings_with_default_set ⇒ Object
- #to_s ⇒ Object
Class Method Details
.method_missing(lookup_code, *options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/selections/selection.rb', line 58 def self.method_missing lookup_code, * if (scope = Selection.where(:system_code => lookup_code.to_s)) && scope.exists? scope.first elsif (scope = Selection.where(:system_code => lookup_code.to_s.singularize)) && scope.exists? scope.first.children else super end end |
Instance Method Details
#archived ⇒ Object
69 70 71 |
# File 'app/models/selections/selection.rb', line 69 def archived !!archived_at end |
#archived=(archived_set) ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/models/selections/selection.rb', line 73 def archived=(archived_set) if archived_set self.archived_at = Time.now unless archived_at else self.archived_at = nil end end |
#auto_gen_system_code ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/models/selections/selection.rb', line 39 def auto_gen_system_code unless system_code if parent self.system_code = parent.system_code + "_" + name.to_s.underscore.split(" ").join("_").singularize.underscore else self.system_code = name.to_s.underscore.split(" ").join("_").singularize.underscore end end end |
#check_defaults ⇒ Object
49 50 51 52 |
# File 'app/models/selections/selection.rb', line 49 def check_defaults siblings_with_default_set.update_attribute(:is_default, false) if self.parent && siblings_with_default_set && self.is_default self.is_default = false if archived end |
#disable_system_code_change ⇒ Object
31 32 33 |
# File 'app/models/selections/selection.rb', line 31 def disable_system_code_change errors.add(:system_code, "cannot be changed") if system_code_changed? end |
#position ⇒ Object
35 36 37 |
# File 'app/models/selections/selection.rb', line 35 def position position_value unless position_value == HIDDEN_POSITION end |
#position=(value) ⇒ Object
27 28 29 |
# File 'app/models/selections/selection.rb', line 27 def position=(value) self.position_value = value || HIDDEN_POSITION end |
#siblings_with_default_set ⇒ Object
54 55 56 |
# File 'app/models/selections/selection.rb', line 54 def siblings_with_default_set self.parent.children.where(:is_default => true).where("id != #{self.id.to_i}").first end |
#to_s ⇒ Object
23 24 25 |
# File 'app/models/selections/selection.rb', line 23 def to_s name.to_s end |