Class: Easy::Resource
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- Easy::Resource
show all
- Defined in:
- lib/easy/resource.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/easy/resource.rb', line 4
def self.configure(conf)
case conf
when ::Hash
if conf[:url].present? && conf[:token].present?
configure_bearer(conf[:url], conf[:token])
elsif conf[:url].present?
self.site = conf[:url]
end
when ::OAuth2::AccessToken
configure_bearer(conf.client.site, conf.token)
else
end
end
|
19
20
21
22
23
|
# File 'lib/easy/resource.rb', line 19
def self.configure_bearer(url, token)
self.site = url
connection.auth_type = :bearer
connection.bearer_token = token
end
|
Instance Method Details
#becomes(entity_class) ⇒ Object
25
26
27
28
29
|
# File 'lib/easy/resource.rb', line 25
def becomes(entity_class)
model = entity_class.new
model.attributes = attributes
model
end
|
#patch(method_name, options = {}, body = "") ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/easy/resource.rb', line 31
def patch(method_name, options = {}, body = "")
if method_name.nil?
connection.patch(element_path(options), body, self.class.)
else
super
end
end
|
#update_column(attribute, value) ⇒ Object
39
40
41
|
# File 'lib/easy/resource.rb', line 39
def update_column(attribute, value)
update_columns(attribute.to_sym => value)
end
|
#update_columns(**attributes) ⇒ Object
43
44
45
|
# File 'lib/easy/resource.rb', line 43
def update_columns(**attributes)
patch(nil, {}, encode_attributes(attributes))
end
|