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
31
32
33
34
35
|
# File 'lib/buttercms/butter_resource.rb', line 31
def self.all(options = {})
response = ButterCMS.request(self.endpoint, options)
self.create_collection(response)
end
|
.endpoint(id = '') ⇒ Object
23
24
25
|
# File 'lib/buttercms/butter_resource.rb', line 23
def self.endpoint(id = '')
resource_path + '/' + id.to_s
end
|
.find(id, options = {}) ⇒ Object
37
38
39
40
41
|
# File 'lib/buttercms/butter_resource.rb', line 37
def self.find(id, options = {})
response = ButterCMS.request(self.endpoint(id), options)
self.create_object(response)
end
|
.resource_path ⇒ Object
27
28
29
|
# File 'lib/buttercms/butter_resource.rb', line 27
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
|