Class: Hashblue::API::Model
- Inherits:
-
Object
- Object
- Hashblue::API::Model
show all
- Defined in:
- lib/hashblue/api/model.rb
Overview
Defined Under Namespace
Classes: Name
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Model
Returns a new instance of Model.
32
33
34
|
# File 'lib/hashblue/api/model.rb', line 32
def initialize(attributes = {})
@attributes = attributes.stringify_keys
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/hashblue/api/model.rb', line 36
def method_missing(method, *args, &block)
if @attributes.keys.include?(method.to_s)
@attributes[method.to_s]
else
super
end
end
|
Class Method Details
.from_json(models) ⇒ Object
26
27
28
29
30
|
# File 'lib/hashblue/api/model.rb', line 26
def self.from_json(models)
models.map do |attributes|
new(attributes)
end
end
|
.model_name ⇒ Object
22
23
24
|
# File 'lib/hashblue/api/model.rb', line 22
def self.model_name
@_model_name ||= Name.new(self.name.from(15))
end
|
Instance Method Details
#get(path, query_options = {}) ⇒ Object
52
53
54
|
# File 'lib/hashblue/api/model.rb', line 52
def get(path, query_options={})
Hashblue::API.get(path, :query => query_options)
end
|
#id ⇒ Object
44
45
46
|
# File 'lib/hashblue/api/model.rb', line 44
def id
@attributes["id"]
end
|
#post(path, query_options = {}) ⇒ Object
56
57
58
|
# File 'lib/hashblue/api/model.rb', line 56
def post(path, query_options = {})
Hashblue::API.post(path, :query => query_options)
end
|
#to_param ⇒ Object
48
49
50
|
# File 'lib/hashblue/api/model.rb', line 48
def to_param
id
end
|