Skip to content

Fix Thor warning due to missing :after option #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix #inject_into_class causing Thor warning due to missing :after option
  • Loading branch information
Inkybro committed Jul 22, 2020
commit ede2267ac4452dff8529e84cb48d4b02579e7223
55 changes: 41 additions & 14 deletions lib/generators/sorcery/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,68 @@ module Generators
module Helpers
private

def sorcery_config_path
'config/initializers/sorcery.rb'
def file_path
model_name.underscore
end

def migration_class_name
if Rails::VERSION::MAJOR >= 5
"ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
else
'ActiveRecord::Migration'
end
end

# Either return the model passed in a classified form or return the default "User".
def model_class_name
options[:model] ? options[:model].classify : 'User'
end

def tableized_model_class
options[:model] ? options[:model].gsub(/::/, '').tableize : 'User'
def model_injection
indents = model_class_name.split('::').count
indents += 1 if namespace

"#{' ' * indents}authenticates_with_sorcery!\n"
end

def model_injection_point
"class #{model_class_name} < #{model_superclass_name}\n"
end

def model_name
if namespace
[namespace.to_s] + [model_class_name]
else
[model_class_name]
end.join('::')
end

def model_path
@model_path ||= File.join('app', 'models', "#{file_path}.rb")
end

def file_path
model_name.underscore
def model_superclass_name
if Rails::VERSION::MAJOR >= 5
'ApplicationRecord'
else
'ActiveRecord::Base'
end
end

def namespace
Rails::Generators.namespace if Rails::Generators.respond_to?(:namespace)
end

def namespaced?
!!namespace
def only_submodules?
options[:migrations] || options[:only_submodules]
end

def model_name
if namespaced?
[namespace.to_s] + [model_class_name]
else
[model_class_name]
end.join('::')
def sorcery_config_path
'config/initializers/sorcery.rb'
end

def tableized_model_class
model_class_name.gsub(/::/, '').tableize
end
end
end
Expand Down
25 changes: 3 additions & 22 deletions lib/generators/sorcery/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ def configure_model
return if only_submodules?

generate "model #{model_class_name} --skip-migration"
inject_sorcery_to_model
end

def inject_sorcery_to_model
indents = ' ' * (namespaced? ? 2 : 1)

inject_into_class(model_path, model_class_name, "#{indents}authenticates_with_sorcery!\n")

inject_into_class(model_path, model_class_name, model_injection, after: model_injection_point)
end

# Copy the migrations files to db/migrate folder
Expand All @@ -81,21 +76,7 @@ def self.next_migration_number(dirname)
else
format('%.3d', (current_migration_number(dirname) + 1))
end
end

private

def only_submodules?
options[:migrations] || options[:only_submodules]
end

def migration_class_name
if Rails::VERSION::MAJOR >= 5
"ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
else
'ActiveRecord::Migration'
end
end
end
end
end
end