Class: Grape::Validations::ParamsScope
- Inherits:
-
Object
- Object
- Grape::Validations::ParamsScope
- Includes:
- DSL::Parameters
- Defined in:
- lib/grape/validations.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
Returns the value of attribute element.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #full_name(name) ⇒ Object
-
#initialize(opts, &block) ⇒ ParamsScope
constructor
A new instance of ParamsScope.
- #root? ⇒ Boolean
- #should_validate?(parameters) ⇒ Boolean
Methods included from DSL::Parameters
#at_least_one_of, #exactly_one_of, #group, #mutually_exclusive, #optional, #params, #requires, #use
Constructor Details
#initialize(opts, &block) ⇒ ParamsScope
Returns a new instance of ParamsScope.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/grape/validations.rb', line 85 def initialize(opts, &block) @element = opts[:element] @parent = opts[:parent] @api = opts[:api] @optional = opts[:optional] || false @type = opts[:type] @declared_params = [] instance_eval(&block) if block_given? configure_declared_params end |
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
81 82 83 |
# File 'lib/grape/validations.rb', line 81 def element @element end |
#parent ⇒ Object
Returns the value of attribute parent.
81 82 83 |
# File 'lib/grape/validations.rb', line 81 def parent @parent end |
Instance Method Details
#full_name(name) ⇒ Object
104 105 106 107 |
# File 'lib/grape/validations.rb', line 104 def full_name(name) return "#{@parent.full_name(@element)}[#{name}]" if @parent name.to_s end |
#root? ⇒ Boolean
109 110 111 |
# File 'lib/grape/validations.rb', line 109 def root? !@parent end |
#should_validate?(parameters) ⇒ Boolean
98 99 100 101 102 |
# File 'lib/grape/validations.rb', line 98 def should_validate?(parameters) return false if @optional && params(parameters).respond_to?(:all?) && params(parameters).all?(&:blank?) return true if parent.nil? parent.should_validate?(parameters) end |