lib/restful_model.rb in inbox-0.7.0 vs lib/restful_model.rb in inbox-0.8.0

- old
+ new

@@ -1,13 +1,15 @@ require 'time_attr_accessor' +require 'parameters' module Inbox class RestfulModel extend Inbox::TimeAttrAccessor + include Inbox::Parameters - attr_accessor :id - attr_accessor :namespace_id + parameter :id + parameter :namespace_id time_attr_accessor :created_at def self.collection_name "#{self.to_s.downcase}s".split('::').last end @@ -21,14 +23,12 @@ def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object.id == id) end def inflate(json) - setters = methods.grep(/^\w+=$/) - setters.each do |setter| - property_name = setter.to_s.sub('=', '') - send(setter, json[property_name]) if json.has_key?(property_name) + parameters.each do |property_name| + send("#{property_name}=", json[property_name]) if json.has_key?(property_name) end end def save! if id @@ -43,12 +43,10 @@ @_api.url_for_path("/n/#{@namespace_id}/#{self.class.collection_name}/#{id}#{action}") end def as_json(options = {}) hash = {} - setters = methods.grep(/^\w+=$/) - setters.each do |setter| - getter = setter.to_s.sub('=', '') + parameters.each do |getter| unless options[:except] && options[:except].include?(getter) value = send(getter) unless value.is_a?(RestfulModelCollection) value = value.as_json(options) if value.respond_to?(:as_json) hash[getter] = value \ No newline at end of file