Class: Saruman::ModelBuilderField
- Inherits:
-
Object
- Object
- Saruman::ModelBuilderField
- Defined in:
- lib/saruman.rb
Constant Summary collapse
- SQL_TYPE_MAPPINGS =
{:string => "varchar(255)", :text => "text NOT NULL", :boolean => "tinyint(1) NOT NULL default 0", :date => "DATETIME default NULL", :int => "int(10)", :integer => "int(10)" }
- SQL_LINE_PADDING =
" "
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#index_sql ⇒ Object
Returns the value of attribute index_sql.
-
#segs ⇒ Object
Returns the value of attribute segs.
-
#sql ⇒ Object
Returns the value of attribute sql.
-
#sql_type ⇒ Object
Returns the value of attribute sql_type.
Instance Method Summary collapse
- #index? ⇒ Boolean
-
#initialize(field, model_table_name) ⇒ ModelBuilderField
constructor
A new instance of ModelBuilderField.
Constructor Details
#initialize(field, model_table_name) ⇒ ModelBuilderField
Returns a new instance of ModelBuilderField.
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/saruman.rb', line 464 def initialize(field, model_table_name) @segs = field.split(":") case segs.length when 1 @sql_type = :string when 2 @sql_type = segs[1].to_sym when 3 @sql_type = segs[1].to_sym end @sql = "#{SQL_LINE_PADDING}`#{segs[0]}` #{SQL_TYPE_MAPPINGS[sql_type]}" if index? @index = true @index_sql = "#{SQL_LINE_PADDING}KEY `IDX_#{model_table_name.upcase}_#{segs[0].upcase}` (`#{segs[0]}`),\n" end end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
461 462 463 |
# File 'lib/saruman.rb', line 461 def index @index end |
#index_sql ⇒ Object
Returns the value of attribute index_sql.
461 462 463 |
# File 'lib/saruman.rb', line 461 def index_sql @index_sql end |
#segs ⇒ Object
Returns the value of attribute segs.
461 462 463 |
# File 'lib/saruman.rb', line 461 def segs @segs end |
#sql ⇒ Object
Returns the value of attribute sql.
461 462 463 |
# File 'lib/saruman.rb', line 461 def sql @sql end |
#sql_type ⇒ Object
Returns the value of attribute sql_type.
461 462 463 |
# File 'lib/saruman.rb', line 461 def sql_type @sql_type end |
Instance Method Details
#index? ⇒ Boolean
483 484 485 486 487 488 489 |
# File 'lib/saruman.rb', line 483 def index? if(@segs.length==3) return true else return false end end |