Class: Mengpaneel::CallProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mengpaneel/call_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name = nil, args = []) ⇒ CallProxy

Returns a new instance of CallProxy.


7
8
9
10
11
12
# File 'lib/mengpaneel/call_proxy.rb', line 7

def initialize(method_name = nil, args = [])
  @method_name  = method_name
  @args         = args

  @calls = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object


14
15
16
# File 'lib/mengpaneel/call_proxy.rb', line 14

def method_missing(method_name, *args)
  save_call(method_name, *args)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args


4
5
6
# File 'lib/mengpaneel/call_proxy.rb', line 4

def args
  @args
end

#callsObject (readonly)

Returns the value of attribute calls


5
6
7
# File 'lib/mengpaneel/call_proxy.rb', line 5

def calls
  @calls
end

#method_nameObject (readonly)

Returns the value of attribute method_name


3
4
5
# File 'lib/mengpaneel/call_proxy.rb', line 3

def method_name
  @method_name
end

Instance Method Details

#all_calls(prefixes = []) ⇒ Object


35
36
37
38
39
40
# File 'lib/mengpaneel/call_proxy.rb', line 35

def all_calls(prefixes = [])
  calls = []
  calls << to_call(prefixes) if self.method_name && (@calls.empty? || !@args.empty?)
  calls += child_calls(prefixes)
  calls
end

#child_calls(prefixes = []) ⇒ Object


30
31
32
33
# File 'lib/mengpaneel/call_proxy.rb', line 30

def child_calls(prefixes = [])
  method_name = full_method_name(prefixes)
  @calls.flat_map { |proxy| proxy.all_calls(method_name) }
end

#full_method_name(prefixes) ⇒ Object


22
23
24
# File 'lib/mengpaneel/call_proxy.rb', line 22

def full_method_name(prefixes)
  [*prefixes, *self.method_name]
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/mengpaneel/call_proxy.rb', line 18

def respond_to_missing?(method_name, include_private = false)
  true
end

#to_call(prefixes = []) ⇒ Object


26
27
28
# File 'lib/mengpaneel/call_proxy.rb', line 26

def to_call(prefixes = [])
  [full_method_name(prefixes), args] if self.method_name
end