module Kelbim::DSL::Checker
Private Instance Methods
__identify(errmsg)
click to toggle source
# File lib/kelbim/dsl/checker.rb, line 56 def __identify(errmsg) if @error_identifier errmsg = "#{@error_identifier}: #{errmsg}" end return errmsg end
call_once(method_name)
click to toggle source
# File lib/kelbim/dsl/checker.rb, line 46 def call_once(method_name) @called ||= [] if @called.include?(method_name) raise __identify("`#{method_name}` is already defined") end @called << method_name end
expected_length(value, length)
click to toggle source
# File lib/kelbim/dsl/checker.rb, line 28 def expected_length(value, length) if value.length != length raise __identify("Invalid length: #{value}") end end
expected_type(value, *types)
click to toggle source
# File lib/kelbim/dsl/checker.rb, line 22 def expected_type(value, *types) unless types.any? {|t| value.kind_of?(t) } raise __identify("Invalid type: #{value}") end end
expected_value(value, *list)
click to toggle source
# File lib/kelbim/dsl/checker.rb, line 34 def expected_value(value, *list) unless list.any? {|i| value == i } raise __identify("Invalid value: #{value}") end end
not_include(value, list)
click to toggle source
# File lib/kelbim/dsl/checker.rb, line 40 def not_include(value, list) if list.include?(value) raise __identify("`#{value}` is already included") end end
required(name, value)
click to toggle source
# File lib/kelbim/dsl/checker.rb, line 5 def required(name, value) invalid = false if value case value when String invalid = value.strip.empty? when Array, Hash invalid = value.empty? end else invalid = true end raise __identify("`#{name}` is required") if invalid end