Class: Spectifly::Sequel::FieldForMigration
- Inherits:
-
Object
- Object
- Spectifly::Sequel::FieldForMigration
- Defined in:
- lib/spectifly/sequel/field_for_migration.rb
Instance Attribute Summary collapse
-
#field_name ⇒ Object
Returns the value of attribute field_name.
-
#field_type ⇒ Object
Returns the value of attribute field_type.
-
#model ⇒ Object
Returns the value of attribute model.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(field, model, entity_references) ⇒ FieldForMigration
constructor
A new instance of FieldForMigration.
- #multiple_value_simple_type? ⇒ Boolean
- #render ⇒ Object
- #retrieve_options(field) ⇒ Object
- #single_value_simple_type? ⇒ Boolean
Constructor Details
#initialize(field, model, entity_references) ⇒ FieldForMigration
Returns a new instance of FieldForMigration.
6 7 8 9 10 11 12 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 6 def initialize(field, model, entity_references) @field = field @field_name = field.name @field_type = field.type @model = model @options = (field) end |
Instance Attribute Details
#field_name ⇒ Object
Returns the value of attribute field_name.
4 5 6 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 4 def field_name @field_name end |
#field_type ⇒ Object
Returns the value of attribute field_type.
4 5 6 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 4 def field_type @field_type end |
#model ⇒ Object
Returns the value of attribute model.
4 5 6 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 4 def model @model end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 4 def @options end |
Instance Method Details
#multiple_value_simple_type? ⇒ Boolean
40 41 42 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 40 def multiple_value_simple_type? @model_for_field.nil? && @field.multiple? end |
#render ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 21 def render template = if single_value_simple_type? 'single_value_simple_type_field' elsif multiple_value_simple_type? 'multiple_value_simple_type_field' end return if template.nil? path = File.(File.join(*File.dirname(__FILE__), 'erb', 'field', "#{template}.erb")) content = File.read(path) t = ERB.new(content, nil, '-') t.filename = path t.result(binding) end |
#retrieve_options(field) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 14 def (field) = [] << ':null => false' if field.required? << ':unique => true' if field.unique? end |
#single_value_simple_type? ⇒ Boolean
36 37 38 |
# File 'lib/spectifly/sequel/field_for_migration.rb', line 36 def single_value_simple_type? @model_for_field.nil? && !@field.multiple? end |