Class: RequestParamsValidation::Definitions::Param
- Inherits:
-
Object
- Object
- RequestParamsValidation::Definitions::Param
- Defined in:
- lib/request_params_validation/definitions/param.rb
Instance Attribute Summary collapse
-
#allow_blank ⇒ Object
readonly
Returns the value of attribute allow_blank.
-
#custom_validation ⇒ Object
readonly
Returns the value of attribute custom_validation.
-
#decimal_precision ⇒ Object
readonly
Returns the value of attribute decimal_precision.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#inclusion ⇒ Object
readonly
Returns the value of attribute inclusion.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#transform ⇒ Object
readonly
Returns the value of attribute transform.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #default ⇒ Object
- #element_of_array? ⇒ Boolean
- #has_default? ⇒ Boolean
-
#initialize(options, &block) ⇒ Param
constructor
A new instance of Param.
- #sub_definition ⇒ Object
- #validate_custom_validation? ⇒ Boolean
- #validate_format? ⇒ Boolean
- #validate_inclusion? ⇒ Boolean
- #validate_length? ⇒ Boolean
- #validate_presence? ⇒ Boolean
- #validate_type? ⇒ Boolean
- #validate_value? ⇒ Boolean
Constructor Details
#initialize(options, &block) ⇒ Param
Returns a new instance of Param.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/request_params_validation/definitions/param.rb', line 10 def initialize(, &block) @key = [:key] @required = [:required] @allow_blank = [:allow_blank] @type = [:type].try(:to_sym) @default = [:default] @transform = [:transform] @decimal_precision = [:precision] @element_of_array = [:element_of_array] @inclusion = build_inclusion_option([:inclusion]) @length = build_length_option([:length]) @value = build_value_option([:value]) @format = build_format_option([:format]) @custom_validation = build_custom_validation_option([:validate]) @elements = build_elements_option([:elements], &block) @sub_definition = build_sub_definition(&block) end |
Instance Attribute Details
#allow_blank ⇒ Object (readonly)
Returns the value of attribute allow_blank.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def allow_blank @allow_blank end |
#custom_validation ⇒ Object (readonly)
Returns the value of attribute custom_validation.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def custom_validation @custom_validation end |
#decimal_precision ⇒ Object (readonly)
Returns the value of attribute decimal_precision.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def decimal_precision @decimal_precision end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def elements @elements end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def format @format end |
#inclusion ⇒ Object (readonly)
Returns the value of attribute inclusion.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def inclusion @inclusion end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def key @key end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def length @length end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def required @required end |
#transform ⇒ Object (readonly)
Returns the value of attribute transform.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def transform @transform end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/request_params_validation/definitions/param.rb', line 7 def value @value end |
Instance Method Details
#default ⇒ Object
35 36 37 |
# File 'lib/request_params_validation/definitions/param.rb', line 35 def default @default.respond_to?(:call) ? @default.call : @default end |
#element_of_array? ⇒ Boolean
43 44 45 |
# File 'lib/request_params_validation/definitions/param.rb', line 43 def element_of_array? !!@element_of_array end |
#has_default? ⇒ Boolean
31 32 33 |
# File 'lib/request_params_validation/definitions/param.rb', line 31 def has_default? !@default.nil? # default value could be `false` end |
#sub_definition ⇒ Object
39 40 41 |
# File 'lib/request_params_validation/definitions/param.rb', line 39 def sub_definition @sub_definition || @elements.try(:sub_definition) end |
#validate_custom_validation? ⇒ Boolean
73 74 75 |
# File 'lib/request_params_validation/definitions/param.rb', line 73 def validate_custom_validation? !!@custom_validation end |
#validate_format? ⇒ Boolean
67 68 69 70 71 |
# File 'lib/request_params_validation/definitions/param.rb', line 67 def validate_format? return false if [Params::DATE_TYPE, Params::DATETIME_TYPE].include?(@type) !!@format end |
#validate_inclusion? ⇒ Boolean
55 56 57 |
# File 'lib/request_params_validation/definitions/param.rb', line 55 def validate_inclusion? !!@inclusion end |
#validate_length? ⇒ Boolean
59 60 61 |
# File 'lib/request_params_validation/definitions/param.rb', line 59 def validate_length? !!@length end |
#validate_presence? ⇒ Boolean
47 48 49 |
# File 'lib/request_params_validation/definitions/param.rb', line 47 def validate_presence? !!@required end |
#validate_type? ⇒ Boolean
51 52 53 |
# File 'lib/request_params_validation/definitions/param.rb', line 51 def validate_type? !!@type end |
#validate_value? ⇒ Boolean
63 64 65 |
# File 'lib/request_params_validation/definitions/param.rb', line 63 def validate_value? !!@value end |