lib/acfs/resource/attributes.rb in acfs-1.5.1 vs lib/acfs/resource/attributes.rb in acfs-1.6.0
- old
+ new
@@ -66,11 +66,11 @@
# @param [Hash{String, Symbol => Object}, #each{|key, value|}]
# Attributes to set in resource.
# @see #write_attributes Delegates attributes hash to {#write_attributes}.
#
def attributes=(attributes)
- write_attributes attributes
+ write_attributes(attributes)
end
# @api public
#
# Read an attribute from instance variable.
@@ -101,35 +101,34 @@
# @param [Hash{String, Symbol => Object, Proc}, #each{|key, value|}]
# Attributes to write.
#
# @see #write_attribute Delegates attribute values to `#write_attribute`.
#
- def write_attributes(attributes, opts = {})
+ def write_attributes(attributes, **opts)
unless attributes.respond_to?(:each) && attributes.respond_to?(:keys)
return false
end
- if opts.fetch(:unknown, :ignore) == :raise
- if (attributes.keys.map(&:to_s) - self.class.attributes.keys).any?
- missing = attributes.keys - self.class.attributes.keys
- missing.map!(&:inspect)
- raise ArgumentError.new "Unknown attributes: #{missing.join(', ')}"
- end
+ if opts.fetch(:unknown, :ignore) == :raise &&
+ (attributes.keys.map(&:to_s) - self.class.attributes.keys).any?
+ missing = attributes.keys - self.class.attributes.keys
+ missing.map!(&:inspect)
+ raise ArgumentError.new "Unknown attributes: #{missing.join(', ')}"
end
procs = {}
attributes.each do |key, _|
if attributes[key].is_a? Proc
procs[key] = attributes[key]
else
- write_local_attribute key, attributes[key], opts
+ write_local_attribute(key, attributes[key], **opts)
end
end
procs.each do |key, proc|
- write_local_attribute key, instance_exec(&proc), opts
+ write_local_attribute(key, instance_exec(&proc), **opts)
end
true
end
@@ -199,16 +198,16 @@
#
# @param [#to_sym] name Attribute name.
# @param [Symbol, String, Class] type Attribute
# type identifier or type class.
#
- def attribute(name, type, opts = {})
+ def attribute(name, type, **opts)
if type.is_a?(Symbol) || type.is_a?(String)
type = "#{ATTR_CLASS_BASE}::#{type.to_s.classify}".constantize
end
- define_attribute name.to_sym, type, opts
+ define_attribute(name.to_sym, type, **opts)
end
# @api public
#
# Return list of possible attributes and default
@@ -263,9 +262,9 @@
end
end
# Load attribute type classes.
#
-Dir[File.dirname(__FILE__) + '/attributes/*.rb'].sort.each do |path|
+Dir[File.join(__dir__, 'attributes/*.rb')].sort.each do |path|
filename = File.basename(path)
require "acfs/resource/attributes/#{filename}"
end