Class: MigrationDefs::MigrationMethod

Inherits:
AbstractMigrationClass show all
Defined in:
lib/migration_defs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ MigrationMethod

Returns a new instance of MigrationMethod.



87
88
89
90
91
92
# File 'lib/migration_defs.rb', line 87

def initialize(name)
  return nil if !MethodName.include? name

  @name = name
  @funcs = Array.new
end

Instance Attribute Details

#funcsObject

Returns the value of attribute funcs.



85
86
87
# File 'lib/migration_defs.rb', line 85

def funcs
  @funcs
end

#nameObject

Returns the value of attribute name.



85
86
87
# File 'lib/migration_defs.rb', line 85

def name
  @name
end

Instance Method Details

#add_func(name, func_name, *func_options) ⇒ Object



94
95
96
# File 'lib/migration_defs.rb', line 94

def add_func(name, func_name, *func_options)
  @funcs << FuncFactory::get(name, func_name, func_options)
end

#get_strObject



113
114
115
116
117
118
119
# File 'lib/migration_defs.rb', line 113

def get_str
  result = "def #{@name}\n"
  @funcs.each do |func|
    result += func.get_str if !func.nil?
  end
  result += "end\n"
end

#parse_from_params(parse_params) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/migration_defs.rb', line 98

def parse_from_params(parse_params)
  return '' if parse_params[:funcs].nil?

  parse_params[:funcs].each do |val|
    add_func(val[:name], val[:table_name]) if val[:delete] != 'true'
  end
  index = 0
  parse_params[:funcs].each do |val|#not DRY
    if val[:delete] != 'true'
      @funcs[index].parse_from_params(val)
      index += 1
    end
  end
end