mac_generators 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +12 -16
  3. data/lib/generators/authentication/email/email_generator.rb +62 -63
  4. data/lib/generators/authentication/email/templates/create_identities.rb +1 -2
  5. data/lib/generators/authentication/email/templates/database_authentication.rb +2 -0
  6. data/lib/generators/authentication/email/templates/identities_controller.rb +4 -2
  7. data/lib/generators/authentication/email/templates/identity.rb +2 -0
  8. data/lib/generators/authentication/email/templates/sessions_controller.rb +2 -0
  9. data/lib/generators/authentication/email/templates/warden.rb +3 -1
  10. data/lib/generators/authentication/omniauth/omniauth_generator.rb +69 -68
  11. data/lib/generators/authentication/omniauth/templates/authentication_domain.rb +1 -1
  12. data/lib/generators/authentication/omniauth/templates/create_identities.rb +1 -1
  13. data/lib/generators/bootstrap/bootstrap_generator.rb +13 -13
  14. data/lib/mac_generators/version.rb +1 -1
  15. data/test/dummy/Rakefile +1 -1
  16. data/test/dummy/app/assets/config/manifest.js +3 -0
  17. data/test/dummy/app/controllers/application_controller.rb +4 -4
  18. data/test/dummy/config.ru +1 -1
  19. data/test/dummy/config/application.rb +3 -4
  20. data/test/dummy/config/boot.rb +4 -4
  21. data/test/dummy/config/environment.rb +1 -1
  22. data/test/dummy/config/environments/development.rb +1 -1
  23. data/test/dummy/config/environments/production.rb +2 -2
  24. data/test/dummy/config/environments/test.rb +1 -1
  25. data/test/dummy/config/initializers/secret_token.rb +1 -1
  26. data/test/dummy/config/initializers/session_store.rb +1 -1
  27. data/test/dummy/config/routes.rb +3 -3
  28. data/test/dummy/log/test.log +2981 -0
  29. data/test/dummy/script/rails +3 -3
  30. data/test/dummy/tmp/Gemfile +2 -2
  31. data/test/dummy/tmp/app/controllers/application_controller.rb +17 -16
  32. data/test/dummy/tmp/config/initializers/authentication_domain.rb +1 -1
  33. data/test/dummy/tmp/config/routes.rb +2 -2
  34. data/test/dummy/tmp/db/migrate/create_identities.rb +1 -1
  35. data/test/generators/authentication_email_generator_test.rb +64 -66
  36. data/test/generators/authentication_omniauth_generator_test.rb +46 -46
  37. data/test/support/generators_test_helper.rb +4 -4
  38. data/test/test_helper.rb +2 -24
  39. metadata +39 -54
  40. data/test/dummy/db/development.sqlite3 +0 -0
  41. data/test/dummy/db/test.sqlite3 +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a0c6c6f50f69fc3f6941611f6d9fab72cac60c17
4
- data.tar.gz: 6e0a02d7487fe3b1cf4fcf4fc2bf584ae6361328
2
+ SHA256:
3
+ metadata.gz: baf8524f87d52021b03e6b6f5af70ab0c486f18e1b11839f40d6f5c3200e976f
4
+ data.tar.gz: 115b302ed421d852463e02b599cd100ecc2b2d4cceebb4d7619171637dea4753
5
5
  SHA512:
6
- metadata.gz: e870af3fb84accf9b357f9628a55ecca2433b4bdb0d39c9842064cec31bc5cb03b8f6e1e0bcf0a47694cd97ad08e5adc0565f7c23c4c3b0dde3951b92056df4f
7
- data.tar.gz: 0746550dd261a4615b533d9ce0e5dac9fc00b32ebf6078925cbbf9ef1e347e7a125e3a15738fd0e4ef2eb8c325fabd0299c41bf5be4c06666cc1f74e90ce70eb
6
+ metadata.gz: 895e123dc7242cb28ecec463ca019d67f4a6eac100bd6d8a0a27ab9704ca6366ec9aa5dfb4133a50e7ee84e775a64c341d554f801e15b63d7506baecc9dcd6c0
7
+ data.tar.gz: 99cfa1f0f0b26b31bc6fe9d3eda78fd320a1fe9331847590e7cef0c74aa7bf76f1b7a13b7d933e47368cdb6eda90cbea3e0161e0588df085650b47156c530c61
data/Rakefile CHANGED
@@ -1,32 +1,28 @@
1
1
  begin
