Class: AttributedObjectHelpers::TypeCheck
- Inherits:
-
Object
- Object
- AttributedObjectHelpers::TypeCheck
- Defined in:
- lib/attributed_object_helpers/type_check.rb
Class Method Summary collapse
Class Method Details
.check(type_info, value) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/attributed_object_helpers/type_check.rb', line 18 def self.check(type_info, value) return value.is_a?(type_info) if type_info.is_a?(Class) case type_info when :string return value.is_a?(String) when :boolean return value == true || value == false when :integer return value.is_a?(Integer) when :float return value.is_a?(Float) when :numeric return value.is_a?(Numeric) when :symbol return value.is_a?(Symbol) when :array return value.is_a?(Array) when :hash return value.is_a?(Hash) else if type_info.is_a?(AttributedObject::Type) return type_info.strict_check(value) end raise AttributedObject::ConfigurationError.new("Unknown Type for type checking #{type_info}") end end |
.check_type_supported!(type_info) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/attributed_object_helpers/type_check.rb', line 3 def self.check_type_supported!(type_info) supported = type_info.is_a?(Class) || [ :string, :boolean, :integer, :float, :numeric, :symbol, :array, :hash ].include?(type_info) supported = type_info.is_a?(AttributedObject::Type) if !supported raise AttributedObject::ConfigurationError.new("Unknown Type for type checking #{type_info}") unless supported end |