built a nifty, useful error message thingy
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
require_relative '../args/card_range'
|
||||
require_relative '../args/draw'
|
||||
|
||||
module Squib
|
||||
class Deck
|
||||
|
||||
# DSL method. See http://squib.readthedocs.io
|
||||
def background(opts = {})
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
range.each { |i| @cards[i].background(draw.color[i]) }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
+3
-2
@@ -33,7 +33,7 @@ module Squib
|
||||
:img_dir, :prefix, :text_hint, :typographer
|
||||
# :nodoc:
|
||||
# @api private
|
||||
attr_reader :layout, :conf, :dpi, :font
|
||||
attr_reader :layout, :conf, :dpi, :font, :caller_loc
|
||||
|
||||
#
|
||||
# deck.size is really just @cards.size
|
||||
@@ -69,6 +69,7 @@ module Squib
|
||||
@height = Args::UnitConversion.parse height, dpi
|
||||
cards.times{ |i| @cards << Squib::Card.new(self, @width, @height, i) }
|
||||
@layout = LayoutParser.new(dpi).load_layout(layout)
|
||||
@caller_loc = caller_locations[0] # useful for error messages
|
||||
enable_groups_from_env!
|
||||
if block_given?
|
||||
instance_eval(&block) # here we go. wheeeee!
|
||||
@@ -102,7 +103,7 @@ module Squib
|
||||
##################
|
||||
### PUBLIC API ###
|
||||
##################
|
||||
require_relative 'api/background'
|
||||
require_relative 'dsl/background'
|
||||
require_relative 'api/data'
|
||||
require_relative 'api/groups'
|
||||
require_relative 'api/image'
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
require_relative '../errors_warnings/warn_unexpected_params'
|
||||
module Squib
|
||||
class Deck
|
||||
def background(opts = {}) # DSL method. See http://squib.readthedocs.io
|
||||
BackgroundDSLMethod.new(self).run(opts)
|
||||
end
|
||||
end
|
||||
|
||||
class BackgroundDSLMethod
|
||||
include WarnUnexpectedParam
|
||||
|
||||
def initialize(deck)
|
||||
@error_cxt = <<~EOS.split("\n").join(' ').strip
|
||||
to Squib method '#{caller_locations[1].label}'
|
||||
from #{caller_locations[2].path}:#{caller_locations[2].lineno}
|
||||
EOS
|
||||
@deck = deck
|
||||
end
|
||||
|
||||
def accepted_params
|
||||
[
|
||||
:range,
|
||||
:color
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
def run(opts)
|
||||
warn_unexpected_params(opts)
|
||||
range = Args::CardRange.new(opts[:range], deck_size: @deck.size)
|
||||
draw = Args::Draw.new(@deck.custom_colors).load!(opts, expand_by: @deck.size, layout: @deck.layout, dpi: @deck.dpi)
|
||||
range.each { |i| @deck.cards[i].background(draw.color[i]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
require_relative 'caller_finder'
|
||||
|
||||
module Squib::WarnUnexpectedParam
|
||||
def warn_unexpected_params(opts)
|
||||
unexpected = opts.keys - accepted_params
|
||||
unexpected.each do |key|
|
||||
Squib.logger.warn do
|
||||
"Unexpected option '#{key}' #{@error_cxt} ...ignoring"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user