Module: ActsAsListAR

Defined in:
lib/acts_as_list_ar.rb,
lib/acts_as_list_ar/rails2.rb,
lib/acts_as_list_ar/rails3.rb

Overview

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



75
76
77
78
# File 'lib/acts_as_list_ar/rails2.rb', line 75

def self.included(receiver)
  receiver.extend         ClassMethods
  receiver.send :include, InstanceMethods
end

Instance Method Details

#acts_as_list(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
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
51
52
53
# File 'lib/acts_as_list_ar.rb', line 7

def acts_as_list(options = {})
  raise ArgumentError, "Hash expected, got #{options.class.name}" if !options.is_a?(Hash) && !options.empty?        
  configuration = { :column => "position", :scope => "'deleted_at IS NULL OR deleted_at IS NOT NULL'" }
  configuration.update(options) if options.is_a?(Hash)

  configuration[:scope] = "#{configuration[:scope]}_id".intern if configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/

  if configuration[:scope].is_a?(Symbol)
    scope_condition_method = %(
      def scope_condition
        if #{configuration[:scope].to_s}.nil?
          "#{configuration[:scope].to_s} IS NULL"
        else
          "#{configuration[:scope].to_s} = #{configuration[:scope].to_s}"
        end
      end
    )
  else
    scope_condition_method = "def scope_condition() \"#{configuration[:scope]}\" end"
  end

  class_eval "    def self.with_acts_as_list_scope(scope_conditions)\n      clazz = self # not sure this works!\n      with_scope :find => {:conditions => scope_conditions} do\n        if block\n          block.arity < 1 ? clazz.instance_eval(&block) : block.call(clazz) \n        end\n      end\n    end            \n\n    def acts_as_list_class\n      self.class\n    end\n\n    def position_column\n      '\#{configuration[:column]}'\n    end\n\n    \#{scope_condition_method}\n\n    before_destroy :eliminate_current_position\n    before_create  :add_to_list_bottom_when_necessary \n  EOV\n  \n  include InstanceMethods\nend\n"   

#scope_nameObject



3
4
5
# File 'lib/acts_as_list_ar.rb', line 3

def scope_name
  "named_scope"
end