Sha256: 59e1237fd0e9fbc596d7a6a6edfbb27dc90db9a0030c9aab394c332567c2ad02

Contents?: true

Size: 608 Bytes

Versions: 7

Compression:

Stored size: 608 Bytes

Contents

# To test:
# 1. Should be able to add extra arguments after attributes in a subclass
# 2. Should throw an error if hash is not provided as FIRST argument

module Materialize
  class Entity

    def self.wrap(entities_data)
      entities_data.map { |entity_data| new(entity_data) }
    end

    def initialize(attributes)
      raise "Attributes must be a hash" unless attributes.is_a?(Hash)

      attributes.each_pair do |key, value|
        instance_variable_set("@#{key}", value)

        (class << self; self; end).class_eval do
          attr_reader key.to_sym
        end
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
materialize-0.2.6 lib/materialize/entity.rb
materialize-0.2.5 lib/materialize/entity.rb
materialize-0.2.4 lib/materialize/entity.rb
materialize-0.2.3 lib/materialize/entity.rb
materialize-0.2.2 lib/materialize/entity.rb
materialize-0.2.1 lib/materialize/entity.rb
materialize-0.2.0 lib/materialize/entity.rb