lib/clamp/attribute_declaration.rb in clamp-0.1.5 vs lib/clamp/attribute_declaration.rb in clamp-0.1.6
- old
+ new
@@ -4,10 +4,11 @@
protected
def define_accessors_for(attribute, &block)
define_reader_for(attribute)
+ define_default_for(attribute)
define_writer_for(attribute, &block)
end
def define_reader_for(attribute)
reader_name = attribute.attribute_name
@@ -16,10 +17,18 @@
define_method(reader_name) do
if instance_variable_defined?(ivar_name)
instance_variable_get(ivar_name)
elsif parent_command && parent_command.respond_to?(reader_name)
parent_command.send(reader_name)
- elsif attribute.respond_to?(:default_value)
+ elsif respond_to?("default_#{attribute.attribute_name}")
+ send("default_#{attribute.attribute_name}")
+ end
+ end
+ end
+
+ def define_default_for(attribute)
+ if attribute.respond_to?(:default_value)
+ define_method("default_#{attribute.attribute_name}") do
attribute.default_value
end
end
end
\ No newline at end of file