2
- require 'bundler/setup'
2
+ require "bundler/setup"
3
3
  rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
5
  end
6
6
 
7
- require 'rdoc/task'
7
+ require "rdoc/task"
8
8
 
9
9
  RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'MacGenerators'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "MacGenerators"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.rdoc")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
15
15
  end
16
16
 
17
-
18
-
19
-
20
17
  Bundler::GemHelper.install_tasks
21
18
 
22
- require 'rake/testtask'
19
+ require "rake/testtask"
23
20
 
24
21
  Rake::TestTask.new(:test) do |t|
25
- t.libs << 'lib'
26
- t.libs << 'test'
27
- t.pattern = 'test/**/*_test.rb'
22
+ t.libs << "lib"
23
+ t.libs << "test"
24
+ t.pattern = "test/**/*_test.rb"
28
25
  t.verbose = false
29
26
  end
30
27
 
31
-
32
28
  task default: :test
@@ -1,29 +1,29 @@
1
1
  module Authentication
2
2
  module Generators
3
3
  class EmailGenerator < Rails::Generators::Base
4
- source_root File.expand_path('../templates', __FILE__)
5
- argument :resource_name, :type => :string, :default => 'identity'
6
- class_option :haml, type: :boolean, default: false, description: 'Generate haml templates'
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ argument :resource_name, type: :string, default: "identity"
6
+ class_option :haml, type: :boolean, default: false, description: "Generate haml templates"
7
7
 
8
8
  def copy_controller_files
9
- template 'identities_controller.rb', File.join('app/controllers', "#{resource_pluralize}_controller.rb")
10
- template 'sessions_controller.rb', 'app/controllers/sessions_controller.rb'
9
+ template "identities_controller.rb", File.join("app/controllers", "#{resource_pluralize}_controller.rb")
10
+ template "sessions_controller.rb", "app/controllers/sessions_controller.rb"
11
11
  end
12
12
 
13
13
  def copy_view_files
14
14
  if options[:haml]
15
- template 'haml/identity_new.html.haml', "app/views/#{resource_pluralize}/new.html.haml"
16
- template 'haml/session_new.html.haml', "app/views/sessions/new.html.haml"
15
+ template "haml/identity_new.html.haml", "app/views/#{resource_pluralize}/new.html.haml"
16
+ template "haml/session_new.html.haml", "app/views/sessions/new.html.haml"
17
17
  else
18
- template 'erb/identity_new.html.erb', "app/views/#{resource_pluralize}/new.html.erb"
19
- template 'erb/session_new.html.erb', "app/views/sessions/new.html.erb"
18
+ template "erb/identity_new.html.erb", "app/views/#{resource_pluralize}/new.html.erb"
19
+ template "erb/session_new.html.erb", "app/views/sessions/new.html.erb"
20
20
  end
21
21
  end
22
22
 
23
23
  def add_routes
24
- route "get 'sign_up' => '#{resource_pluralize}#new', as: :sign_up"
25
- route "get 'log_in' => 'sessions#new', as: :log_in"
26
- route "delete 'log_out' => 'sessions#destroy', as: :log_out"
24
+ route "get 'sign_up', to: '#{resource_pluralize}#new', as: :sign_up"
25
+ route "get 'log_in', to: 'sessions#new', as: :log_in"
26
+ route "delete 'log_out', to: 'sessions#destroy', as: :log_out"
27
27
 
28
28
  route "resource :#{resource_name}, only: [:create, :new]"
29
29
  route "resource :sessions, only: [:create, :new]"
@@ -31,51 +31,49 @@ module Authentication
31
31
 
32
32
  def generate_user
33
33
  if Dir["db/migrate/*create_#{resource_pluralize}.rb"].empty?
34
- template 'create_identities.rb', "db/migrate/#{migration_name}"
34
+ template "create_identities.rb", "db/migrate/#{migration_name}"
35
35
  end
36
- template 'identity.rb', "app/models/#{resource_name}.rb"
36
+ template "identity.rb", "app/models/#{resource_name}.rb"
37
37
  end
38
38
 
39
39
  def add_helper_methods
40
- insert_into_file 'app/controllers/application_controller.rb', after: /:exception/ do
41
- <<-EOS
40
+ insert_into_file "app/controllers/application_controller.rb", after: /::Base/ do
41
+ <<~EOS
42
42
 
43
+ helper_method :current_#{resource_name}, :#{resource_name}_signed_in?, :warden_message
43
44
 
