Class: FieldFactory
- Inherits:
-
Object
- Object
- FieldFactory
- Defined in:
- lib/generators/hot_glue/field_factory.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#field ⇒ Object
Returns the value of attribute field.
Instance Method Summary collapse
-
#initialize(type:, name:, generator:) ⇒ FieldFactory
constructor
A new instance of FieldFactory.
Constructor Details
#initialize(type:, name:, generator:) ⇒ FieldFactory
Returns a new instance of FieldFactory.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/hot_glue/field_factory.rb', line 17 def initialize(type: , name: , generator: ) field_class = case type when :integer if name.to_s.ends_with?("_id") AssociationField else IntegerField end when :uuid UUIDField when :string StringField when :text TextField when :float FloatField when :decimal FloatField when :datetime DateTimeField when :date DateField when :time TimeField when :boolean BooleanField when :enum EnumField when :attachment AttachmentField when :related_set RelatedSetField end @class_name = class_name if field_class.nil? raise "Field type could be identified #{name} " end @field = field_class.new(scaffold: generator, name: name) end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
16 17 18 |
# File 'lib/generators/hot_glue/field_factory.rb', line 16 def class_name @class_name end |
#field ⇒ Object
Returns the value of attribute field.
16 17 18 |
# File 'lib/generators/hot_glue/field_factory.rb', line 16 def field @field end |