lib/reviewed/base.rb in reviewed-0.1.2 vs lib/reviewed/base.rb in reviewed-0.1.4
- old
+ new
@@ -1,36 +1,48 @@
require 'active_model'
module Reviewed
class Base
include ::Reviewed::Embeddable
- include ::Reviewed::Utils
extend ::ActiveModel::Naming
attr_accessor :attributes
def initialize(data)
self.attributes = objectify(data)
end
- class << self
-
- def find(id, params={})
- object_from_response(:get, "#{resource_url}/#{id}", params)
+ def created_at
+ if @attributes.has_key?(:created_at)
+ Time.parse(@attributes[:created_at])
+ else
+ nil
end
+ end
- def where(params={})
- collection_from_response(:get, resource_url, params)
+ def updated_at
+ if @attributes.has_key?(:updated_at)
+ Time.parse(@attributes[:updated_at])
+ else
+ nil
end
+ end
- def all
- where({})
+ class << self
+
+ def path
+ @resource_name ||= association_name
end
- def resource_url
- @resource_name ||= self.name.demodulize.downcase.pluralize
+ def association_name
+ self.name.demodulize.downcase.pluralize
end
+ end
+
+ def respond_to?(sym, include_private=false)
+ return true if super
+ @attributes.has_key?(sym)
end
def method_missing(sym, *args, &block)
if @attributes.has_key?(sym)
@attributes[sym]