Class: Dominion::Invoker
- Inherits:
-
Object
- Object
- Dominion::Invoker
- Defined in:
- lib/dominion.rb
Instance Method Summary collapse
- #for?(path) ⇒ Boolean
-
#initialize(path) ⇒ Invoker
constructor
A new instance of Invoker.
- #invoke(args) ⇒ Object
- #options=(options) ⇒ Object
Constructor Details
#initialize(path) ⇒ Invoker
Returns a new instance of Invoker.
102 103 104 105 |
# File 'lib/dominion.rb', line 102 def initialize(path) @path = path @options = {} end |
Instance Method Details
#for?(path) ⇒ Boolean
111 112 113 |
# File 'lib/dominion.rb', line 111 def for?(path) @path == path || path.to_s == '*' end |
#invoke(args) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/dominion.rb', line 115 def invoke(args) top = case @options[:top] when Class, Module @options[:top].name else @options[:top] end elements = @path.split(/:/) method = elements.pop klass = [top].concat(elements.map(&:classify)).compact.join('::').constantize if klass.instance_method(method).arity == 1 klass.new.send(method, args) else klass.new.send(method) end end |
#options=(options) ⇒ Object
107 108 109 |
# File 'lib/dominion.rb', line 107 def () @options.merge!() end |