Class: Saruman::ModelBuilderField

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#indexObject

Returns the value of attribute index.



461
462
463
# File 'lib/saruman.rb', line 461

def index
  @index
end

#index_sqlObject

Returns the value of attribute index_sql.



461
462
463
# File 'lib/saruman.rb', line 461

def index_sql
  @index_sql
end

#segsObject

Returns the value of attribute segs.



461
462
463
# File 'lib/saruman.rb', line 461

def segs
  @segs
end

#sqlObject

Returns the value of attribute sql.



461
462
463
# File 'lib/saruman.rb', line 461

def sql
  @sql
end

#sql_typeObject

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

Returns:

  • (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