Class: Coach4rb::Proxy::Base
- Inherits:
-
Object
- Object
- Coach4rb::Proxy::Base
- Includes:
- Mixin::BasicAuth
- Defined in:
- lib/coach4rb/proxy.rb
Overview
This class provides an interface that all subclasses must implement.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) coach
readonly
Returns the value of attribute coach.
Instance Method Summary (collapse)
-
- (Base) initialize(coach)
constructor
Base access proxy which is extended by the subclasses to provide more specific access to the coach client.
-
- (Object) method_missing(meth, *args, &block)
Delegates all messages send to this proxy to the coach client.
- - (Object) password
-
- (Hash) proxy_options
Always returns an empty hash.
- - (Object) username
-
- (Boolean) valid?
Tests if the provided user credentials are valid.
Methods included from Mixin::BasicAuth
Constructor Details
- (Base) initialize(coach)
Base access proxy which is extended by the subclasses to provide more specific access to the coach client.
19 20 21 |
# File 'lib/coach4rb/proxy.rb', line 19 def initialize(coach) @coach = coach end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(meth, *args, &block)
Delegates all messages send to this proxy to the coach client
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/coach4rb/proxy.rb', line 55 def method_missing(meth, *args, &block) params = *args # handle options hash if params.last.is_a?(Hash) # if last param is a hash then it's a option hash. params[-1] = params.last.merge() else # otherwise add a option hash with the given proxy options. params << end # check if coach responds to the message meth / or method meth if coach.respond_to?(meth) begin # try to pass the options hash coach.send meth, *params, &block rescue # otherwise do it without options hash coach.send meth, *args, &block end else raise 'Error: Method missing in coach!' end end |
Instance Attribute Details
- (Object) coach (readonly)
Returns the value of attribute coach
13 14 15 |
# File 'lib/coach4rb/proxy.rb', line 13 def coach @coach end |
Instance Method Details
- (Object) password
29 30 31 |
# File 'lib/coach4rb/proxy.rb', line 29 def password raise 'Not implemented!' end |
- (Hash) proxy_options
Always returns an empty hash.
36 37 38 |
# File 'lib/coach4rb/proxy.rb', line 36 def {} end |
- (Object) username
24 25 26 |
# File 'lib/coach4rb/proxy.rb', line 24 def username raise 'Not implemented!' end |
- (Boolean) valid?
Tests if the provided user credentials are valid.
44 45 46 47 48 49 50 |
# File 'lib/coach4rb/proxy.rb', line 44 def valid? begin coach.authenticate(username, password) rescue false end end |