Class: LcpRuby::Dsl::FieldBuilder
- Inherits:
-
Object
- Object
- LcpRuby::Dsl::FieldBuilder
- Defined in:
- lib/lcp_ruby/dsl/field_builder.rb
Instance Attribute Summary collapse
-
#validations ⇒ Object
readonly
Returns the value of attribute validations.
Instance Method Summary collapse
-
#initialize ⇒ FieldBuilder
constructor
A new instance of FieldBuilder.
- #validates(type, **options) ⇒ Object
Constructor Details
#initialize ⇒ FieldBuilder
Returns a new instance of FieldBuilder.
6 7 8 |
# File 'lib/lcp_ruby/dsl/field_builder.rb', line 6 def initialize @validations = [] end |
Instance Attribute Details
#validations ⇒ Object (readonly)
Returns the value of attribute validations.
4 5 6 |
# File 'lib/lcp_ruby/dsl/field_builder.rb', line 4 def validations @validations end |
Instance Method Details
#validates(type, **options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lcp_ruby/dsl/field_builder.rb', line 10 def validates(type, **) validation = { "type" => type.to_s } validator_class = .delete(:validator_class) validation["validator_class"] = validator_class if validator_class when_condition = .delete(:when) validation["when"] = when_condition if when_condition field_ref = .delete(:field_ref) validation["field_ref"] = field_ref.to_s if field_ref operator = .delete(:operator) validation["operator"] = operator.to_s if operator = .delete(:message) validation["message"] = if service = .delete(:service) validation["service"] = service.to_s if service validation["options"] = stringify_keys() unless .empty? @validations << validation end |