Class: ShopQiAppWebhookGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



32
33
34
# File 'lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb', line 32

def self.next_migration_number(dirname)
  ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Instance Method Details

#add_routesObject



14
15
16
# File 'lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb', line 14

def add_routes
  route "use_shopqi_webhook"
end

#copy_filesObject



8
9
10
11
12
# File 'lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb', line 8

def copy_files
  directory 'app'
  directory 'script'
  chmod "script/delayed_job", 0755
end

#install_migrationObject



23
24
25
26
# File 'lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb', line 23

def install_migration
  migration_template 'db/migrate/create_delayed_jobs.rb', 'db/migrate/create_delayed_jobs.rb'
  migration_template 'db/migrate/create_orders.rb', 'db/migrate/create_orders.rb'
end

#showObject



28
29
30
# File 'lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb', line 28

def show
  readme "README"
end

#update_filesObject



18
19
20
21
# File 'lib/generators/shopqi_app_webhook/shopqi_app_webhook_generator.rb', line 18

def update_files
  prepend_to_file "app/models/shop.rb", "require \"\#{ShopQiAppWebhook::Engine.models_dir}/shop\"\n"
  insert_into_file "app/models/shop.rb", "\s\shas_many :orders\n", after: /class Shop( < ActiveRecord::Base){0,1}\n/
end