Class: ChainGang::Proxy
- Inherits:
-
Object
- Object
- ChainGang::Proxy
- Defined in:
- lib/chaingang/proxy.rb
Instance Attribute Summary collapse
-
#find_scope ⇒ Object
Returns the value of attribute find_scope.
Instance Method Summary collapse
-
#and ⇒ Object
Simply improves readability.
-
#execute ⇒ Object
Make the service call immediately.
-
#from(f) ⇒ Object
Specify a custom url path to retrieve send the service call to.
-
#initialize(client, id = nil) ⇒ Proxy
constructor
A new instance of Proxy.
-
#method_missing(method_name, *args, &block) ⇒ Object
Set the query string parameters on your request by calling them as methods with an exclamation point at the end.
-
#param!(name, value) ⇒ Object
Suppose you have a parameter name that collides with an existing method.
-
#where ⇒ Object
Simply improves readability.
Constructor Details
#initialize(client, id = nil) ⇒ Proxy
Returns a new instance of Proxy.
5 6 7 8 9 |
# File 'lib/chaingang/proxy.rb', line 5 def initialize(client, id=nil) @client = client @params = {} @find_scope = id || :all end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Set the query string parameters on your request by calling them as methods with an exclamation point at the end.
Article.find(:all).where.("moonmaster9000") #/articles.xml?author=moonmaster9000
35 36 37 38 39 40 41 42 |
# File 'lib/chaingang/proxy.rb', line 35 def method_missing(method_name, *args, &block) if args.length == 1 && exclamatory?(method_name) @params[unexclaim method_name] = args.first self else self.execute.send method_name, *args, &block end end |
Instance Attribute Details
#find_scope ⇒ Object
Returns the value of attribute find_scope.
3 4 5 |
# File 'lib/chaingang/proxy.rb', line 3 def find_scope @find_scope end |
Instance Method Details
#and ⇒ Object
Simply improves readability. Does nothing but return self.
Article.find.where.("moonmaster9000").and.published!(true)
18 |
# File 'lib/chaingang/proxy.rb', line 18 def and; self; end |
#execute ⇒ Object
Make the service call immediately.
Article.find(:all).execute
46 47 48 49 50 51 |
# File 'lib/chaingang/proxy.rb', line 46 def execute = {} [:from] = @from if @from [:params] = @params @client.find_without_chaingang(@find_scope, ) end |
#from(f) ⇒ Object
Specify a custom url path to retrieve send the service call to.
Article.find(:all).from :published
14 |
# File 'lib/chaingang/proxy.rb', line 14 def from(f); @from = f; self; end |
#param!(name, value) ⇒ Object
Suppose you have a parameter name that collides with an existing method. Simply set it with this param! method:
Article.find(:all).param!(:from, "New York Times")
27 28 29 30 |
# File 'lib/chaingang/proxy.rb', line 27 def param!(name, value) @params[name] = value self end |
#where ⇒ Object
Simply improves readability. Does nothing but return self.
Article.find.where.("moonmaster9000").and.published!(true)
22 |
# File 'lib/chaingang/proxy.rb', line 22 def where; self; end |