parent
003a26ae68
commit
54185fe9eb
|
|
@ -52,16 +52,17 @@ module Squib
|
|||
#
|
||||
def defaultify(p, args, layout)
|
||||
return args[p] if args.key? p # arg was specified, no defaults used
|
||||
dsl_method_defaults = @dsl_method_defaults || {}
|
||||
defaults = self.class.parameters.merge(@dsl_method_defaults || {})
|
||||
args[:layout].map do |layout_arg|
|
||||
if layout_arg.nil?
|
||||
self.class.parameters.merge(dsl_method_defaults)[p] # no layout specified, use default
|
||||
else
|
||||
if layout[layout_arg.to_s].key? p.to_s
|
||||
return defaults[p] if layout_arg.nil? # no layout specified, use default
|
||||
unless layout.key? layout_arg.to_s # specified a layout, but it doesn't exist in layout. Oops!
|
||||
Squib.logger.warn("Layout \"#{layout_arg.to_s}\" does not exist in layout file - using default instead")
|
||||
return defaults[p]
|
||||
end
|
||||
if layout[layout_arg.to_s].key?(p.to_s)
|
||||
layout[layout_arg.to_s][p.to_s] # param specified in layout
|
||||
else
|
||||
self.class.parameters.merge(dsl_method_defaults)[p] # layout specified, but not this param
|
||||
end
|
||||
defaults[p] # layout specified, but not this param
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -79,6 +79,16 @@ describe Squib::Args::Box do
|
|||
y: [0, 0], # Box default
|
||||
)
|
||||
end
|
||||
|
||||
it 'warns on non-existent layouts' do
|
||||
args = { layout: :heal}
|
||||
expect(Squib.logger).to receive(:warn).with('Layout "heal" does not exist in layout file - using default instead').at_least(:once)
|
||||
box.load!(args, expand_by: 2, layout: layout)
|
||||
expect(box).to have_attributes(
|
||||
x: [0, 0], # Box default
|
||||
y: [0, 0], # Box default
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'unit conversion' do
|
||||
|
|
|
|||
Loading…
Reference in New Issue