Class: SmartVkApi::Methods::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_vk_api/methods.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vk, scope) ⇒ Proxy

Returns a new instance of Proxy.



21
22
23
24
# File 'lib/smart_vk_api/methods.rb', line 21

def initialize(vk, scope)
  self.vk = vk
  self.scope = scope
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



26
27
28
29
# File 'lib/smart_vk_api/methods.rb', line 26

def method_missing(method_name, *arguments, &block)
  method_name = Proxy.camelcase(method_name)
  vk.call("#{scope}.#{method_name}", arguments.first)
end

Instance Attribute Details

#scopeObject

Returns the value of attribute scope.



13
14
15
# File 'lib/smart_vk_api/methods.rb', line 13

def scope
  @scope
end

#vkObject

Returns the value of attribute vk.



12
13
14
# File 'lib/smart_vk_api/methods.rb', line 12

def vk
  @vk
end

Class Method Details

.camelcase(method_name) ⇒ Object



15
16
17
18
19
# File 'lib/smart_vk_api/methods.rb', line 15

def self.camelcase(method_name)
  result = method_name.to_s.split('_').map(&:capitalize).join
  result[0] = result[0].downcase
  result
end

Instance Method Details

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

Returns:

  • (Boolean)


31
32
33
# File 'lib/smart_vk_api/methods.rb', line 31

def respond_to?(method_name, include_private = false)
  true # we should respond to any method using Proxy
end