Class: Kobana::Client::ResourceProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/kobana/client.rb

Overview

Generic proxy for all resource modules

Instance Method Summary collapse

Constructor Details

#initialize(client, module_ref) ⇒ ResourceProxy

Returns a new instance of ResourceProxy.



35
36
37
38
# File 'lib/kobana/client.rb', line 35

def initialize(client, module_ref)
  @client = client
  @module = module_ref
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kobana/client.rb', line 40

def method_missing(method_name, *args, &)
  # Convert method name to class name (e.g., :pix => Pix, :account_balance => AccountBalance)
  class_name = method_name.to_s.split("_").map(&:capitalize).join

  # Try to find the resource class
  if @module.const_defined?(class_name)
    resource_class = @module.const_get(class_name)
    # Return a client-bound version of the class
    resource_class.with_client(@client)
  else
    super
  end
end

Instance Method Details

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

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/kobana/client.rb', line 54

def respond_to_missing?(method_name, include_private = false)
  class_name = method_name.to_s.split("_").map(&:capitalize).join
  @module.const_defined?(class_name) || super
end