44
- helper_method :current_#{resource_name}, :#{resource_name}_signed_in?, :warden_message
45
+ protected
46
+ def current_#{resource_name}
47
+ warden.user(scope: :#{resource_name})
48
+ end
45
49
 
46
- protected
47
- def current_#{resource_name}
48
- warden.user(scope: :#{resource_name})
49
- end
50
+ def #{resource_name}_signed_in?
51
+ warden.authenticate?(scope: :#{resource_name})
52
+ end
50
53
 
51
- def #{resource_name}_signed_in?
52
- warden.authenticate?(scope: :#{resource_name})
53
- end
54
+ def authenticate!
55
+ redirect_to root_path, notice: t('.not_logged') unless #{resource_name}_signed_in?
56
+ end
54
57
 
55
- def authenticate!
56
- redirect_to root_path, notice: t('.not_logged') unless #{resource_name}_signed_in?
57
- end
58
-
59
- def warden_message
60
- warden.message
61
- end
58
+ def warden_message
59
+ warden.message
60
+ end
62
61
 
63
- def warden
64
- request.env['warden']
65
- end
66
- EOS
62
+ def warden
63
+ request.env['warden']
64
+ end
65
+ EOS
67
66
  end
68
-
69
67
  end
70
68
 
71
- def add_gems
72
- gem 'warden', '~> 1.2.0'
73
- gem 'bcrypt-ruby'
74
- end
69
+ def add_gems
70
+ gem "warden", "~> 1.2.0"
71
+ gem "bcrypt"
72
+ end
75
73
 
76
- def add_translations
77
- insert_into_file "config/locales/en.yml", after: 'en:' do
78
- <<-EOS
74
+ def add_translations
75
+ insert_into_file "config/locales/en.yml", after: "en:" do
76
+ <<-EOS
79
77
 
80
78
  sessions:
81
79
  new:
@@ -90,33 +88,34 @@ protected
90
88
  create: 'Create #{resource_name}'
91
89
  create:
92
90
  sign_up: 'Welcome to your new account!'
93
- EOS
91
+ EOS
92
+ end
94
93
  end
95
- end
96
94
 
97
- def copy_warden_file
98
- template 'warden.rb', File.join('config', 'initializers', 'warden.rb')
99
- end
95
+ def copy_warden_file
96
+ template "warden.rb", File.join("config", "initializers", "warden.rb")
97
+ end
100
98
 
101
- def copy_warden_strategies
102
- template 'database_authentication.rb', File.join('lib', 'strategies', 'database_authentication.rb')
103
- end
99
+ def copy_warden_strategies
100
+ template "database_authentication.rb", File.join("lib", "strategies", "database_authentication.rb")
101
+ end
104
102
 
105
- def instructions
106
- message = "There are a few manual steps that you need to take care of\n\n"
107
- message << "1. Run bundle command to install new gems.\n"
108
- message << "2. Be sure that to have definition for root in your routes.\n"
109
- message << "3. Run rake db:migrate to add your #{resource_pluralize} table.\n"
110
- message << "4. Inspect warden initializer at config/initializers/warden.rb\n"
111
- message << " and update the failure_app if need it.\n"
112
- message << "5. Inspect generated files and learn how authentication was implemented.\n\n"
103
+ def instructions
104
+ message = "There are a few manual steps that you need to take care of\n\n"
105
+ message << "1. Run bundle command to install new gems.\n"
106
+ message << "2. Be sure that to have definition for root in your routes.\n"
107
+ message << "3. Run rake db:migrate to add your #{resource_pluralize} table.\n"
108
+ message << "4. Inspect warden initializer at config/initializers/warden.rb\n"
109
+ message << " and update the failure_app if need it.\n"
110
+ message << "5. Inspect generated files and learn how authentication was implemented.\n\n"
113
111
 
114
- puts message
115
- end
112
+ puts message
113
+ end
114
+
115
+ private
116
116
 
117
- private
118
117
  def migration_name
119
- date = (DateTime.now.strftime "%Y %m %d %H %M %S").gsub(' ', '')
118
+ date = (DateTime.now.strftime "%Y %m %d %H %M %S").delete(" ")
120
119
  "#{date}_create_#{resource_pluralize}.rb"
121
120
  end
122
121
 
@@ -1,8 +1,7 @@
1
- class Create<%= resource_pluralize.capitalize %> < ActiveRecord::Migration
1
+ class Create<%= resource_pluralize.capitalize %> < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :<%= resource_pluralize %> do |t|
4
4
  t.string :email
5
- t.string :password_hash
6
5
  t.string :password_digest
7
6
 
8
7
  t.timestamps
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strategies
2
4
  class DatabaseAuthentication < ::Warden::Strategies::Base
3
5
  def valid?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class <%= resource_pluralize.capitalize %>Controller < ApplicationController
2
4
 
3
5
  def new
@@ -15,9 +17,9 @@ class <%= resource_pluralize.capitalize %>Controller < ApplicationController
15
17
  end
16
18
  end
17
19
 
18
- private
20
+ private
21
+
19
22
  def <%= resource_name %>_params
20
23
  params.require(:<%= resource_name %>).permit :email, :password, :password_confirmation
21
24
  end
22
-
23
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class <%= resource_name.classify %> < ActiveRecord::Base
2
4
  has_secure_password validations: true
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SessionsController < ApplicationController
2
4
  def new
3
5
  @<%= resource_name %> = <%= resource_name.classify %>.new
@@ -1,4 +1,6 @@
1
- load File.expand_path("../../../lib/strategies/database_authentication.rb", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require_relative File.join(__FILE__, "..", "..", "..", "lib", "strategies", "database_authentication.rb")
2
4
  Rails.application.config.middleware.use Warden::Manager do |manager|
3
5
  manager.default_strategies :database_authentication
4
6
 
@@ -1,65 +1,65 @@
1
1
  module Authentication
2
2
  module Generators
3
3
  class OmniauthGenerator < Rails::Generators::Base
4
- source_root File.expand_path('../templates', __FILE__)
5
- argument :resource_name, :type => :string, :default => 'identity'
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ argument :resource_name, type: :string, default: "identity"
6
6
 
7
7
  def copy_controller_files
8
- template 'sessions_controller.rb', 'app/controllers/sessions_controller.rb'
8
+ template "sessions_controller.rb", "app/controllers/sessions_controller.rb"
9
9
  end
10
10
 
11
11
  def add_routes
12
- route "get 'auth/:provider/callback' => 'sessions#create', as: :log_in"
13
- route "delete '/sessions/destroy' => 'sessions#destroy', as: :log_out"
12
+ route "get 'auth/:provider/callback', to: 'sessions#create', as: :log_in"
13
+ route "delete '/sessions/destroy', to: 'sessions#destroy', as: :log_out"
14
14
  end
15
15
 
16
16
  def generate_user
17
17
  if Dir["db/migrate/*create_#{resource_pluralize}.rb"].empty?
18
- template 'create_identities.rb', "db/migrate/#{migration_name}"
18
+ template "create_identities.rb", "db/migrate/#{migration_name}"
19
19
  end
20
- template 'identity.rb', "app/models/#{resource_name}.rb"
20
+ template "identity.rb", "app/models/#{resource_name}.rb"
21
21
  end
22
22
 
23
23
  def add_helper_methods
24
- insert_into_file 'app/controllers/application_controller.rb', after: /:exception/ do
25
- <<-EOS
24
+ insert_into_file "app/controllers/application_controller.rb", after: /:exception/ do
25
+ <<~EOS
26
26
 
27
27
 
28
- helper_method :current_#{resource_name}, :#{resource_name}_signed_in?, :warden_message
28
+ helper_method :current_#{resource_name}, :#{resource_name}_signed_in?, :warden_message
29
29
 
30
- protected
31
- def current_#{resource_name}
32
- warden.user(scope: :#{resource_name})
33
- end
30
+ protected
34
31
 
35
- def #{resource_name}_signed_in?
36
- warden.authenticate?(scope: :#{resource_name})
37
- end
32
+ def current_#{resource_name}
33
+ warden.user(scope: :#{resource_name})
34
+ end
38
35
 
39
- def authenticate!
40
- redirect_to root_path, notice: t('.not_logged') unless #{resource_name}_signed_in?
41
- end
36
+ def #{resource_name}_signed_in?
37
+ warden.authenticate?(scope: :#{resource_name})
38
+ end
42
39
 
43
- def warden_message
44
- warden.message
45
- end
40
+ def authenticate!
41
+ redirect_to root_path, notice: t('.not_logged') unless #{resource_name}_signed_in?
42
+ end
46
43
 
47
- def warden
48
- request.env['warden']
49
- end
50
- EOS
51
- end
44
+ def warden_message
45
+ warden.message
46
+ end
52
47
 
48
+ def warden
49
+ request.env['warden']
50
+ end
51
+ EOS
52
+ end
53
53
  end
54
54
 
55
- def add_gems
56
- gem 'warden', '~> 1.2.0'
57
- gem 'omniauth'
58
- end
55
+ def add_gems
56
+ gem "warden", "~> 1.2.0"
57
+ gem "omniauth"
58
+ end
59
59
 
60
- def add_translations
61
- insert_into_file "config/locales/en.yml", after: 'en:' do
62
- <<-EOS
60
+ def add_translations
61
+ insert_into_file "config/locales/en.yml", after: "en:" do
62
+ <<-EOS
63
63
 
64
64
  sessions:
65
65
  new:
@@ -69,47 +69,48 @@ protected
69
69
  logged_in: 'Welcome back!'
70
70
  destroy:
71
71
  logged_out: 'See you later!'
72
- EOS
72
+ EOS
73
+ end
73
74
  end
74
- end
75
75
 
76
- def copy_warden_file
77
- template 'warden.rb', File.join('config', 'initializers', 'warden.rb')
78
- end
76
+ def copy_warden_file
77
+ template "warden.rb", File.join("config", "initializers", "warden.rb")
78
+ end
79
79
 
80
- def copy_configuration
81
- template 'authentication_domain.rb', File.join('config', 'initializers', 'authentication_domain.rb')
82
- end
80
+ def copy_configuration
81
+ template "authentication_domain.rb", File.join("config", "initializers", "authentication_domain.rb")
82
+ end
83
83
 
84
- def copy_omniauth_configuration
85
- template 'omniauth.rb', File.join('config', 'initializers', 'omniauth.rb')
86
- end
84
+ def copy_omniauth_configuration
85
+ template "omniauth.rb", File.join("config", "initializers", "omniauth.rb")
86
+ end
87
87
 
88
- def copy_warden_strategies
89
- template 'oauth_authentication.rb', File.join('lib', 'strategies', 'oauth_authentication.rb')
90
- end
88
+ def copy_warden_strategies
89
+ template "oauth_authentication.rb", File.join("lib", "strategies", "oauth_authentication.rb")
90
+ end
91
91
 
92
- def instructions
93
- message = "There are a few manual steps that you need to take care of\n\n"
94
- message << "1. Add an omniauth provider gem like twitter, facebook, etc..\n"
95
- message << "2. Modify config/initializers/omniauth.rb and setup your provider\n"
96
- message << " and your provider credentials.\n"
97
- message << "3. Run bundle command to install new gems.\n"
98
- message << "4. If you want to restrict access to a specific email domain.\n"
99
- message << " modify config/initializers/authentication_domain.rb and add \n"
100
- message << " your allowed domain.\n"
101
- message << "5. Inspect warden initializer at config/initializers/warden.rb\n"
102
- message << " and update the failure_app.\n"
103
- message << "6. Be sure that to have definition for root in your routes.\n"
104
- message << "7. Run rake db:migrate to add your #{resource_pluralize} table.\n"
105
- message << "8. Inspect generated files and learn how authentication was implemented.\n\n"
106
-
107
- puts message
108
- end
92
+ def instructions
93
+ message = "There are a few manual steps that you need to take care of\n\n"
94
+ message << "1. Add an omniauth provider gem like twitter, facebook, etc..\n"
95
+ message << "2. Modify config/initializers/omniauth.rb and setup your provider\n"
96
+ message << " and your provider credentials.\n"
97
+ message << "3. Run bundle command to install new gems.\n"
98
+ message << "4. If you want to restrict access to a specific email domain.\n"
99
+ message << " modify config/initializers/authentication_domain.rb and add \n"
100
+ message << " your allowed domain.\n"
101
+ message << "5. Inspect warden initializer at config/initializers/warden.rb\n"
102
+ message << " and update the failure_app.\n"
103
+ message << "6. Be sure that to have definition for root in your routes.\n"
104
+ message << "7. Run rake db:migrate to add your #{resource_pluralize} table.\n"
105
+ message << "8. Inspect generated files and learn how authentication was implemented.\n\n"
106
+
107
+ puts message
108
+ end
109
+
110
+ private
109
111
 
110
- private
111
112
  def migration_name
112
- date = (DateTime.now.strftime "%Y %m %d %H %M %S").gsub(' ', '')
113
+ date = (DateTime.now.strftime "%Y %m %d %H %M %S").delete(" ")
113
114
  "#{date}_create_#{resource_pluralize}.rb"
114
115
  end
115
116