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.
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
Constructor Details
#initialize(attribute) ⇒ RequiredParameterMatcher
Returns a new instance of RequiredParameterMatcher.
10 11 12 13 14 15 |
# 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 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 |
Instance Method Details
#description ⇒ Object
40 41 42 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 40 def description "require #{@attribute} to be set" end |
#failure_message_for_should ⇒ Object
44 45 46 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 44 def "Expected #{@default_value} to be set and to be one of #{@allowed_values}" end |
#failure_message_for_should_not ⇒ Object
48 49 50 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 48 def "Expected #{@default_value} not to be set and not to be one of #{@allowed_values}" end |
#matches?(subject) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 27 def matches?(subject) super(subject) ||= :blank if @default_value matches_default_value? elsif @allowed_values disallows_value_of(nil) && matches_allowed_values? else disallows_value_of(nil, ) end end |
#with_allowed_values(*values) ⇒ Object
22 23 24 25 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 22 def with_allowed_values(*values) @allowed_values = values self end |
#with_default(value) ⇒ Object
17 18 19 20 |
# File 'lib/simple_params/validation_matchers/required_parameter_matcher.rb', line 17 def with_default(value) @default_value = value self end |