module UserNaming::Generators::Helpers
Private Instance Methods
class_path()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 82 def class_path @class_path end
copy_migration(migration_name, config = {})
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 6 def copy_migration(migration_name, config = {}) unless migration_exists?(migration_name) migration_template( "db/migrate/#{migration_name}", "db/migrate/#{migration_name}", config.merge(migration_version: migration_version) ) end end
existing_migrations()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 21 def existing_migrations @existing_migrations ||= Dir.glob('db/migrate/*.rb').map do |file| migration_name_without_timestamp(file) end end
file_path()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 51 def file_path model_name.underscore end
migration_exists?(name)
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 17 def migration_exists?(name) existing_migrations.include?(name) end
migration_name_without_timestamp(file)
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 27 def migration_name_without_timestamp(file) file.sub(%r{^.*(db/migrate/)(?:\d+_)?}, '') end
migration_version()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 34 def migration_version if Rails.version >= '5.0.0' "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end
model_class_name()
click to toggle source
Either return the model passed in a classified form or return the default “User”.
# File lib/generators/user_naming/helpers.rb, line 43 def model_class_name options[:model] ? options[:model].classify : 'User' end
model_name()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 63 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/user_naming/helpers.rb, line 47 def model_path @model_path ||= File.join('app', 'models', "#{file_path}.rb") end
namespace()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 55 def namespace Rails::Generators.namespace if Rails::Generators.respond_to?(:namespace) end
namespaced?()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 59 def namespaced? !namespace.nil? end
plural_name()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 90 def plural_name singular_name.pluralize end
singular_name()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 86 def singular_name @file_name end
table_name()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 75 def table_name @table_name ||= begin base = plural_name (class_path + [base]).join('_') end end
table_reference_name()
click to toggle source
# File lib/generators/user_naming/helpers.rb, line 71 def table_reference_name table_name.singularize end