Module: DataMapper::Is::List::ClassMethods

Defined in:
lib/dm-is-list/is/list.rb

Overview

is_list

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#list_optionsObject (readonly)

Returns the value of attribute list_options.



304
305
306
# File 'lib/dm-is-list/is/list.rb', line 304

def list_options
  @list_options
end

Instance Method Details

#repair_list(scope = {}) ⇒ Object

use this function to repair / build your lists.

Examples:

Usage

MyModel.repair_list # repairs the list, given that lists are not scoped
MyModel.repair_list(:user_id => 1) # fixes the list for user 1, given that the scope is [:user_id]

Parameters:

  • scope (Hash) (defaults to: {})


316
317
318
319
320
321
322
323
# File 'lib/dm-is-list/is/list.rb', line 316

def repair_list(scope = {})
  return false unless scope.keys.all?{ |s| list_options[:scope].include?(s) || s == :order }
  retval = true
  all({ :order => [ :position.asc ] | default_order }.merge(scope)).each_with_index do |item, index|
    retval &= item.update(:position => index.succ)
  end
  retval
end