module Structural::Model

Attributes

data[R]

Public Class Methods

new(data = {}) click to toggle source
# File lib/structural/model.rb, line 5
def initialize(data = {})
  @data = Hashifier.hashify(data)
end

Private Class Methods

included(base) click to toggle source
# File lib/structural/model.rb, line 28
def self.included(base)
  base.extend(Descriptor)
end

Public Instance Methods

==(other)
Alias for: eql?
eql?(other) click to toggle source
# File lib/structural/model.rb, line 17
def eql? other
  other.is_a?(Structural::Model) && other.data.eql?(self.data)
end
Also aliased as: ==
hash() click to toggle source
# File lib/structural/model.rb, line 22
def hash
  data.hash
end
set(values) click to toggle source
# File lib/structural/model.rb, line 9
def set(values)
  self.class.new(data.merge(Hashifier.hashify(values)))
end
unset(*keys) click to toggle source
# File lib/structural/model.rb, line 13
def unset(*keys)
  self.class.new(data.except(*keys.map(&:to_sym)))
end

Private Instance Methods

memoize(ivar, &b) click to toggle source
# File lib/structural/model.rb, line 32
def memoize(ivar, &b)
  instance_variable_get(ivar) || instance_variable_set(ivar, b.call(data))
end