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.
-
#if_given ⇒ Object
readonly
Returns the value of attribute if_given.
-
#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.
-
#rename_as ⇒ Object
readonly
Returns the value of attribute rename_as.
-
#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.
- #rename? ⇒ Boolean
- #skip?(request_params) ⇒ Boolean
- #sub_definition ⇒ Object
- #transform? ⇒ Boolean
- #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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/request_params_validation/definitions/param.rb', line 9 def initialize(, &block) @key = [:key] @required = [:required] @allow_blank = [:allow_blank] @type = [:type].try(:to_sym) @rename_as = [:as].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]) @if_given = build_if_given_option([:if_given]) @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.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def allow_blank @allow_blank end |
#custom_validation ⇒ Object (readonly)
Returns the value of attribute custom_validation.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def custom_validation @custom_validation end |
#decimal_precision ⇒ Object (readonly)
Returns the value of attribute decimal_precision.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def decimal_precision @decimal_precision end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def elements @elements end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def format @format end |
#if_given ⇒ Object (readonly)
Returns the value of attribute if_given.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def if_given @if_given end |
#inclusion ⇒ Object (readonly)
Returns the value of attribute inclusion.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def inclusion @inclusion end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def key @key end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def length @length end |
#rename_as ⇒ Object (readonly)
Returns the value of attribute rename_as.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def rename_as @rename_as end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def required @required end |
#transform ⇒ Object (readonly)
Returns the value of attribute transform.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def transform @transform end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/request_params_validation/definitions/param.rb', line 6 def value @value end |
Instance Method Details
#default ⇒ Object
36 37 38 |
# File 'lib/request_params_validation/definitions/param.rb', line 36 def default @default.respond_to?(:call) ? @default.call : @default end |
#element_of_array? ⇒ Boolean
44 45 46 |
# File 'lib/request_params_validation/definitions/param.rb', line 44 def element_of_array? !!@element_of_array end |
#has_default? ⇒ Boolean
32 33 34 |
# File 'lib/request_params_validation/definitions/param.rb', line 32 def has_default? !@default.nil? # default value could be `false` end |
#rename? ⇒ Boolean
78 79 80 |
# File 'lib/request_params_validation/definitions/param.rb', line 78 def rename? !!@rename_as end |
#skip?(request_params) ⇒ Boolean
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/request_params_validation/definitions/param.rb', line 86 def skip?(request_params) return false unless @if_given if_given_param_value = request_params[@if_given.param] if @if_given.function !@if_given.function.call(if_given_param_value) else if_given_param_value.blank? end end |
#sub_definition ⇒ Object
40 41 42 |
# File 'lib/request_params_validation/definitions/param.rb', line 40 def sub_definition @sub_definition || @elements.try(:sub_definition) end |
#transform? ⇒ Boolean
82 83 84 |
# File 'lib/request_params_validation/definitions/param.rb', line 82 def transform? !!@transform end |
#validate_custom_validation? ⇒ Boolean
74 75 76 |
# File 'lib/request_params_validation/definitions/param.rb', line 74 def validate_custom_validation? !!@custom_validation end |
#validate_format? ⇒ Boolean
68 69 70 71 72 |
# File 'lib/request_params_validation/definitions/param.rb', line 68 def validate_format? return false if [Params::DATE_TYPE, Params::DATETIME_TYPE].include?(@type) !!@format end |
#validate_inclusion? ⇒ Boolean
56 57 58 |
# File 'lib/request_params_validation/definitions/param.rb', line 56 def validate_inclusion? !!@inclusion end |
#validate_length? ⇒ Boolean
60 61 62 |
# File 'lib/request_params_validation/definitions/param.rb', line 60 def validate_length? !!@length end |
#validate_presence? ⇒ Boolean
48 49 50 |
# File 'lib/request_params_validation/definitions/param.rb', line 48 def validate_presence? !!@required end |
#validate_type? ⇒ Boolean
52 53 54 |
# File 'lib/request_params_validation/definitions/param.rb', line 52 def validate_type? !!@type end |
#validate_value? ⇒ Boolean
64 65 66 |
# File 'lib/request_params_validation/definitions/param.rb', line 64 def validate_value? !!@value end |