Class: Virtus::Matchers::HaveAttributeMatcher
- Inherits:
-
Object
- Object
- Virtus::Matchers::HaveAttributeMatcher
- Defined in:
- lib/virtus/matchers/have_attribute_matcher.rb
Instance Method Summary collapse
- #coerced_with(custom_coercer) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(name, type = nil) ⇒ HaveAttributeMatcher
constructor
A new instance of HaveAttributeMatcher.
- #matches?(klass) ⇒ Boolean
Constructor Details
#initialize(name, type = nil) ⇒ HaveAttributeMatcher
Returns a new instance of HaveAttributeMatcher.
6 7 8 9 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 6 def initialize(name, type = nil) @name = name @type = type end |
Instance Method Details
#coerced_with(custom_coercer) ⇒ Object
11 12 13 14 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 11 def coerced_with(custom_coercer) @custom_coercer = custom_coercer self end |
#description ⇒ Object
29 30 31 32 33 34 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 29 def description type = @type.class == Array ? "Array#{@type}" : @type str = "have attribute #{@name}" str += " of type #{type}#{coercer_description}" unless @type.nil? str end |
#failure_message ⇒ Object
36 37 38 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 36 def "expected #{@klass} to #{description}" end |
#matches?(klass) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 16 def matches?(klass) @klass = klass @attribute = @klass.attribute_set[@name] return false unless @attribute if @type.class == Array return @attribute.primitive == Array && @attribute.[:member_type].primitive == @type.first end valid_type && valid_coercer end |