Sha256: 576ce2e4209d036172cfd97b2196ceedaddb05c88ca0e5f2638462c78c5cacb8

Contents?: true

Size: 981 Bytes

Versions: 8

Compression:

Stored size: 981 Bytes

Contents

require 'active_model'

module Reviewed
  class Base
    include ::Reviewed::Embeddable

    extend ::ActiveModel::Naming

    attr_accessor :attributes

    def initialize(data)
      self.attributes = objectify(data)
    end

    def created_at
      if @attributes.has_key?(:created_at)
        Time.parse(@attributes[:created_at])
      else
        nil
      end
    end

    def updated_at
      if @attributes.has_key?(:updated_at)
        Time.parse(@attributes[:updated_at])
      else
        nil
      end
    end

    class << self

      def path
        @resource_name ||= association_name
      end

      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]
      else
        super
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reviewed-0.2.2 lib/reviewed/base.rb
reviewed-0.2.1 lib/reviewed/base.rb
reviewed-0.2.0 lib/reviewed/base.rb
reviewed-0.1.4 lib/reviewed/base.rb
reviewed-0.1.32 lib/reviewed/base.rb
reviewed-0.1.31 lib/reviewed/base.rb
reviewed-0.1.30 lib/reviewed/base.rb
reviewed-0.1.29 lib/reviewed/base.rb