Module: LazyResource::Resource::ClassMethods

Defined in:
lib/lazy_resource/resource.rb

Instance Method Summary collapse

Instance Method Details

#allObject



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

def find(id, params={}, options={})
  self.new(self.primary_key_name => id).tap do |resource|
    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



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_queueObject



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

def request_queue
  Thread.current[:request_queue] ||= Typhoeus::Hydra.new
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



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

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