Class: Object

Inherits:
BasicObject
Defined in:
lib/dm2/unit_of_work/observer_definition.rb

Class Method Summary collapse

Class Method Details

.define_value_method(method_name) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/dm2/unit_of_work/observer_definition.rb', line 25

def self.define_value_method method_name
  modified_method = modified_method_name method_name
  define_method method_name.to_s do |*args, &block|
    returned = send modified_method, *args, &block
    Kernel.const_get("#{self.class}Mapper").unit_of_work self, method_name, args
    returned
  end
end

.has_mapper?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/dm2/unit_of_work/observer_definition.rb', line 19

def self.has_mapper?
  Module.const_defined?("#{self}Mapper")
rescue
  false
end

.method_added(name) ⇒ Object



2
3
4
5
6
7
# File 'lib/dm2/unit_of_work/observer_definition.rb', line 2

def self.method_added name
  return true unless has_mapper?
  return if @__last_methods_added && @__last_methods_added.include?(name)
  return if self.methods.include?(name) && name != :name
  send :set_unit_of_work_observer, name
end

.modified_method_name(method_name) ⇒ Object



34
35
36
# File 'lib/dm2/unit_of_work/observer_definition.rb', line 34

def self.modified_method_name method_name
  :"modified_#{method_name}"
end

.set_unit_of_work_observer(method_name) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/dm2/unit_of_work/observer_definition.rb', line 9

def self.set_unit_of_work_observer method_name
  modified_method = :"modified_#{method_name}"
  @__last_methods_added = [method_name, modified_method]

  alias_method modified_method, method_name
  define_value_method method_name

  @__last_methods_added = nil
end