Class: TradoPaypalModule::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/trado_paypal_module/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#assign_model_concernsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/trado_paypal_module/install_generator.rb', line 25

def assign_model_concerns
	order_content = <<-CONTENT

	has_order_paypal
	CONTENT
	transaction_content = <<-CONTENT

	has_transaction_paypal
	CONTENT

	inject_into_file "app/models/order.rb", order_content, after: "class Order < ActiveRecord::Base"
	inject_into_file "app/models/transaction.rb", transaction_content, after: "class Transaction < ActiveRecord::Base"
end

#copy_controllerObject



13
14
15
# File 'lib/generators/trado_paypal_module/install_generator.rb', line 13

def copy_controller
	template "controller.rb", "app/controllers/carts/paypal_controller.rb"
end

#copy_migrationObject



6
7
8
9
10
11
# File 'lib/generators/trado_paypal_module/install_generator.rb', line 6

def copy_migration
	unless paypal_migration_already_exists?
		timestamp_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
		copy_file "migration.rb", "db/migrate/#{timestamp_number}_add_paypal_attributes.rb"
	end
end

#setup_env_configsObject



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
# File 'lib/generators/trado_paypal_module/install_generator.rb', line 39

def setup_env_configs
	development_content = <<-CONTENT

	# PayPal settings
	config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :test
  paypal_options = {
   	login: Rails.application.secrets.paypal_login,
   	password: Rails.application.secrets.paypal_password,
   	signature: Rails.application.secrets.paypal_signature
  }
  ::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
	end
	CONTENT

	test_content = <<-CONTENT

	# PayPal settings
	config.after_initialize do
		ActiveMerchant::Billing::Base.mode = :test
  ::EXPRESS_GATEWAY = ActiveMerchant::Billing::BogusGateway.new
	end
	CONTENT

	production_content = <<-CONTENT

	# PayPal settings
	config.after_initialize do
  paypal_options = {
  	login: Rails.application.secrets.paypal_login,
  	password: Rails.application.secrets.paypal_password,
  	signature: Rails.application.secrets.paypal_signature
  }
  ::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
	end
	CONTENT
	inject_into_file "config/environments/development.rb", development_content, after: "Trado::Application.configure do"
	inject_into_file "config/environments/test.rb", test_content, after: "Trado::Application.configure do"
	inject_into_file "config/environments/production.rb", production_content, after: "Trado::Application.configure do"
end

#setup_routesObject



17
18
19
20
21
22
23
# File 'lib/generators/trado_paypal_module/install_generator.rb', line 17

def setup_routes
	route_content = <<-CONTENT

	mount TradoPaypalModule::Engine => '/paypal'
	CONTENT
	inject_into_file "config/routes.rb", route_content, after: "Trado::Application.routes.draw do"
end