Class: RestResource::Resource
- Inherits:
-
Object
- Object
- RestResource::Resource
- Defined in:
- lib/rest_resource/resource.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(params = {}) ⇒ Resource
Returns a new instance of Resource.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rest_resource/resource.rb', line 25 def initialize(params={}) params_hash = (params.is_a?(String)) ? ActiveSupport::JSON.decode(params) : params @attributes = params_hash (class << self; self; end).class_eval do params_hash.each_pair do |method_name, value| define_method(method_name) do Value.new(value).value end end end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/rest_resource/resource.rb', line 3 def attributes @attributes end |
Class Method Details
.create(params) ⇒ Object
10 11 12 |
# File 'lib/rest_resource/resource.rb', line 10 def create(params) self.new(rest_crud.create(params)) end |
.find(resource_id) ⇒ Object
6 7 8 |
# File 'lib/rest_resource/resource.rb', line 6 def find(resource_id) self.new(rest_crud.find(resource_id)) end |