class Mi::Generators::Base
Constants
- Methods
Attributes
arguments[R]
Public Class Methods
editable()
click to toggle source
# File lib/generators/mi.rb, line 19 def self.editable define_method :edit do if @edit editor = ENV['EDITOR'] || 'vim' fname = File.join('db/migrate', "#{@migration_number}_#{destination}.rb") system(editor, fname) end end end
next_migration_number(dirname)
click to toggle source
# File lib/generators/mi.rb, line 14 def self.next_migration_number(dirname) next_migration_number = current_migration_number(dirname) + 1 ActiveRecord::Migration.next_migration_number(next_migration_number) end
Public Instance Methods
parse_args()
click to toggle source
# File lib/generators/mi.rb, line 35 def parse_args @arguments = @_initializer[0..1].flatten if @arguments.delete('--version') @version = true end if @arguments.delete('--edit') @edit = true end end
version()
click to toggle source
# File lib/generators/mi.rb, line 47 def version if @version puts Mi::VERSION exit 0 # XXX: end end
Private Instance Methods
arg_groups()
click to toggle source
# File lib/generators/mi.rb, line 58 def arg_groups @arg_groups ||= ( args = arguments.reject{|x| x.start_with?('--')} current = nil res = args.group_by do |a| if %w[+ - %].include? a[0] current else current = a nil end end res.delete(nil) res ) end
migration_version()
click to toggle source
# File lib/generators/mi.rb, line 91 def migration_version return "" unless defined? ActiveRecord::Migration.current_version "[#{ActiveRecord::Migration.current_version}]" end
parse_column(col)
click to toggle source
TODO: parse options @param [String] col +COL_NAME:TYPE:{OPTIONS}
# File lib/generators/mi.rb, line 78 def parse_column(col) sc = StringScanner.new(col) name = sc.scan(/[^:]+/) sc.scan(/:/) type = sc.scan(/[^:]+/) sc.scan(/:/) options = sc.scan(/\{.+\}$/) method = name[0] name = name[1..-1] {name: name, type: type, options: options, method: method} end