Class: Clickwrap::Generators::LinkGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Clickwrap::Generators::LinkGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/clickwrap/link_generator.rb
Overview
Links a domain table to the clickwrap evidence that authorized its rows:
bin/rails generate clickwrap:link payouts_withdrawals
writes the migration for a clickwrap_event_id column (ULID string,
indexed, nullable, no foreign key — see the migration's own comment for
why each of those is deliberate). Pair it with has_clickwrap_evidence
on the model and assign pending_receipt.event_id inside
capture_clickwrap_and!.
Instance Method Summary collapse
Instance Method Details
#create_link_migration ⇒ Object
25 26 27 28 |
# File 'lib/generators/clickwrap/link_generator.rb', line 25 def create_link_migration migration_template "link_clickwrap_event_migration.rb.erb", "db/migrate/add_clickwrap_event_to_#{table_name}.rb" end |
#explain ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/clickwrap/link_generator.rb', line 30 def explain say "" say "Next, on the model:" say "" say " has_clickwrap_evidence policy: :your_policy," say " statement: :your_statement," say " actor: :user," say " subject: :self" say "" say "and assign the event inside the capture that authorizes the row:" say "" say " capture_clickwrap_and!(:your_policy) do |pending_receipt|" say " record.clickwrap_event_id = pending_receipt.event_id" say " record.save!" say " record # returned to the protected-outcome recorder" say " end" say "" end |