module Gearbox::SemanticAccessors::ClassMethods

Public Instance Methods

attribute(name, opts={}) click to toggle source
# File lib/gearbox/mixins/semantic_accessors.rb, line 17
def attribute(name, opts={})
  opts = opts.merge(:name => name)

  define_method(name) do
    attribute_definitions[name] ||= Attribute.new(opts)
    attribute_definitions[name].to_value
  end
  
  define_method("#{name}=") do |value|
    @previously_changed = changes
    attribute_definitions[name] ||= Attribute.new(opts)
    old_value = attribute_definitions[name].get
    new_value = attribute_definitions[name].set(value)
    name_will_change! unless new_value == old_value
  end

  attributes[name] = opts
  define_attribute_method(name)
end
attributes() click to toggle source
# File lib/gearbox/mixins/semantic_accessors.rb, line 13
def attributes
  @attributes ||= {}
end