Class: Shoulda::Lotus::Matchers::CoerceAttributeMatcher
- Inherits:
-
Object
- Object
- Shoulda::Lotus::Matchers::CoerceAttributeMatcher
- Defined in:
- lib/shoulda/lotus/matchers/coerce_attribute_matcher.rb
Constant Summary collapse
- TYPES =
{ 'Array' => [1, [1]], 'BigDecimal' => ['x', nil], 'Boolean' => ['0303', false], 'Date' => [false, nil], 'DateTime' => ['x', nil], 'Float' => ['x', nil], 'Hash' => ['รง', nil], 'Integer' => ['x', nil], 'Pathname' => [true, nil], 'Set' => [nil, Set.new], 'String' => [1, '1'], 'Symbol' => [Hash.new, nil], 'Time' => ['uy', nil], }
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(attribute) ⇒ CoerceAttributeMatcher
constructor
A new instance of CoerceAttributeMatcher.
- #matches?(target) ⇒ Boolean
- #to(type) ⇒ Object
Constructor Details
#initialize(attribute) ⇒ CoerceAttributeMatcher
25 26 27 |
# File 'lib/shoulda/lotus/matchers/coerce_attribute_matcher.rb', line 25 def initialize(attribute) @attribute = attribute end |
Instance Method Details
#description ⇒ Object
34 35 36 |
# File 'lib/shoulda/lotus/matchers/coerce_attribute_matcher.rb', line 34 def description "coerce '#{@attribute}' to '#{@type}'" end |
#failure_message ⇒ Object
38 39 40 |
# File 'lib/shoulda/lotus/matchers/coerce_attribute_matcher.rb', line 38 def "does coerce '#{@attribute}' to '#{@type}'" end |
#failure_message_when_negated ⇒ Object
42 43 44 |
# File 'lib/shoulda/lotus/matchers/coerce_attribute_matcher.rb', line 42 def "does not coerce '#{@attribute}' to '#{@type}'" end |
#matches?(target) ⇒ Boolean
29 30 31 32 |
# File 'lib/shoulda/lotus/matchers/coerce_attribute_matcher.rb', line 29 def matches?(target) target.send("#{@attribute}=", TYPES[@type.to_s].first) target.send(@attribute) == TYPES[@type.to_s].last end |
#to(type) ⇒ Object
46 47 48 49 |
# File 'lib/shoulda/lotus/matchers/coerce_attribute_matcher.rb', line 46 def to(type) @type = type self end |