Class: CurrentScope::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/current_scope/install/install_generator.rb

Constant Summary collapse

GUIDE_PATH =

An ABSOLUTE URL, not a repo-relative path. This prints in the HOST's terminal, in the HOST's app directory: "docs/guides/..." would resolve against their app, where it does not exist — and the gemspec ships only app,config,db,lib + README, so it is not in the installed gem either. Shipping docs/ wouldn't fix it (nobody reads docs out of a gem's install dir); a URL is the only form that resolves from where the reader is standing, and terminals make it clickable. (#64 review, qodo)

Points at blob/main deliberately: the guide does not exist at the last release tag (it landed after v0.2.0), so a version-pinned URL would 404 today. Revisit pinning to "blob/v#VERSION" at the next release, when a tag containing the guide exists. (#71 review, qodo)

"docs/guides/adopting-in-an-existing-app.md".freeze
GUIDE_URL =
"https://github.com/davidteren/current_scope/blob/main/#{GUIDE_PATH}".freeze

Instance Method Summary collapse

Instance Method Details

#copy_initializerObject



6
7
8
# File 'lib/generators/current_scope/install/install_generator.rb', line 6

def copy_initializer
  template "initializer.rb", "config/initializers/current_scope.rb"
end

#mount_engineObject



10
11
12
# File 'lib/generators/current_scope/install/install_generator.rb', line 10

def mount_engine
  route 'mount CurrentScope::Engine => "/current_scope"'
end

#show_next_stepsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/current_scope/install/install_generator.rb', line 14

def show_next_steps
  # Keep this list in lockstep with README Installation and
  # docs/site/quickstart.md (#25). Three paths must not disagree.
  say <<~NEXT

    CurrentScope installed. Next steps (canonical quickstart):

      1. bin/rails current_scope:install:migrations && bin/rails db:migrate
      2. Include the concerns in ApplicationController (Context first):
           include CurrentScope::Context
           include CurrentScope::Guard
      3. Skip the gate on sign-in / public endpoints (or nobody can log in):
           class SessionsController < ApplicationController
             # Declared form: the role grid shows WHY the gate is off.
             # A bare skip_before_action :current_scope_check! still works,
             # but the grid marks it as an unexplained "gate not run".
             current_scope_skip_gate!(reason: "sign-in must run without a grant")
             # If you use impersonation, also skip the mutation guard on
             # sign-in/out or POSTs while acting-as stay blocked:
             skip_before_action :current_scope_mutation_guard!
           end
           Skipping leaves that controller ungated by CurrentScope —
           use your own auth there (security checklist:
           https://davidteren.github.io/current_scope/).
      4. Bootstrap the first admin (Member starts with zero permissions):
           bin/rails current_scope:grant SUBJECT_ID=YOUR_USER_ID
           # or: CurrentScope.grant!(User.first)  # upserts Owner; not RoleAssignment.create!
      5. Manage roles at /current_scope (full-access subjects only).
      6. A denial is 403 with X-Current-Scope-Reason (no_grant, sod_veto, …).

      Full guide: https://davidteren.github.io/current_scope/quickstart.html

  NEXT

  say_retrofit_warning if existing_app?
end