Clamp::Attribute::Declaration

Protected Instance Methods

define_accessors_for(attribute, &block) click to toggle source
# File lib/clamp/attribute/declaration.rb, line 8
def define_accessors_for(attribute, &block)
  define_reader_for(attribute)
  define_default_for(attribute)
  if attribute.multivalued?
    define_appender_for(attribute, &block)
    define_multi_writer_for(attribute)
  else
    define_simple_writer_for(attribute, &block)
  end
end
define_appender_for(attribute, &block) click to toggle source
# File lib/clamp/attribute/declaration.rb, line 38
def define_appender_for(attribute, &block)
  define_method(attribute.append_method) do |value|
    value = instance_exec(value, &block) if block
    attribute.of(self)._append(value)
  end
end
define_default_for(attribute) click to toggle source
# File lib/clamp/attribute/declaration.rb, line 25
def define_default_for(attribute)
  define_method(attribute.default_method) do
    attribute.default_value
  end
end
define_multi_writer_for(attribute) click to toggle source
# File lib/clamp/attribute/declaration.rb, line 45
def define_multi_writer_for(attribute)
  define_method(attribute.write_method) do |values|
    attribute.of(self)._replace(values)
  end
end
define_reader_for(attribute) click to toggle source
# File lib/clamp/attribute/declaration.rb, line 19
def define_reader_for(attribute)
  define_method(attribute.read_method) do
    attribute.of(self)._read
  end
end
define_simple_writer_for(attribute, &block) click to toggle source
# File lib/clamp/attribute/declaration.rb, line 31
def define_simple_writer_for(attribute, &block)
  define_method(attribute.write_method) do |value|
    value = instance_exec(value, &block) if block
    attribute.of(self).set(value)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.