Class: Webpay::ScaffoldGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/webpay/scaffold.rb

Constant Summary collapse

@@template_path =
source_root File.expand_path( "../scaffold/templates", __FILE__ )

Instance Method Summary collapse

Instance Method Details

#generate_scaffoldObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/webpay/scaffold.rb', line 10

def generate_scaffold
  ## config/initializers
  copy_file( "#{@@template_path}/initializers/web_pay.rb", "config/initializers/web_pay.rb" )

  ## db/migrate
  copy_file( "#{@@template_path}/migrate/create_payments.rb", "db/migrate/20010101000000_create_payments.rb" )
  copy_file( "#{@@template_path}/migrate/create_cards.rb", "db/migrate/20010102000000_create_cards.rb" )

  ## models
  copy_file( "#{@@template_path}/models/card.rb", "app/models/card.rb" )
  copy_file( "#{@@template_path}/models/payment.rb", "app/models/payment.rb" )
  copy_file( "#{@@template_path}/models/web_pay_connect.rb", "app/models/web_pay_connect.rb" )

  ## settings
  if File.exist?("config/settings.yml")
    content = "\n# WebPay API Key\n"
    content += "web_pay_api_key: 'test_secret_5ete0yfRC3g67ndfMm0kC1S9'\n"
    content += "web_pay_currency: 'jpy'\n"
    append_file( "config/settings.yml", content.force_encoding('ASCII-8BIT') )
  else
    copy_file( "#{@@template_path}/config/settings.yml", "config/settings.yml" )
  end
end