Class: Taro::Types::FieldDef

Inherits:
Object
  • Object
show all
Defined in:
lib/taro/types/field_def.rb

Overview

Lazily-evaluated field definition.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defined_at: nil, **attributes) ⇒ FieldDef

Returns a new instance of FieldDef.



5
6
7
8
9
# File 'lib/taro/types/field_def.rb', line 5

def initialize(defined_at: nil, **attributes)
  @attributes = attributes
  @defined_at = defined_at
  validate
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/taro/types/field_def.rb', line 3

def attributes
  @attributes
end

#defined_atObject (readonly)

Returns the value of attribute defined_at.



3
4
5
# File 'lib/taro/types/field_def.rb', line 3

def defined_at
  @defined_at
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
# File 'lib/taro/types/field_def.rb', line 23

def ==(other)
  other.is_a?(self.class) && attributes == other.attributes
end

#evaluateObject



11
12
13
14
15
16
17
# File 'lib/taro/types/field_def.rb', line 11

def evaluate
  Taro::Types::Field.new(
    **attributes.except(*Taro::Types::Coercion.keys),
    defined_at:,
    type: Taro::Types::Coercion.call(attributes),
  )
end

#nameObject



19
20
21
# File 'lib/taro/types/field_def.rb', line 19

def name
  attributes[:name]
end