Module: Mongoid::Listable::Accessors::ClassMethods
- Defined in:
- lib/mongoid/listable/accessors.rb
Instance Method Summary collapse
-
#ids_set(name, meta) ⇒ Object
Redefines the default ids setter, ensuring that the order of objects sent to the relation setter corresponds to the order of the array of ids.
-
#set(name, meta) ⇒ Object
Prepends to the default setter a block that sets the position attribute on each object according to its index in the array.
Instance Method Details
#ids_set(name, meta) ⇒ Object
Redefines the default ids setter, ensuring that the order of objects sent to the relation setter corresponds to the order of the array of ids
19 20 21 22 23 24 25 |
# File 'lib/mongoid/listable/accessors.rb', line 19 def ids_set name, ids_method = "#{name.to_s.singularize}_ids=" redefine_method ids_method do |ids| send .setter, .klass.find(ids).sort_by_attr(:id, ids) end self end |
#set(name, meta) ⇒ Object
Prepends to the default setter a block that sets the position attribute on each object according to its index in the array
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mongoid/listable/accessors.rb', line 36 def set name, before_method "#{name}=" do |objects| objects ||= [] reposition objects, position_field_name(), 1 (send(name).to_a - objects).each do |object| object.unset position_field_name() end end self end |