Permalink
Browse files

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

  • Loading branch information...
1 parent 67c4a4e commit d9644e8b03c34aa128bbc5c913d32176a4e1a67c @thomsbg thomsbg committed with Aug 9, 2012
Showing with 10 additions and 12 deletions.
  1. +10 −12 lib/her/model/orm.rb
View
@@ -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

0 comments on commit d9644e8

Please sign in to comment.