Class: SupplejackApi::SetItem
- Inherits:
-
Object
- Object
- SupplejackApi::SetItem
- Includes:
- Mongoid::Document
- Defined in:
- app/models/supplejack_api/set_item.rb
Constant Summary collapse
- ATTRIBUTES =
RecordSchema.groups[:sets].fields
Instance Attribute Summary collapse
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
- #not_adding_set_to_itself ⇒ Object
- #reindex_record ⇒ Object
-
#set_position ⇒ Object
Set the default position as the last in the set, if not defined.
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record.
15 16 17 |
# File 'app/models/supplejack_api/set_item.rb', line 15 def record @record end |
Instance Method Details
#not_adding_set_to_itself ⇒ Object
29 30 31 32 33 |
# File 'app/models/supplejack_api/set_item.rb', line 29 def not_adding_set_to_itself return unless user_set.record && record_id == user_set.record.record_id errors.add(:set, "can't be added to itself") end |
#reindex_record ⇒ Object
53 54 55 |
# File 'app/models/supplejack_api/set_item.rb', line 53 def reindex_record SupplejackApi::Record.custom_find(record_id).index rescue nil end |
#set_position ⇒ Object
Set the default position as the last in the set, if not defined.
46 47 48 49 50 51 |
# File 'app/models/supplejack_api/set_item.rb', line 46 def set_position return if position positions = user_set.set_items.map(&:position) self.position = positions.compact.max.to_i + 1 end |