Class: SDL::Field Abstract
- Inherits:
-
Object
- Object
- SDL::Field
- Defined in:
- lib/sdl/field.rb
Overview
A base class for all fields of a model
Direct Known Subclasses
Defined Under Namespace
Modules: ColumnOptions
Instance Attribute Summary collapse
-
#name ⇒ Name
readonly
The name of the field.
-
#options ⇒ Hash
readonly
All options that were passed to the field.
Instance Method Summary collapse
-
#association? ⇒ Boolean
Indicates that this is an Association.
-
#attachment? ⇒ Boolean
Indicates that this is an Attachment.
-
#attribute? ⇒ Boolean
Indicates that this is an Attribute.
-
#belongs_to? ⇒ Boolean
Indicates that this is an Association::BelongsTo.
-
#binary? ⇒ Boolean
Indicates that this is an Attribute whose type is
:binary
. -
#boolean? ⇒ Boolean
Indicates that this is an Attribute whose type is
:boolean
. -
#date? ⇒ Boolean
Indicates that this is an Attribute whose type is
:date
. -
#datetime? ⇒ Boolean
Indicates that this is an Attribute whose type is
:datetime
. -
#decimal? ⇒ Boolean
Indicates that this is an Attribute whose type is
:decimal
. -
#enum? ⇒ Boolean
Indicates that this is an Enum.
-
#float? ⇒ Boolean
Indicates that this is an Attribute whose type is
:float
. -
#has_many? ⇒ Boolean
Indicates that this is an Association::HasMany.
-
#has_many_attached? ⇒ Boolean
Indicates that this is an Attachment::HasMany.
-
#has_one? ⇒ Boolean
Indicates that this is an Association::HasOne.
-
#has_one_attached? ⇒ Boolean
Indicates that this is an Attachment::HasOne.
-
#id? ⇒ Boolean
Indicates that this is an Attribute whose type is
:id
. -
#initialize(name, **options) ⇒ Field
constructor
private
A new instance of Field.
-
#integer? ⇒ Boolean
Indicates that this is an Attribute whose type is
:integer
. -
#nullable? ⇒ Boolean
Can this field be null? By default, this is
false
. -
#required? ⇒ Boolean
The opposite of #nullable?.
-
#string? ⇒ Boolean
Indicates that this is an Attribute whose type is
:string
. -
#text? ⇒ Boolean
Indicates that this is an Attribute whose type is
:text
. -
#type ⇒ Symbol
abstract
The type of the field.
-
#type_name ⇒ Name
The name of the type.
Constructor Details
#initialize(name, **options) ⇒ Field
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Field.
17 18 19 20 |
# File 'lib/sdl/field.rb', line 17 def initialize(name, **) @name = Name.new(name.to_s) @options = end |
Instance Attribute Details
#name ⇒ Name (readonly)
The name of the field
10 11 12 |
# File 'lib/sdl/field.rb', line 10 def name @name end |
#options ⇒ Hash (readonly)
All options that were passed to the field
14 15 16 |
# File 'lib/sdl/field.rb', line 14 def @options end |
Instance Method Details
#association? ⇒ Boolean
Indicates that this is an Association
36 37 38 |
# File 'lib/sdl/field.rb', line 36 def association? has_one? || has_many? || belongs_to? end |
#attachment? ⇒ Boolean
Indicates that this is an Attachment
30 31 32 |
# File 'lib/sdl/field.rb', line 30 def has_one_attached? || has_many_attached? end |
#attribute? ⇒ Boolean
Indicates that this is an Attribute
24 25 26 |
# File 'lib/sdl/field.rb', line 24 def attribute? !enum? && !association? && ! end |
#belongs_to? ⇒ Boolean
Indicates that this is an Association::BelongsTo
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#binary? ⇒ Boolean
Indicates that this is an Attribute whose type is :binary
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#boolean? ⇒ Boolean
Indicates that this is an Attribute whose type is :boolean
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#date? ⇒ Boolean
Indicates that this is an Attribute whose type is :date
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#datetime? ⇒ Boolean
Indicates that this is an Attribute whose type is :datetime
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#decimal? ⇒ Boolean
Indicates that this is an Attribute whose type is :decimal
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#enum? ⇒ Boolean
Indicates that this is an Enum
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#float? ⇒ Boolean
Indicates that this is an Attribute whose type is :float
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#has_many? ⇒ Boolean
Indicates that this is an Association::HasMany
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#has_many_attached? ⇒ Boolean
Indicates that this is an Attachment::HasMany
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#has_one? ⇒ Boolean
Indicates that this is an Association::HasOne
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#has_one_attached? ⇒ Boolean
Indicates that this is an Attachment::HasOne
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#id? ⇒ Boolean
Indicates that this is an Attribute whose type is :id
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#integer? ⇒ Boolean
Indicates that this is an Attribute whose type is :integer
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#nullable? ⇒ Boolean
Can this field be null? By default, this is false
. But, it can
be overridden by passing nullable: true
to a field.
43 44 45 |
# File 'lib/sdl/field.rb', line 43 def nullable? .fetch(:nullable, false) end |
#required? ⇒ Boolean
The opposite of #nullable?. All fields are required by default
49 50 51 |
# File 'lib/sdl/field.rb', line 49 def required? !nullable? end |
#string? ⇒ Boolean
Indicates that this is an Attribute whose type is :string
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#text? ⇒ Boolean
Indicates that this is an Attribute whose type is :text
114 115 116 117 118 |
# File 'lib/sdl/field.rb', line 114 TYPES.each do |meth| define_method "#{meth}?" do type == meth end end |
#type ⇒ Symbol
The type of the field
56 57 58 |
# File 'lib/sdl/field.rb', line 56 def type raise NotImplementedError, __method__ end |