Class: Clickwrap::Generators::DocumentGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/clickwrap/document_generator.rb

Overview

rails generate clickwrap:document terms — declares one document and creates the file its bytes will come from, with the file's own front matter naming its version.

Declaring is not publishing. This generator adds a declaration and a placeholder file; bin/rails clickwrap:publish is what reads the bytes, digests them, and freezes the snapshot that receipts point at from then on (deploys do this automatically after db:prepare).

Changing a document later is NOT another run of this generator: the file that holds the words also names its version, so a new version is one edit in one file — change the text, bump last_updated: (or add clickwrap_version: for a same-day correction), publish. The declaration never changes, published bytes are never edited in place, and every receipt goes on pointing at the exact version its accepted server offer bound.

Instance Method Summary collapse

Instance Method Details

#create_content_fileObject



35
36
37
38
39
40
41
42
# File 'lib/generators/clickwrap/document_generator.rb', line 35

def create_content_file
  if host_file?(content_path)
    say_status :skip, "#{content_path} (you already have a file there)", :yellow
    return
  end

  create_file content_path, placeholder_content
end

#declare_documentObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/generators/clickwrap/document_generator.rb', line 44

def declare_document
  create_policy_file_if_missing

  if declaration_present?
    say_status :skip, "#{policy_file} (:#{document_key} is already declared — a new " \
                      "version is a front-matter bump in #{content_path}, not a new " \
                      "declaration)", :yellow
    return
  end

  append_to_file policy_file, declaration
end

#display_next_stepsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/generators/clickwrap/document_generator.rb', line 57

def display_next_steps
  say "\n☑️  Document :#{document_key} declared.", :green
  say "\nTo finish:"
  say "  1. Put the real text in #{content_path}, keeping the front matter at the top."
  say "     Clickwrap never writes legal text — the words are yours."
  say "  2. Run 'bin/rails clickwrap:publish' to freeze an immutable snapshot."
  say "     Deploys do this for you — publishing rides `db:prepare`."
  say "  3. Reference it from a policy in #{policy_file}."
  say "\nThe file names its own version: its `last_updated:` front matter is the label,"
  say "so changing the text later is one edit in one file — new words, bumped label,"
  say "publish. Reusing a label for different bytes is refused rather than accepted,"
  say "and old receipts go on pointing at the bytes their accepted server offers bound.\n"
end