Class: ShopifyApp::Generators::ShopModelGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/shopify_app/shop_model/shop_model_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dir) ⇒ Object

for generating a timestamp when using ‘create_migration`



83
84
85
# File 'lib/generators/shopify_app/shop_model/shop_model_generator.rb', line 83

def next_migration_number(dir)
  ActiveRecord::Generators::Base.next_migration_number(dir)
end

Instance Method Details

#create_shop_fixturesObject



65
66
67
# File 'lib/generators/shopify_app/shop_model/shop_model_generator.rb', line 65

def create_shop_fixtures
  copy_file("shops.yml", "test/fixtures/shops.yml")
end

#create_shop_migrationObject



18
19
20
# File 'lib/generators/shopify_app/shop_model/shop_model_generator.rb', line 18

def create_shop_migration
  migration_template("db/migrate/create_shops.erb", "db/migrate/create_shops.rb")
end

#create_shop_modelObject



14
15
16
# File 'lib/generators/shopify_app/shop_model/shop_model_generator.rb', line 14

def create_shop_model
  copy_file("shop.rb", "app/models/shop.rb")
end

#create_shop_with_access_scopes_migrationObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/shopify_app/shop_model/shop_model_generator.rb', line 22

def create_shop_with_access_scopes_migration
  scopes_column_prompt = <<~PROMPT
    It is highly recommended that apps record the access scopes granted by \
    merchants during app installation. See app/models/shop.rb to modify how \
    access scopes are stored and retrieved.

    [WARNING] You will need to update the access_scopes accessors in the Shop model \
    to allow shopify_app to store and retrieve scopes when going through OAuth.

    The following migration will add an `access_scopes` column to the Shop model. \
    Do you want to include this migration? [y/n]
  PROMPT

  if new_shopify_cli_app? || Rails.env.test? || yes?(scopes_column_prompt)
    migration_template(
      "db/migrate/add_shop_access_scopes_column.erb",
      "db/migrate/add_shop_access_scopes_column.rb",
    )
  end
end

#create_shop_with_token_refresh_migrationObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/generators/shopify_app/shop_model/shop_model_generator.rb', line 43

def create_shop_with_token_refresh_migration
  token_refresh_prompt = <<~PROMPT
    To support expiring offline access token with refresh, your Shop model needs to store \
    token expiration dates and refresh tokens.

    The following migration will add `expires_at`, `refresh_token`, and \
    `refresh_token_expires_at` columns to the Shop model. \
    Do you want to include this migration? [y/n]
  PROMPT

  if new_shopify_cli_app? || Rails.env.test? || yes?(token_refresh_prompt)
    migration_template(
      "db/migrate/add_shop_access_token_expiry_columns.erb",
      "db/migrate/add_shop_access_token_expiry_columns.rb",
    )
  end
end

#update_shopify_app_initializerObject



61
62
63
# File 'lib/generators/shopify_app/shop_model/shop_model_generator.rb', line 61

def update_shopify_app_initializer
  gsub_file("config/initializers/shopify_app.rb", "ShopifyApp::InMemoryShopSessionStore", "Shop")
end