lib/lita/configuration_builder.rb in lita-4.0.4 vs lib/lita/configuration_builder.rb in lita-4.1.0
- old
+ new
@@ -104,17 +104,17 @@
# is run without it set, Lita will abort on start up with a message about it.
# @param default [Object] An optional default value for the attribute.
# @yield A block to be evaluated in the context of the new attribute. Used for
# defining nested configuration attributes and validators.
# @return [void]
- def config(name, types: nil, type: nil, required: false, default: nil)
+ def config(name, types: nil, type: nil, required: false, default: nil, &block)
attribute = self.class.new
attribute.name = name
attribute.types = types || type
attribute.required = required
attribute.value = default
- attribute.instance_exec(&proc) if block_given?
+ attribute.instance_exec(&block) if block
children << attribute
end
# Sets the valid types for the configuration attribute.
@@ -127,18 +127,18 @@
# Declares a block to be used to validate the value of an attribute whenever it's set.
# Validation blocks should return any object to indicate an error, or +nil+/+false+ if
# validation passed.
# @yield The code that performs validation.
# @return [void]
- def validate
- validator = proc
+ def validate(&block)
+ validator = block
unless value.nil?
error = validator.call(value)
raise ValidationError, error if error
end
- @validator = proc
+ @validator = block
end
# Sets the value of the attribute, raising an error if it is not among the valid types.
# @param value [Object] The new value of the attribute.
# @return [void]