Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use writer methods for data, metadata, and errors to allow customization

  • Loading branch information...
commit d9644e8b03c34aa128bbc5c913d32176a4e1a67c 1 parent 67c4a4e
@thomsbg thomsbg authored committed
Showing with 10 additions and 12 deletions.
  1. +10 −12 lib/her/model/orm.rb
View
22 lib/her/model/orm.rb
@@ -2,7 +2,7 @@ module Her
module Model
# This module adds ORM-like capabilities to the model
module ORM
- attr_reader :metadata, :errors
+ attr_accessor :data, :metadata, :errors
# Initialize a new object with data received from an HTTP request
# @private
@@ -114,11 +114,9 @@ def create(params={}) # {{{
wrap_in_hooks(resource, :create, :save) do |resource, klass|
params = resource.to_params
request(params.merge(:_method => :post, :_path => "#{build_request_path(params)}")) do |parsed_data|
- resource.instance_eval do
- @data = parsed_data[:data]
- @metadata = parsed_data[:metadata]
- @errors = parsed_data[:errors]
- end
+ resource.data = parsed_data[:data]
+ resource.metadata = parsed_data[:metadata]
+ resource.errors = parsed_data[:errors]
end
end
resource
@@ -161,9 +159,9 @@ def save # {{{
self.class.wrap_in_hooks(resource, *hooks) do |resource, klass|
klass.request(params.merge(:_method => method, :_path => "#{request_path}")) do |parsed_data|
- @data = parsed_data[:data]
- @metadata = parsed_data[:metadata]
- @errors = parsed_data[:errors]
+ self.data = parsed_data[:data]
+ self.metadata = parsed_data[:metadata]
+ self.errors = parsed_data[:errors]
end
end
self
@@ -179,9 +177,9 @@ def destroy # {{{
resource = self
self.class.wrap_in_hooks(resource, :destroy) do |resource, klass|
klass.request(:_method => :delete, :_path => "#{request_path}") do |parsed_data|
- @data = parsed_data[:data]
- @metadata = parsed_data[:metadata]
- @errors = parsed_data[:errors]
+ self.data = parsed_data[:data]
+ self.metadata = parsed_data[:metadata]
+ self.errors = parsed_data[:errors]
end
end
self
Please sign in to comment.
Something went wrong with that request. Please try again.