Module: GeneratorUtils

Defined in:
lib/generators/generator_utils.rb

Constant Summary collapse

RAILS_ADDED_COLS =
%w(id created_at updated_at)
ATTR_SORT_PROC =

TODO…There has GOT to be a better way to do this (column name gets listed first if it contains the word “name”)

proc do |a, b|
  if a =~ /name/
    1
  elsif b =~ /name/
    -1
  elsif a =~ /email/
    1
  elsif b =~ /email/
    -1
  else
    0
  end
end

Class Method Summary collapse

Class Method Details

.attr_cols(table_name) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/generators/generator_utils.rb', line 22

def self.attr_cols(table_name)
  #return an array of the columns we are interested in allowing the user to change...
  # as GeneratedAttribute objects
  acs = table_name.classify.constantize.columns
    .reject{ |col| RAILS_ADDED_COLS.include?(col.name) }
    .sort(&ATTR_SORT_PROC)
    .map { |ac| Rails::Generators::GeneratedAttribute.new(ac.name, ac.type)}
end

.curr_localeObject



31
32
33
# File 'lib/generators/generator_utils.rb', line 31

def self.curr_locale
  I18n.locale.to_s
end