Module: LazyResource::Resource::ClassMethods
- Defined in:
- lib/lazy_resource/resource.rb
Instance Method Summary collapse
- #all ⇒ Object
- #create(attributes = {}) ⇒ Object
- #default_headers ⇒ Object
- #default_headers=(headers) ⇒ Object
- #find(id, params = {}, options = {}) ⇒ Object
- #from ⇒ Object
- #from=(from) ⇒ Object
- #limit(limit_value) ⇒ Object
- #offset(offset_value) ⇒ Object
- #order(order_value) ⇒ Object
- #page(page_value) ⇒ Object
- #request_queue ⇒ Object
-
#site ⇒ Object
Gets the URI of the REST resources to map for this class.
-
#site=(site) ⇒ Object
Sets the URI of the REST resources to map for this class to the value in the
site
argument. - #where(where_values) ⇒ Object
Instance Method Details
#all ⇒ Object
106 107 108 |
# File 'lib/lazy_resource/resource.rb', line 106 def all Relation.new(self) end |
#create(attributes = {}) ⇒ Object
110 111 112 113 114 |
# File 'lib/lazy_resource/resource.rb', line 110 def create(attributes={}) new(attributes).tap do |resource| resource.create end end |
#default_headers ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/lazy_resource/resource.rb', line 51 def default_headers if defined?(@default_headers) @default_headers else LazyResource::Resource.default_headers end end |
#default_headers=(headers) ⇒ Object
59 60 61 |
# File 'lib/lazy_resource/resource.rb', line 59 def default_headers=(headers) @default_headers = headers end |
#find(id, params = {}, options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/lazy_resource/resource.rb', line 75 def find(id, params={}, ={}) self.new(self.primary_key_name => id).tap do |resource| resource.fetched = false resource.persisted = true [:headers] ||= {} [:headers].reverse_merge!(default_headers) request = Request.new(resource.element_url(params), resource, ) request_queue.queue(request) end end |
#from ⇒ Object
63 64 65 |
# File 'lib/lazy_resource/resource.rb', line 63 def from @from end |
#from=(from) ⇒ Object
67 68 69 |
# File 'lib/lazy_resource/resource.rb', line 67 def from=(from) @from = from end |
#limit(limit_value) ⇒ Object
94 95 96 |
# File 'lib/lazy_resource/resource.rb', line 94 def limit(limit_value) Relation.new(self, :limit_value => limit_value) end |
#offset(offset_value) ⇒ Object
98 99 100 |
# File 'lib/lazy_resource/resource.rb', line 98 def offset(offset_value) Relation.new(self, :offset_value => offset_value) end |
#order(order_value) ⇒ Object
90 91 92 |
# File 'lib/lazy_resource/resource.rb', line 90 def order(order_value) Relation.new(self, :order_value => order_value) end |
#page(page_value) ⇒ Object
102 103 104 |
# File 'lib/lazy_resource/resource.rb', line 102 def page(page_value) Relation.new(self, :page_value => page_value) end |
#request_queue ⇒ Object
71 72 73 |
# File 'lib/lazy_resource/resource.rb', line 71 def request_queue Thread.current[:request_queue] ||= Typhoeus::Hydra.new end |
#site ⇒ Object
Gets the URI of the REST resources to map for this class. The site variable is required for Active Async’s mapping to work.
37 38 39 40 41 42 43 |
# File 'lib/lazy_resource/resource.rb', line 37 def site if defined?(@site) @site else LazyResource::Resource.site end end |
#site=(site) ⇒ Object
Sets the URI of the REST resources to map for this class to the value in the site
argument. The site variable is required for LazyResources’s mapping to work.
47 48 49 |
# File 'lib/lazy_resource/resource.rb', line 47 def site=(site) @site = site end |