Class: PRX::Model::Base
- Inherits:
-
Object
show all
- Includes:
- ActiveModel::Model
- Defined in:
- lib/prx/model/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
10
11
12
13
14
15
|
# File 'lib/prx/model/base.rb', line 10
def initialize(*args)
return unless args
if args[0].is_a?(Hash)
args[0].each{|k,v| self.send("#{k.to_s}=", v)}
end
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
8
9
10
|
# File 'lib/prx/model/base.rb', line 8
def id
@id
end
|
Class Method Details
.request(opts) ⇒ Object
39
40
41
|
# File 'lib/prx/model/base.rb', line 39
def self.request(opts)
PRX::Client.request(opts)
end
|
Instance Method Details
#class_path_part ⇒ Object
31
32
33
|
# File 'lib/prx/model/base.rb', line 31
def class_path_part
self.class.name.demodulize.underscore.pluralize
end
|
#find_by_id(id) ⇒ Object
17
18
19
|
# File 'lib/prx/model/base.rb', line 17
def find_by_id(id)
request(:path => "#{class_path_part}/#{id}")
end
|
#request(opts) ⇒ Object
35
36
37
|
# File 'lib/prx/model/base.rb', line 35
def request(opts)
self.class.request(opts)
end
|
#save ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/prx/model/base.rb', line 21
def save
opts = {
:action => (id ? :put : :post),
:path => (id ? "#{class_path_part}/#{id}" : class_path_part),
:body => to_hash
}
response = request(opts)
self.from_json(response.response.body)
end
|