Class: ActiveRecord::Events::MethodFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/events/method_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_name, options) ⇒ MethodFactory

Returns a new instance of MethodFactory.



6
7
8
9
10
11
# File 'lib/active_record/events/method_factory.rb', line 6

def initialize(event_name, options)
  @options = options
  @naming = Naming.new(event_name, options)
  @strategy = options[:strategy].try(:to_sym)
  @field_type = options[:field_type].try(:to_sym)
end

Instance Method Details

#class_methodsObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_record/events/method_factory.rb', line 23

def class_methods
  Module.new.tap do |module_|
    time_class = field_type == :date ? Date : Time

    define_collective_action_method(module_, naming, time_class)

    unless options[:skip_scopes]
      define_scope_method(module_, naming, strategy, time_class)
      define_inverse_scope_method(module_, naming, strategy, time_class)
    end
  end
end

#instance_methodsObject



13
14
15
16
17
18
19
20
21
# File 'lib/active_record/events/method_factory.rb', line 13

def instance_methods
  Module.new.tap do |module_|
    define_predicate_method(module_, naming, strategy)
    define_inverse_predicate_method(module_, naming)

    define_action_method(module_, naming)
    define_safe_action_method(module_, naming)
  end
end