Class: Invokr::Method

Inherits:
Struct
  • Object
show all
Defined in:
lib/invokr/method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



2
3
4
# File 'lib/invokr/method.rb', line 2

def method
  @method
end

Instance Method Details

#dependenciesObject



17
18
19
# File 'lib/invokr/method.rb', line 17

def dependencies
  map_identifiers parameters
end

#invoke(args = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/invokr/method.rb', line 3

def invoke args = {}
  receiver, method_name, hsh_args = extract_args! args
  unless receiver == method.owner or receiver.kind_of? method.owner
    raise TypeError, "no implicit conversion of #{receiver.class} into #{method.owner.name}"
  end
  invocation = Builder.build method, hsh_args, args[:block]
  invocation.method = method_name unless method_name == method.name
  invocation.invoke! receiver
end

#optional_dependenciesObject



21
22
23
# File 'lib/invokr/method.rb', line 21

def optional_dependencies
  map_identifiers select_parameters_by_type [:opt, :key]
end

#parametersObject



29
30
31
# File 'lib/invokr/method.rb', line 29

def parameters
  method.parameters
end

#required_dependenciesObject



25
26
27
# File 'lib/invokr/method.rb', line 25

def required_dependencies
  map_identifiers select_parameters_by_type [:req, :keyreq]
end

#trim_args(hsh_args) ⇒ Object



13
14
15
# File 'lib/invokr/method.rb', line 13

def trim_args hsh_args
  hsh_args.select { |key, _| dependencies.include? key }
end