Class: BitBalloon::CollectionProxy
- Inherits:
-
Object
- Object
- BitBalloon::CollectionProxy
show all
- Includes:
- Enumerable
- Defined in:
- lib/bitballoon/collection_proxy.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, prefix = nil) ⇒ CollectionProxy
Returns a new instance of CollectionProxy.
16
17
18
19
|
# File 'lib/bitballoon/collection_proxy.rb', line 16
def initialize(client, prefix = nil)
self.client = client
self.prefix = prefix
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5
6
7
|
# File 'lib/bitballoon/collection_proxy.rb', line 5
def client
@client
end
|
#prefix ⇒ Object
Returns the value of attribute prefix.
5
6
7
|
# File 'lib/bitballoon/collection_proxy.rb', line 5
def prefix
@prefix
end
|
Class Method Details
.model(value = nil) ⇒ Object
12
13
14
|
# File 'lib/bitballoon/collection_proxy.rb', line 12
def self.model(value = nil)
@model ||= BitBalloon.const_get(to_s.split("::").last.sub(/s$/, ''))
end
|
.path(value = nil) ⇒ Object
7
8
9
10
|
# File 'lib/bitballoon/collection_proxy.rb', line 7
def self.path(value = nil)
return @path unless value
@path = value
end
|
Instance Method Details
#all(options = {}) ⇒ Object
21
22
23
24
|
# File 'lib/bitballoon/collection_proxy.rb', line 21
def all(options = {})
response = client.request(:get, path, {:params => options})
response.parsed.map {|attributes| model.new(client, attributes.merge(:prefix => prefix)) } if response.parsed
end
|
#create(attributes) ⇒ Object
35
36
37
38
|
# File 'lib/bitballoon/collection_proxy.rb', line 35
def create(attributes)
response = client.request(:post, path, :body => attributes)
model.new(client, response.parsed.merge(:prefix => prefix)) if response.parsed
end
|
#each(&block) ⇒ Object
26
27
28
|
# File 'lib/bitballoon/collection_proxy.rb', line 26
def each(&block)
all.each(&block)
end
|
#get(id) ⇒ Object
30
31
32
33
|
# File 'lib/bitballoon/collection_proxy.rb', line 30
def get(id)
response = client.request(:get, ::File.join(path, id))
model.new(client, response.parsed.merge(:prefix => prefix)) if response.parsed
end
|
#model ⇒ Object
40
41
42
|
# File 'lib/bitballoon/collection_proxy.rb', line 40
def model
self.class.model
end
|
#path ⇒ Object
44
45
46
|
# File 'lib/bitballoon/collection_proxy.rb', line 44
def path
[prefix, self.class.path].compact.join("/")
end
|