Class: Option

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



429
430
431
432
433
434
435
436
437
# File 'lib/schema.rb', line 429

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    hint: d["hint"],
    label: d.fetch("label"),
    required: d["required"] ? AllowDependencyFailureUnion.from_dynamic!(d["required"]) : nil,
    value: d.fetch("value")
  )
end

.from_json!(json) ⇒ Object



439
440
441
# File 'lib/schema.rb', line 439

def self.from_json!(json)
  from_dynamic!(JSON.parse(json))
end

Instance Method Details

#to_dynamicObject



443
444
445
446
447
448
449
450
# File 'lib/schema.rb', line 443

def to_dynamic
  {
    "hint" => hint,
    "label" => label,
    "required" => required&.to_dynamic,
    "value" => value
  }
end

#to_json(options = nil) ⇒ Object



452
453
454
# File 'lib/schema.rb', line 452

def to_json(options = nil)
  JSON.generate(to_dynamic, options)
end