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.



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

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.



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

def funcs
  @funcs
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

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



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

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

#get_strObject



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

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



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

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