Module: Koi::Helpers::AttributeTypes

Defined in:
lib/generators/koi/helpers/attribute_types.rb

Defined Under Namespace

Modules: GeneratedAttributeExtensions Classes: ArchivedType, AssociationType, AttachmentType, Base, BooleanType, DateType, DatetimeType, EnumType, IntegerType, OrdinalType, RichTextType, StringType

Constant Summary collapse

TYPES =
{
  string:     StringType,
  integer:    IntegerType,
  boolean:    BooleanType,
  date:       DateType,
  datetime:   DatetimeType,
  rich_text:  RichTextType,
  text:       StringType,
  attachment: AttachmentType,
  enum:       EnumType,
}.freeze

Class Method Summary collapse

Class Method Details

.for(attribute) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/generators/koi/helpers/attribute_types.rb', line 199

def for(attribute)
  if attribute.association?
    AssociationType.new(attribute)
  elsif attribute.attachment?
    AttachmentType.new(attribute)
  elsif attribute.enum?
    EnumType.new(attribute)
  elsif attribute.name == "ordinal"
    OrdinalType.new(attribute)
  elsif attribute.name == "archived_at"
    ArchivedType.new(attribute)
  else
    TYPES.fetch(attribute.type, StringType).new(attribute)
  end
end