19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/mongoid/acts_as_list.rb', line 19
def acts_as_list(options = {})
configuration = { :column => 'position' }
configuration.update(options) if options.is_a?(Hash)
if configuration[:scope]
configuration[:scope] = configuration[:scope].to_sym
configuration[:scope] = "#{configuration[:scope]}_id".intern if configuration[:scope].to_s !~ /_id$/
end
define_method :position_column do
configuration[:column].to_s
end
if !configuration[:scope]
define_method :scope_condition do
{position_key.ne => nil}
end
elsif configuration[:scope].is_a?(Symbol)
define_method :scope_condition do
{configuration[:scope] => self[configuration[:scope]]}
end
else
raise ArgumentError, "acts_as_list must either take a valid :scope option or be in an embedded document and use the parent document as scope"
end
include ::Mongoid::EmbeddedHelper
include InstanceMethods
include Fields
include Triggers
extend Fields
extend ClassMethods
end
|