module Sphene::Attributes

Constants

Types

Public Class Methods

included(base) click to toggle source
# File lib/sphene/attributes.rb, line 15
def self.included(base)
  base.extend(ClassMethods)
end
new(attrs = {}) click to toggle source
# File lib/sphene/attributes.rb, line 10
def initialize(attrs = {})
  initialize_attributes
  assign_attributes(attrs)
end

Public Instance Methods

assign_attributes(attrs) click to toggle source
# File lib/sphene/attributes.rb, line 31
def assign_attributes(attrs)
  attrs.each do |name, value|
    write_attribute(name, value)
  end
end
attributes() click to toggle source
# File lib/sphene/attributes.rb, line 37
def attributes
  @attributes.to_hash
end
read_attribute(name) click to toggle source
# File lib/sphene/attributes.rb, line 19
def read_attribute(name)
  ensure_attribute(name) do |attr|
    @attributes[attr].value
  end
end
write_attribute(name, value) click to toggle source
# File lib/sphene/attributes.rb, line 25
def write_attribute(name, value)
  ensure_attribute(name) do |attr|
    @attributes[attr].value = value
  end
end

Private Instance Methods

assert_attribute(name) click to toggle source
# File lib/sphene/attributes.rb, line 52
def assert_attribute(name)
  @attributes.key?(name.to_sym) ||
    (raise InvalidAttributeNameError, name)
end
ensure_attribute(name) { |to_sym| ... } click to toggle source
# File lib/sphene/attributes.rb, line 47
def ensure_attribute(name)
  assert_attribute(name)
  yield(name.to_sym) if block_given?
end
initialize_attributes() click to toggle source
# File lib/sphene/attributes.rb, line 43
def initialize_attributes
  @attributes = AttributeSet.from(self)
end