Class: SupplejackApi::SetItem

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/supplejack_api/set_item.rb

Constant Summary collapse

ATTRIBUTES =
RecordSchema.groups[:sets].fields

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#recordObject

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_itselfObject


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_recordObject


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_positionObject

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