Class: UserApp::ProxyClient
- Inherits:
-
Object
- Object
- UserApp::ProxyClient
- Defined in:
- lib/userapp/userapp.rb,
lib/userapp/proxy_client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#service_name ⇒ Object
Returns the value of attribute service_name.
-
#services ⇒ Object
Returns the value of attribute services.
Instance Method Summary collapse
- #get_options ⇒ Object
-
#initialize(*args) ⇒ ProxyClient
constructor
A new instance of ProxyClient.
- #method_missing(method_id, *args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ProxyClient
Returns a new instance of ProxyClient.
12 13 14 15 16 17 18 19 20 |
# File 'lib/userapp/proxy_client.rb', line 12 def initialize(*args) @services = Hash.new() if args.length == 2 and args[0].is_a?(Client) @client = args[0] @service_name = args[1] else @client = Client.new(*args) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/userapp/proxy_client.rb', line 26 def method_missing(method_id, *args) if args.length > 0 if self.service_name.nil? raise UserApp::Error.new("Unable to call method on base service.") end self.client.call(self.().version, self.service_name, self.camel_case_lower(method_id.to_s()), args[0]) else target_service = nil if self.services[method_id] return self.services[method_id] end if self.service_name.nil? and method_id.length >= 2 and method_id[0] == 'v' and method_id[1, method_id.length-1].match(/\A[0-9]+\Z/) self.().version = method_id[1].to_i else if !self.service_name.nil? target_service = self.service_name.to_s + '.' + self.camel_case_lower(method_id.to_s) else target_service = self.camel_case_lower(method_id.to_s) end end proxy = ProxyClient.new(self.client, target_service) self.services[method_id] = proxy return proxy end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/userapp/proxy_client.rb', line 8 def client @client end |
#service_name ⇒ Object
Returns the value of attribute service_name.
10 11 12 |
# File 'lib/userapp/proxy_client.rb', line 10 def service_name @service_name end |
#services ⇒ Object
Returns the value of attribute services.
9 10 11 |
# File 'lib/userapp/proxy_client.rb', line 9 def services @services end |
Instance Method Details
#get_options ⇒ Object
22 23 24 |
# File 'lib/userapp/proxy_client.rb', line 22 def () return self.client.() end |