Module: Direction

Defined in:
lib/direction.rb,
lib/direction/version.rb

Overview

relationship between objects.

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_methods(mod, options) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/direction.rb', line 42

def self.define_methods(mod, options)
  method_defs = []
  options.each_pair do |method_names, accessor|
    Array(method_names).map do |message|
      method_defs.unshift yield(message, accessor)
    end
  end
  mod.class_eval method_defs.join("\n"), __FILE__, __LINE__
end

Instance Method Details

#command(options) ⇒ Object

Forward messages and return self, protecting the encapsulation of the object



20
21
22
23
24
25
26
27
28
29
# File 'lib/direction.rb', line 20

def command(options)
  Direction.define_methods(self, options) do |message, accessor|
    %{
    def #{message}(*args, &block)
      #{accessor}.__send__(:#{message}, *args, &block)
      self
    end
    }
  end
end

#query(options) ⇒ Object

Forward messages and return the result of the forwarded message



32
33
34
35
36
37
38
39
40
# File 'lib/direction.rb', line 32

def query(options)
  Direction.define_methods(self, options) do |message, accessor|
    %{
    def #{message}(*args, &block)
      #{accessor}.__send__(:#{message}, *args, &block)
    end
    }
  end
end