Sha256: 6faf00544afba25bbcd4a33bec4fd08a5655d94bbdd758d32b48f48763ae9480

Contents?: true

Size: 804 Bytes

Versions: 2

Compression:

Stored size: 804 Bytes

Contents

module Collector
  module Model

    def self.included(base)
      attr_reader :id, :created_at, :updated_at
    end

    def initialize(attributes = {})
      attributes.each do |key, value|
        instance_variable_set("@#{key}", value) if methods.include? "#{key}".to_sym
        send("#{key}=", value)                  if methods.include? "#{key}=".to_sym
      end
    end

    def touch
      @created_at ||= Time.now.utc
      @updated_at   = Time.now.utc
    end

    def attributes
      instance_variables.each_with_object({}) do |instance_variable, hash|
        hash[instance_variable.to_s[1..-1]] = instance_variable_get(instance_variable)
      end
    end

    def ==(other_model)
      return nil if self.id.nil? || other_model.id.nil?
      self.id == other_model.id
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
collector-0.1.4 lib/collector/model.rb
collector-0.1.3 lib/collector/model.rb