Class: RubyNative::Generators::IapGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Must increment within a single run, or the second migration below collides with the first on a bare Time.now timestamp.



13
14
15
# File 'lib/generators/ruby_native/iap_generator.rb', line 13

def self.next_migration_number(dirname)
  ActiveRecord::Migration.next_migration_number(current_migration_number(dirname) + 1)
end

Instance Method Details

#copy_migrationsObject

Re-running this generator on an app that already has the first migration reports it identical and creates only what is missing, so it doubles as the upgrade path.

That rests on create_ruby_native_purchase_intents.rb never changing. Rails compares the template against the copy the app already has, and only calls it identical when they match byte for byte; edit one character and it reports a conflict instead, which raises and aborts the run before the migrations added after it are copied. So an app upgrading would get none of them. Add a new template alongside it rather than editing it -- iap_generator_test.rb fails if that file is touched.



28
29
30
31
32
33
# File 'lib/generators/ruby_native/iap_generator.rb', line 28

def copy_migrations
  migration_template "create_ruby_native_purchase_intents.rb",
    "db/migrate/create_ruby_native_purchase_intents.rb"
  migration_template "add_restored_transaction_id_to_ruby_native_purchase_intents.rb",
    "db/migrate/add_restored_transaction_id_to_ruby_native_purchase_intents.rb"
end


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/ruby_native/iap_generator.rb', line 35

def print_next_steps
  say ""
  say "Ruby Native IAP installed!", :green
  say ""
  say "  1. Run migrations: bin/rails db:migrate"
  say "  2. Add your callback in config/initializers/ruby_native.rb:"
  say ""
  say '     RubyNative.on_subscription_change do |event|'
  say '       user = User.find_by(id: event.owner_token)'
  say '       user&.update!(subscribed: event.active?)'
  say '     end'
  say ""
  say "  3. Set your App Store Server Notification URL to:"
  say "     https://yourapp.com/native/webhooks/apple"
  say ""
end