14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/generators/spree/authentication/devise/devise_generator.rb', line 14
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
user_class_file = Rails.root.join('app', 'models', "#{Spree.user_class.name.underscore}.rb")
if File.exist?(user_class_file)
inject_into_file user_class_file, after: "class #{Spree.user_class.name} < ApplicationRecord\n" do
" # Spree modules\n include Spree::UserAddress\n include Spree::UserMethods\n include Spree::UserPaymentSource\n RUBY\n end\n gsub_file user_class_file, \"< ApplicationRecord\", \"< Spree.base_class\"\n\n say \"Successfully added Spree user modules into \#{user_class_file}\"\n else\n say \"Could not locate user model file at \#{user_class_file}. Please add these lines manually:\", :red\n say <<~RUBY\n # Spree modules\n include Spree::UserAddress\n include Spree::UserMethods\n include Spree::UserPaymentSource\n RUBY\n\n say \"Please replace < ApplicationRecord with < Spree.base_class in \#{user_class_file}\"\n end\n\n if Spree.admin_user_class != Spree.user_class\n admin_user_class_file = Rails.root.join('app', 'models', \"\#{Spree.admin_user_class.name.underscore}.rb\")\n\n if File.exist?(admin_user_class_file)\n inject_into_file admin_user_class_file, after: \"class \#{Spree.admin_user_class.name} < ApplicationRecord\\n\" do\n <<-RUBY\n # Spree modules\n include Spree::UserMethods\n RUBY\n end\n gsub_file admin_user_class_file, \"< ApplicationRecord\", \"< Spree.base_class\"\n\n say \"Successfully added Spree admin user modules into \#{admin_user_class_file}\"\n else\n say \"Could not locate admin user model file at \#{admin_user_class_file}. Please add these lines manually:\", :red\n say <<~RUBY\n # Spree modules\n include Spree::UserMethods\n RUBY\n\n say \"Please replace < ApplicationRecord with < Spree.base_class in \#{admin_user_class_file}\"\n end\n end\n\n append_file 'config/initializers/spree.rb' do\n %Q{\n if defined?(Devise) && Devise.respond_to?(:parent_controller)\n Devise.parent_controller = \"Spree::BaseController\"\n end\\n}\n end\nend\n"
|