lib/clamp/attribute/instance.rb in clamp-1.2.1 vs lib/clamp/attribute/instance.rb in clamp-1.3.0
- old
+ new
@@ -1,9 +1,11 @@
+# frozen_string_literal: true
+
module Clamp
module Attribute
- # Represents an option/parameter of a Clamp::Command instance.
+ # Represents an attribute of a Clamp::Command instance.
#
class Instance
def initialize(attribute, command)
@attribute = attribute
@@ -25,11 +27,11 @@
def set(value)
command.instance_variable_set(attribute.ivar_name, value)
end
def default
- command.send(attribute.default_method)
+ command.send(attribute.default_method) if command.respond_to?(attribute.default_method, true)
end
# default implementation of read_method
def _read
set(default) unless self.defined?
@@ -71,10 +73,10 @@
# Set the parameter value if it's environment variable is present
value = ENV[attribute.environment_variable]
begin
take(value)
rescue ArgumentError => e
- signal_usage_error Clamp.message(:env_argument_error, :env => attribute.environment_variable, :message => e.message)
+ signal_usage_error Clamp.message(:env_argument_error, env: attribute.environment_variable, message: e.message)
end
end
def unset?
if attribute.multivalued?