Class: Clickwrap::Generators::PolicyGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Clickwrap::Generators::PolicyGenerator
- Defined in:
- lib/generators/clickwrap/policy_generator.rb
Overview
rails generate clickwrap:policy contractor_declaration declare --statement-text="I declare ..." â one compiling policy and its test.
The verb and exact first-person statement are required because choosing or inventing either would silently make product/legal meaning on the host's behalf. Once they are supplied, the generated file compiles immediately; it never writes an empty policy or an executable TODO placeholder.
The test comes with it for the same reason tests come with a model: a policy is executable meaning, and "does this still say what we think it says" is a question worth asking on every commit.
Constant Summary collapse
- VERBS =
%w[agree_to acknowledge consent_to declare attest authorize].freeze
Instance Method Summary collapse
- #create_policy_file ⇒ Object
- #create_policy_test ⇒ Object
- #display_next_steps ⇒ Object
- #validate_arguments! ⇒ Object
Instance Method Details
#create_policy_file ⇒ Object
51 52 53 |
# File 'lib/generators/clickwrap/policy_generator.rb', line 51 def create_policy_file template "policy.rb.erb", "config/clickwrap/#{policy_key}.rb" end |
#create_policy_test ⇒ Object
55 56 57 |
# File 'lib/generators/clickwrap/policy_generator.rb', line 55 def create_policy_test template "policy_test.rb.erb", "test/clickwrap/#{policy_key}_policy_test.rb" end |
#display_next_steps ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/generators/clickwrap/policy_generator.rb', line 59 def display_next_steps say "\nâď¸ Compiling policy created.", :green say "\nTo finish it:" say " 1. Review the verb and exact statement in config/clickwrap/#{policy_key}.rb." say " 2. If it references a document, declare and publish that document." say " 3. Replace the generated test skips with your real actor and submission flow." say "\nThe policy compiles at boot: a missing document, a duplicate statement key, a" say "consent without a withdrawal path, or an indefinite one-time authorization is a" say "startup failure with a sentence explaining it.\n" end |
#validate_arguments! ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/clickwrap/policy_generator.rb', line 38 def validate_arguments! return if VERBS.include?(policy_verb) && (! || withdrawal_path.present?) unless VERBS.include?(policy_verb) raise Thor::Error, "#{verb.inspect} is not a Clickwrap policy verb. Choose one of: #{VERBS.join(", ")}." end raise Thor::Error, "A consent_to policy needs --withdrawal-path=/your/settings/page so the " \ "person has a concrete way to withdraw it." end |