Class: SimpleParams::ValidationMatchers::RequiredParameterMatcher
- Inherits:
-
ValidationMatcher
- Object
- Shoulda::Matchers::ActiveModel::ValidationMatcher
- ValidationMatcher
- SimpleParams::ValidationMatchers::RequiredParameterMatcher
- Defined in:
- lib/simple_params/validation_matchers/required_parameter_matcher.rb
Instance Attribute Summary collapse
-
#allowed_values ⇒ Object
Returns the value of attribute allowed_values.
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#disallowed_values ⇒ Object
Returns the value of attribute disallowed_values.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(attribute) ⇒ RequiredParameterMatcher
constructor
A new instance of RequiredParameterMatcher.
- #matches?(subject) ⇒ Boolean
- #with_allowed_values(*values) ⇒ Object
- #with_default(value) ⇒ Object
- #with_disallowed_values(*values) ⇒ Object
Constructor Details
#initialize(attribute) ⇒ RequiredParameterMatcher
Returns a new instance of RequiredParameterMatcher.
10 11 12 13 14 15 16 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 10 def initialize(attribute) super(attribute) @default_value = nil @attribute = attribute @allowed_values = nil @disallowed_values = nil end |
Instance Attribute Details
#allowed_values ⇒ Object
Returns the value of attribute allowed_values.
8 9 10 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 8 def allowed_values @allowed_values end |
#attribute ⇒ Object
Returns the value of attribute attribute.
8 9 10 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 8 def attribute @attribute end |
#default_value ⇒ Object
Returns the value of attribute default_value.
8 9 10 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 8 def default_value @default_value end |
#disallowed_values ⇒ Object
Returns the value of attribute disallowed_values.
8 9 10 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 8 def disallowed_values @disallowed_values end |
Instance Method Details
#description ⇒ Object
48 49 50 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 48 def description "require #{@attribute} to be set" end |
#failure_message_for_should ⇒ Object
52 53 54 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 52 def "Expected #{@default_value} to be set and to be one of #{@allowed_values}" end |
#failure_message_for_should_not ⇒ Object
56 57 58 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 56 def "Expected #{@default_value} not to be set and not to be one of #{@allowed_values}" end |
#matches?(subject) ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 33 def matches?(subject) super(subject) @expected_message ||= :blank if @default_value matches_default_value? elsif @allowed_values disallows_value_of(nil) && matches_allowed_values? elsif @disallowed_values matches_disallowed_values? else disallows_value_of(nil, @expected_message) end end |
#with_allowed_values(*values) ⇒ Object
23 24 25 26 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 23 def with_allowed_values(*values) @allowed_values = values self end |
#with_default(value) ⇒ Object
18 19 20 21 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 18 def with_default(value) @default_value = value self end |
#with_disallowed_values(*values) ⇒ Object
28 29 30 31 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 28 def with_disallowed_values(*values) @disallowed_values = values self end |