Sha256: db008281bd7ffb4b888e7a7436f087fcecb20b1b5c4b02e027af009599f72cae

Contents?: true

Size: 672 Bytes

Versions: 3

Compression:

Stored size: 672 Bytes

Contents

module Structural
  module Model
    attr_reader :data

    def initialize(data = {})
      @data = Hashifier.hashify(data)
    end

    def set(values)
      self.class.new(data.merge(Hashifier.hashify(values)))
    end

    def unset(*keys)
      self.class.new(data.except(*keys.map(&:to_s)))
    end

    def eql? other
      other.is_a?(Structural::Model) && other.data.eql?(self.data)
    end
    alias_method :==, :eql?

    def hash
      data.hash
    end

    private

    def self.included(base)
      base.extend(Descriptor)
    end

    def memoize(f, &b)
      instance_variable_get("@#{f}") || instance_variable_set("@#{f}", b.call(data))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
structural-0.0.3 lib/structural/model.rb
structural-0.0.2 lib/structural/model.rb
structural-0.0.1 lib/structural/model.rb