class SDL::Field
A base class for all fields of a model @abstract
Attributes
name[R]
The name of the field @return [Name]
options[R]
All options that were passed to the field @return [Hash]
Public Class Methods
new(name, **options)
click to toggle source
@api private
# File lib/sdl/field.rb, line 17 def initialize(name, **options) @name = Name.new(name.to_s) @options = options end
Public Instance Methods
association?()
click to toggle source
Indicates that this is an {Association} @return [Boolean]
# File lib/sdl/field.rb, line 36 def association? has_one? || has_many? || belongs_to? end
attachment?()
click to toggle source
Indicates that this is an {Attachment} @return [Boolean]
# File lib/sdl/field.rb, line 30 def attachment? has_one_attached? || has_many_attached? end
attribute?()
click to toggle source
Indicates that this is an {Attribute} @return [Boolean]
# File lib/sdl/field.rb, line 24 def attribute? !enum? && !association? && !attachment? end
nullable?()
click to toggle source
Can this field be null? By default, this is `false`. But, it can be overridden by passing `nullable: true` to a field. @return [Boolean]
# File lib/sdl/field.rb, line 43 def nullable? options.fetch(:nullable, false) end
required?()
click to toggle source
The opposite of {#nullable?}. All fields are required by default @return [Boolean]
# File lib/sdl/field.rb, line 49 def required? !nullable? end
type()
click to toggle source
The type of the field @abstract @return [Symbol]
# File lib/sdl/field.rb, line 56 def type raise NotImplementedError, __method__ end
type_name()
click to toggle source
The name of the type @return [Name]
# File lib/sdl/field.rb, line 62 def type_name Name.new(type.to_s) end