Module: MarkMapper::Plugins::EmbeddedCallbacks::ClassMethods

Defined in:
lib/mark_mapper/plugins/embedded_callbacks.rb

Instance Method Summary collapse

Instance Method Details

#define_callbacks(*args) ⇒ Object


22
23
24
25
# File 'lib/mark_mapper/plugins/embedded_callbacks.rb', line 22

def define_callbacks(*args)
  embedded_callbacks_on if @embedded_callbacks_status.nil?
  super
end

#embedded_callbacks_offObject


31
32
33
# File 'lib/mark_mapper/plugins/embedded_callbacks.rb', line 31

def embedded_callbacks_off
  @embedded_callbacks_status = false
end

#embedded_callbacks_off?Boolean

Returns:


39
40
41
# File 'lib/mark_mapper/plugins/embedded_callbacks.rb', line 39

def embedded_callbacks_off?
  !@embedded_callbacks_status
end

#embedded_callbacks_onObject


27
28
29
# File 'lib/mark_mapper/plugins/embedded_callbacks.rb', line 27

def embedded_callbacks_on
  @embedded_callbacks_status = true
end

#embedded_callbacks_on?Boolean

Returns:


35
36
37
# File 'lib/mark_mapper/plugins/embedded_callbacks.rb', line 35

def embedded_callbacks_on?
  !!@embedded_callbacks_status
end

#proxy_callbacks(definition) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mark_mapper/plugins/embedded_callbacks.rb', line 43

def proxy_callbacks(definition)
  definition.each do |prefix, suffixes|
    suffixes.each do |suffix|
      callback = "%s_%s" % [prefix, suffix]
      class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
        class << self
          alias_method :__original_#{callback}, :#{callback}

          def #{callback}(*args, &block)
            embedded_callbacks_on if @embedded_callbacks_status.nil?
            __original_#{callback}(*args, &block)
          end
        end
      CALLBACK
    end
  end
end