Module: Arke::Resource::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/arke/resource/model.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary
collapse
- DEFAULT_URL_TEMPLATE =
The default template used for generating resource urls.
'/{endpoint}{/id}{?query*}'
- RESPONSE_HANDLERS =
{}
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
220
221
222
223
224
|
# File 'lib/arke/resource/model.rb', line 220
def method_missing(meth, *args)
return self.class.associations[meth.to_sym][:association].
new(self, meth.to_sym, associations[meth.to_sym][:options]) if self.class.associations && self.class.associations[meth.to_sym]
super
end
|
Instance Method Details
#initialize(attributes = {}) ⇒ Object
178
179
180
181
|
# File 'lib/arke/resource/model.rb', line 178
def initialize(attributes={})
@_attributes = attributes
self.class.after_initializers.each { |ai| ai.call } if self.class.after_initializers
end
|
#inspect ⇒ Object
199
200
201
202
|
# File 'lib/arke/resource/model.rb', line 199
def inspect
id = "id: ''#{self.id}'" if try(:id)
"#<#{self.class.name}:0x%08x>" % (object_id * 2)
end
|
#persisted? ⇒ Boolean
187
188
189
|
# File 'lib/arke/resource/model.rb', line 187
def persisted?
!self.id.empty?
end
|
#save ⇒ Object
191
192
193
194
195
196
|
# File 'lib/arke/resource/model.rb', line 191
def save
unless self.persisted?
return make_request(:post, @_attributes) && true
end
false
end
|
#to_param ⇒ Object
183
184
185
|
# File 'lib/arke/resource/model.rb', line 183
def to_param
self.id
end
|