Sha256: 5f73705697f82c5f0f866b02b9a9f913d327a451fb4a30128abe4e3108cb8625

Contents?: true

Size: 823 Bytes

Versions: 2

Compression:

Stored size: 823 Bytes

Contents

module Collector
  module Model

    def self.included(base)
      attr_accessor :id
      attr_reader :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.6 lib/collector/model.rb
collector-0.1.5 lib/collector/model.rb