Module: LazyResource::Resource::ClassMethods

Defined in:
lib/lazy_resource/resource.rb

Instance Method Summary collapse

Instance Method Details

#allObject



107
108
109
# File 'lib/lazy_resource/resource.rb', line 107

def all
  Relation.new(self)
end

#create(attributes = {}) ⇒ Object



111
112
113
114
115
# File 'lib/lazy_resource/resource.rb', line 111

def create(attributes={})
  new(attributes).tap do |resource|
    resource.create
  end
end

#default_headersObject



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
85
# File 'lib/lazy_resource/resource.rb', line 75

def find(id, params={}, options={})
  self.new.tap do |resource|
    resource.instance_variable_set("@#{self.primary_key_name}", id)
    resource.fetched = false
    resource.persisted = true
    options[:headers] ||= {}
    options[:headers].reverse_merge!(default_headers)
    request = Request.new(resource.element_url(params), resource, options)
    request_queue.queue(request)
  end
end

#fromObject



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



95
96
97
# File 'lib/lazy_resource/resource.rb', line 95

def limit(limit_value)
  Relation.new(self, :limit_value => limit_value)
end

#offset(offset_value) ⇒ Object



99
100
101
# File 'lib/lazy_resource/resource.rb', line 99

def offset(offset_value)
  Relation.new(self, :offset_value => offset_value)
end

#order(order_value) ⇒ Object



91
92
93
# File 'lib/lazy_resource/resource.rb', line 91

def order(order_value)
  Relation.new(self, :order_value => order_value)
end

#page(page_value) ⇒ Object



103
104
105
# File 'lib/lazy_resource/resource.rb', line 103

def page(page_value)
  Relation.new(self, :page_value => page_value)
end

#request_queueObject



71
72
73
# File 'lib/lazy_resource/resource.rb', line 71

def request_queue
  Thread.current[:request_queue] ||= Typhoeus::Hydra.new(:max_concurrency => LazyResource.max_concurrency)
end

#siteObject

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

#where(where_values) ⇒ Object



87
88
89
# File 'lib/lazy_resource/resource.rb', line 87

def where(where_values)
  Relation.new(self, :where_values => where_values)
end