module Enja::Generators::Helper
Private Instance Methods
attribute_name()
click to toggle source
# File lib/generators/enja/helper.rb, line 36 def attribute_name options.key?(:attribute) ? options[:attribute].underscore : "role" end
migration_class_name()
click to toggle source
# File lib/generators/enja/helper.rb, line 40 def migration_class_name if Rails::VERSION::MAJOR >= 5 "ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" else "ActiveRecord::Migration" end end
model_class_name()
click to toggle source
# File lib/generators/enja/helper.rb, line 8 def model_class_name options.key?(:model) ? options[:model].classify : "User" end
model_file_path()
click to toggle source
# File lib/generators/enja/helper.rb, line 12 def model_file_path model_name.underscore end
model_name()
click to toggle source
# File lib/generators/enja/helper.rb, line 28 def model_name if namespaced? [namespace.to_s] + [model_class_name] else [model_class_name] end.join("::") end
model_path()
click to toggle source
# File lib/generators/enja/helper.rb, line 16 def model_path @model_path ||= File.join("app", "models", "#{model_file_path}.rb") end
namespace()
click to toggle source
# File lib/generators/enja/helper.rb, line 20 def namespace Rails::Generators.namespace if Rails::Generators.respond_to?(:namespace) end
namespaced?()
click to toggle source
# File lib/generators/enja/helper.rb, line 24 def namespaced? !!namespace end
next_migration_number(dirname)
click to toggle source
Define the next_migration_number
method (necessary for the migration_template method to work)
# File lib/generators/enja/helper.rb, line 50 def next_migration_number(dirname) if ActiveRecord::Base.timestamped_migrations sleep 1 # make sure each time we get a different timestamp Time.new.utc.strftime("%Y%m%d%H%M%S") else format("%.3d", (current_migration_number(dirname) + 1)) end end