Class: RailsValidationApi::DSL
- Inherits:
-
Object
- Object
- RailsValidationApi::DSL
- Defined in:
- lib/rails_validation_api/dsl.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
- #param!(name, type, **opts, &block) ⇒ Object
Constructor Details
#initialize ⇒ DSL
7 8 9 |
# File 'lib/rails_validation_api/dsl.rb', line 7 def initialize @rules = {} end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
5 6 7 |
# File 'lib/rails_validation_api/dsl.rb', line 5 def rules @rules end |
Instance Method Details
#param!(name, type, **opts, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rails_validation_api/dsl.rb', line 11 def param!(name, type, **opts, &block) key = :"#{name}_validate" rule = { field: name, type: type, opts: [opts].compact } if block_given? nested = DSL.new nested.instance_eval(&block) rule[:items] = nested.rules.values end @rules[key] = rule end |