Sha256: 1b265e4be337513b69a0e01e40006afee5a8e41f16b0d9f204872d59e7df2542

Contents?: true

Size: 683 Bytes

Versions: 13

Compression:

Stored size: 683 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

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
collector-0.1.2 lib/collector/model.rb
collector-0.1.1 lib/collector/model.rb
collector-0.1.0 lib/collector/model.rb
collector-0.0.19 lib/collector/model.rb
collector-0.0.18 lib/collector/model.rb
collector-0.0.17 lib/collector/model.rb
collector-0.0.16 lib/collector/model.rb
collector-0.0.15 lib/collector/model.rb
collector-0.0.14 lib/collector/model.rb
collector-0.0.13 lib/collector/model.rb
collector-0.0.12 lib/collector/model.rb
collector-0.0.11 lib/collector/model.rb
collector-0.0.10 lib/collector/model.rb