module SparkleFormation::Utils::TypeCheckers
Type check helpers
Public Instance Methods
__t_check(val, types)
click to toggle source
Validate given value is type defined within valid types
@param val [Object] value @param types [Class, Array<Class>] valid types @return [NilClass] @raise [TypeError]
# File lib/sparkle_formation/utils.rb, line 15 def __t_check(val, types) types = [types] unless types.is_a?(Array) if types.none? { |t| val.is_a?(t) } ignore_paths = Gem::Specification.find_by_name("sparkle_formation").full_require_paths file_name, line_no = ::Kernel.caller.detect do |l| ignore_paths.none? { |i_path| l.include?(i_path) } end.split(":")[0, 2] file_name = file_name.to_s.sub(::Dir.pwd, ".") ::Kernel.raise TypeError.new "Received invalid value type `#{val.class}`! " \ "(Allowed types: `#{types.join("`, `")}`) -> #{file_name} @ line #{line_no}" end end
__t_hashish(val)
click to toggle source
Validate given value is a Hash type
@return [NilClass] @raise [TypeError]
# File lib/sparkle_formation/utils.rb, line 40 def __t_hashish(val) __t_check(val, Hash) end
__t_stringish(val)
click to toggle source
Validate given value is String or Symbol type
@return [NilClass] @raise [TypeError]
# File lib/sparkle_formation/utils.rb, line 32 def __t_stringish(val) __t_check(val, [String, Symbol]) end