Class: Tsubaki::Shoulda::Matchers::ValidateMyNumberOfMatcher
- Inherits:
-
Object
- Object
- Tsubaki::Shoulda::Matchers::ValidateMyNumberOfMatcher
- Defined in:
- lib/tsubaki/matchers/validate_my_number_of_matcher.rb
Instance Method Summary collapse
- #allow_nil(allow_nil = true) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(attribute_name) ⇒ ValidateMyNumberOfMatcher
constructor
A new instance of ValidateMyNumberOfMatcher.
- #matches?(subject) ⇒ Boolean
- #strict(strict = true) ⇒ Object
- #with_divider(divider) ⇒ Object
Constructor Details
#initialize(attribute_name) ⇒ ValidateMyNumberOfMatcher
Returns a new instance of ValidateMyNumberOfMatcher.
17 18 19 20 21 22 23 24 25 |
# File 'lib/tsubaki/matchers/validate_my_number_of_matcher.rb', line 17 def initialize(attribute_name) @attribute_name = attribute_name @options = {} @options[:strict] = nil @options[:divider] = nil @options[:allow_nil] = nil @failure_messages = [] self end |
Instance Method Details
#allow_nil(allow_nil = true) ⇒ Object
56 57 58 59 |
# File 'lib/tsubaki/matchers/validate_my_number_of_matcher.rb', line 56 def allow_nil(allow_nil = true) @options[:allow_nil] = allow_nil self end |
#description ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/tsubaki/matchers/validate_my_number_of_matcher.rb', line 37 def description result = 'ensure my number format' result << " for #{@attribute_name}" result << ' with strict mode' if @options[:strict].present? result << " with divider '#{@options[:divider]}'" if @options[:divider].present? result << ' and allow nil' if @options[:allow_nil].present? result end |
#failure_message ⇒ Object
33 34 35 |
# File 'lib/tsubaki/matchers/validate_my_number_of_matcher.rb', line 33 def @failure_messages.join("\n") end |
#matches?(subject) ⇒ Boolean
27 28 29 30 31 |
# File 'lib/tsubaki/matchers/validate_my_number_of_matcher.rb', line 27 def matches?(subject) @subject = subject @subject = @subject.new if @subject.class == Class (error_when_not_valid + no_error_when_valid).all? end |
#strict(strict = true) ⇒ Object
46 47 48 49 |
# File 'lib/tsubaki/matchers/validate_my_number_of_matcher.rb', line 46 def strict(strict = true) @options[:strict] = strict self end |
#with_divider(divider) ⇒ Object
51 52 53 54 |
# File 'lib/tsubaki/matchers/validate_my_number_of_matcher.rb', line 51 def with_divider(divider) @options[:divider] = divider self end |