Class: Trubl::Collection
- Inherits:
-
Array
- Object
- Array
- Trubl::Collection
show all
- Defined in:
- lib/trubl/collection.rb
Instance Method Summary
collapse
Instance Method Details
#container_name ⇒ Object
16
17
18
|
# File 'lib/trubl/collection.rb', line 16
def container_name
klass_name
end
|
#from_response(response, options = {}) ⇒ Object
6
7
8
9
10
|
# File 'lib/trubl/collection.rb', line 6
def from_response(response, options = {})
return nil if missing_or_exception?(response)
json = JSON.parse(response.body)
self.concat (json[container_name] || []).map{|m| klass.new(m[member_name]) }
end
|
#klass ⇒ Object
12
13
14
|
# File 'lib/trubl/collection.rb', line 12
def klass
"Trubl::#{member_name.classify}".constantize
end
|
#klass_name ⇒ Object
24
25
26
|
# File 'lib/trubl/collection.rb', line 24
def klass_name
self.class.name.downcase.gsub('trubl::', '')
end
|
#member_name ⇒ Object
20
21
22
|
# File 'lib/trubl/collection.rb', line 20
def member_name
klass_name.singularize
end
|