Class: Alchemrest::Data::Field
- Inherits:
-
Object
- Object
- Alchemrest::Data::Field
- Defined in:
- lib/alchemrest/data/field.rb
Instance Method Summary collapse
- #constraints ⇒ Object
-
#initialize(transform:, name:, required: false) ⇒ Field
constructor
A new instance of Field.
- #output_type ⇒ Object
Constructor Details
#initialize(transform:, name:, required: false) ⇒ Field
Returns a new instance of Field.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/alchemrest/data/field.rb', line 8 def initialize(transform:, name:, required: false) unless transform.is_a?(Morpher::Transform) || transform.is_a?(Data) raise ArgumentError, "transform must be an instance of Morpher::Transform or Alchemrest::Data, not #{transform.class}" end raise ArgumentError, "must provide name" unless name raise ArgumentError, "must provide non-empty name" if name.to_s.strip.empty? @transform = transform @name = name.to_s @required = required && !transform.instance_of?(Morpher::Transform::Maybe) end |
Instance Method Details
#constraints ⇒ Object
31 32 33 |
# File 'lib/alchemrest/data/field.rb', line 31 def constraints output_type&.constraints || [] end |
#output_type ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/alchemrest/data/field.rb', line 20 def output_type base_type = transform.output_type if transform.respond_to?(:output_type) return unless base_type if required base_type else base_type.with(sorbet_type: T.nilable(base_type.sorbet_type)) end end |