Class: WechatPayment::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_concern_to_goodsObject



24
25
26
27
28
29
30
31
32
# File 'lib/generators/wechat_payment/install/install_generator.rb', line 24

def add_concern_to_goods
  goods_model_head_one = "class #{goods_model_name} < ApplicationRecord"
  inject_into_file goods_model_file, after: goods_model_head_one do <<-GOODS_CONCERN

include WechatPayment::Concern::Goods
#{def_custom_user_model}
  GOODS_CONCERN
  end
end

#add_concern_to_user_goodsObject



43
44
45
46
47
48
49
50
# File 'lib/generators/wechat_payment/install/install_generator.rb', line 43

def add_concern_to_user_goods
  user_goods_model_head_one = "class #{user_goods_model_name} < ApplicationRecord"
  inject_into_file user_goods_model_file, after: user_goods_model_head_one do <<-'USER_GOOD_CONCERN'

include WechatPayment::Concern::UserGoods
  USER_GOOD_CONCERN
  end
end

#add_concern_to_usersObject



34
35
36
37
38
39
40
41
# File 'lib/generators/wechat_payment/install/install_generator.rb', line 34

def add_concern_to_users
  user_model_head_one = "class #{user_model_name} < ApplicationRecord"
  inject_into_file user_model_file, after: user_model_head_one do <<-'USERS_CONCERN'

include WechatPayment::Concern::User
  USERS_CONCERN
  end
end

#copy_migrationObject

安装迁移文件



20
21
22
# File 'lib/generators/wechat_payment/install/install_generator.rb', line 20

def copy_migration
  rake "wechat_payment:install:migrations"
end

#gen_initializer_fileObject

生成 initializer 文件



10
11
12
# File 'lib/generators/wechat_payment/install/install_generator.rb', line 10

def gen_initializer_file
  copy_file "initializer.rb", "config/initializers/wechat_payment.rb"
end

#mount_payment_engineObject

挂载 engine 到路由上



15
16
17
# File 'lib/generators/wechat_payment/install/install_generator.rb', line 15

def mount_payment_engine
  route %Q(mount WechatPayment::Engine => "/wechat_payment")
end