Sha256: a0cf935614bd745006af85cfa2bfebe0e99549021d4b506f520b83a08341fdd5

Contents?: true

Size: 531 Bytes

Versions: 4

Compression:

Stored size: 531 Bytes

Contents

require 'securerandom'

class Entity
  include Dicer::Contextable

  def initialize(data)
    @id = SecureRandom.hex

    data.each_pair do |key, val|
      instance_variable_set(:"@#{key}", val)

      if key.to_s != 'id'
        (class << self; self; end).class_eval(<<-EOF)
          def #{key}
            @#{key}
          end

          def #{key}=(v)
            @#{key} = v
          end
        EOF
      end
    end
  end

  attr_reader :id

  def ==(other)
    other.class == self.class && other.id == self.id
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dicer-0.3.0 spec/support/entity.rb
dicer-0.2.0 spec/support/entity.rb
dicer-0.1.0 spec/support/entity.rb
dicer-0.0.1 spec/support/entity.rb