-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix custom authentication generators and update docs (#12044)
- Loading branch information
1 parent
8ae3d7f
commit 1ccfa8f
Showing
6 changed files
with
89 additions
and
72 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
core/lib/generators/spree/custom_authentication/custom_authentication_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Spree | ||
class CustomAuthenticationGenerator < Rails::Generators::Base | ||
desc 'Set up a Spree installation with a custom authentication helpers' | ||
|
||
def self.source_paths | ||
paths = superclass.source_paths | ||
paths << File.expand_path('templates', __dir__) | ||
paths.flatten | ||
end | ||
|
||
def generate | ||
template 'authentication_helpers.rb.tt', 'lib/spree/authentication_helpers.rb' | ||
|
||
file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file | ||
send(file_action, 'config/initializers/spree.rb') do | ||
%Q{ | ||
Rails.application.config.to_prepare do | ||
require_dependency 'spree/authentication_helpers' | ||
end\n} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
core/lib/generators/spree/custom_user/templates/current_user_helpers.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Spree | ||
module CurrentUserHelpers | ||
def self.included(receiver) | ||
receiver.send :helper_method, :spree_current_user | ||
end | ||
|
||
def spree_current_user | ||
current_user | ||
end | ||
end | ||
end | ||
|
||
|
||
ApplicationController.include Spree::CurrentUserHelpers if defined?(ApplicationController) | ||
Spree::Api::BaseController.include Spree::CurrentUserHelpers if defined?(Spree::Api::BaseController) |
4 changes: 2 additions & 2 deletions
4
core/lib/generators/spree/custom_user/templates/migration.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
class AddSpreeFieldsToCustomUserTable < ActiveRecord::Migration[4.2] | ||
def up | ||
add_column <%= table_name.inspect %>, :spree_api_key, :string, limit: 48 | ||
add_column <%= table_name.inspect %>, :ship_address_id, :integer | ||
add_column <%= table_name.inspect %>, :bill_address_id, :integer | ||
add_column <%= table_name.inspect %>, :ship_address_id, :bigint | ||
add_column <%= table_name.inspect %>, :bill_address_id, :bigint | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters