Class: SchemaExtractor::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_extractor/field.rb

Defined Under Namespace

Classes: InvalidFieldNameError, InvalidFieldTypeError, InvalidNullableValueError

Constant Summary collapse

TYPES =
i[
  date
  datetime
  decimal
  float
  integer
  string
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, nullable:, default: nil) ⇒ Field

Returns a new instance of Field.



22
23
24
25
26
27
# File 'lib/schema_extractor/field.rb', line 22

def initialize(name:, type:, nullable:, default: nil)
  @name = validate_name!(name)
  @type = validate_type!(type)
  @nullable = validate_nullable!(nullable)
  @default = validate_default!(default)
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



20
21
22
# File 'lib/schema_extractor/field.rb', line 20

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/schema_extractor/field.rb', line 17

def name
  @name
end

#nullableObject (readonly)

Returns the value of attribute nullable.



19
20
21
# File 'lib/schema_extractor/field.rb', line 19

def nullable
  @nullable
end

#typeObject (readonly)

Returns the value of attribute type.



18
19
20
# File 'lib/schema_extractor/field.rb', line 18

def type
  @type
end

Instance Method Details

#nullable?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/schema_extractor/field.rb', line 29

def nullable?
  nullable
end