Class: ButterCMS::ButterResource
- Inherits:
-
Object
- Object
- ButterCMS::ButterResource
show all
- Defined in:
- lib/buttercms/butter_resource.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ButterResource.
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/buttercms/butter_resource.rb', line 5
def initialize(json)
@json = json
@data = HashToObject.convert(json["data"])
@meta = HashToObject.convert(json["meta"]) if json["meta"]
if json["data"].is_a?(Hash)
json["data"].each do |key, value|
instance_variable_set("@#{key}", @data.send(key))
self.class.send(:attr_reader, key)
end
end
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3
4
5
|
# File 'lib/buttercms/butter_resource.rb', line 3
def data
@data
end
|
Returns the value of attribute meta.
3
4
5
|
# File 'lib/buttercms/butter_resource.rb', line 3
def meta
@meta
end
|
Class Method Details
.all(options = {}) ⇒ Object
33
34
35
36
37
|
# File 'lib/buttercms/butter_resource.rb', line 33
def self.all(options = {})
response = ButterCMS.request(self.endpoint, options)
self.create_collection(response)
end
|
.endpoint(id = nil) ⇒ Object
23
24
25
26
27
|
# File 'lib/buttercms/butter_resource.rb', line 23
def self.endpoint(id = nil)
resource_path + (id ? "#{id}/" : '')
end
|
.find(id, options = {}) ⇒ Object
39
40
41
42
43
|
# File 'lib/buttercms/butter_resource.rb', line 39
def self.find(id, options = {})
response = ButterCMS.request(self.endpoint(id), options)
self.create_object(response)
end
|
.resource_path ⇒ Object
29
30
31
|
# File 'lib/buttercms/butter_resource.rb', line 29
def self.resource_path
raise "resource_path must be set"
end
|
Instance Method Details
#inspect ⇒ Object
18
19
20
21
|
# File 'lib/buttercms/butter_resource.rb', line 18
def inspect
id_string = (self.respond_to?(:id) && !self.id.nil?) ? " id=#{self.id}" : ""
"#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@json)
end
|