Class: Yema::Rule::StrongType
- Inherits:
-
Yema::Rule
- Object
- Yema::Rule
- Yema::Rule::StrongType
- Defined in:
- lib/yema/rule/strong_type.rb
Instance Attribute Summary collapse
-
#member_type ⇒ Object
readonly
Returns the value of attribute member_type.
-
#strict ⇒ Object
readonly
Returns the value of attribute strict.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from Yema::Rule
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attribute_name, options = {}) ⇒ StrongType
constructor
A new instance of StrongType.
- #matches?(value) ⇒ Boolean
Methods inherited from Yema::Rule
Constructor Details
#initialize(attribute_name, options = {}) ⇒ StrongType
Returns a new instance of StrongType.
7 8 9 10 |
# File 'lib/yema/rule/strong_type.rb', line 7 def initialize(attribute_name, ={}) super () end |
Instance Attribute Details
#member_type ⇒ Object (readonly)
Returns the value of attribute member_type.
5 6 7 |
# File 'lib/yema/rule/strong_type.rb', line 5 def member_type @member_type end |
#strict ⇒ Object (readonly)
Returns the value of attribute strict.
5 6 7 |
# File 'lib/yema/rule/strong_type.rb', line 5 def strict @strict end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/yema/rule/strong_type.rb', line 5 def type @type end |
Class Method Details
.required_options ⇒ Object
12 13 14 |
# File 'lib/yema/rule/strong_type.rb', line 12 def self. [:type] end |
Instance Method Details
#matches?(value) ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/yema/rule/strong_type.rb', line 16 def matches?(value) raise ArgumentError if member_type && !value.respond_to?(:all?) return true if (strict == :allow_nil && value.nil?) Utils.type_matches?(value, type) && member_type_matches?(value) end |