parent
003a26ae68
commit
54185fe9eb
|
|
@ -52,16 +52,17 @@ module Squib
|
||||||
#
|
#
|
||||||
def defaultify(p, args, layout)
|
def defaultify(p, args, layout)
|
||||||
return args[p] if args.key? p # arg was specified, no defaults used
|
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|
|
args[:layout].map do |layout_arg|
|
||||||
if layout_arg.nil?
|
return defaults[p] if layout_arg.nil? # no layout specified, use default
|
||||||
self.class.parameters.merge(dsl_method_defaults)[p] # no layout specified, use default
|
unless layout.key? layout_arg.to_s # specified a layout, but it doesn't exist in layout. Oops!
|
||||||
else
|
Squib.logger.warn("Layout \"#{layout_arg.to_s}\" does not exist in layout file - using default instead")
|
||||||
if layout[layout_arg.to_s].key? p.to_s
|
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
|
layout[layout_arg.to_s][p.to_s] # param specified in layout
|
||||||
else
|
else
|
||||||
self.class.parameters.merge(dsl_method_defaults)[p] # layout specified, but not this param
|
defaults[p] # layout specified, but not this param
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,16 @@ describe Squib::Args::Box do
|
||||||
y: [0, 0], # Box default
|
y: [0, 0], # Box default
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'unit conversion' do
|
context 'unit conversion' do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue