settings_hub 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +10 -0
  5. data/app/assets/stylesheets/settings_hub/application.css +15 -0
  6. data/app/controllers/settings_hub/api/sections_controller.rb +41 -0
  7. data/app/controllers/settings_hub/application_controller.rb +23 -0
  8. data/app/controllers/settings_hub/sections_controller.rb +78 -0
  9. data/app/controllers/settings_hub/settings_controller.rb +7 -0
  10. data/app/helpers/settings_hub/app_routes_helper.rb +12 -0
  11. data/app/helpers/settings_hub/application_helper.rb +4 -0
  12. data/app/jobs/settings_hub/application_job.rb +4 -0
  13. data/app/mailers/settings_hub/application_mailer.rb +6 -0
  14. data/app/models/settings_hub/application_record.rb +5 -0
  15. data/app/models/settings_hub/change_name.rb +15 -0
  16. data/app/views/settings_hub/sections/_profile.html.erb +6 -0
  17. data/app/views/settings_hub/settings/show.html.erb +26 -0
  18. data/config/routes.rb +11 -0
  19. data/lib/generators/settings_hub/section/section_generator.rb +43 -0
  20. data/lib/generators/settings_hub/section/templates/action.rb.tt +11 -0
  21. data/lib/generators/settings_hub/section/templates/action_test.rb.tt +9 -0
  22. data/lib/generators/settings_hub/section/templates/partial.html.erb.tt +6 -0
  23. data/lib/settings_hub/bad_registration.rb +4 -0
  24. data/lib/settings_hub/engine.rb +9 -0
  25. data/lib/settings_hub/reference/guide.md +216 -0
  26. data/lib/settings_hub/registry.rb +58 -0
  27. data/lib/settings_hub/result.rb +22 -0
  28. data/lib/settings_hub/section.rb +30 -0
  29. data/lib/settings_hub/settings_account.rb +10 -0
  30. data/lib/settings_hub/version.rb +3 -0
  31. data/lib/settings_hub.rb +36 -0
  32. data/lib/tasks/settings_hub_tasks.rake +4 -0
  33. data/the_local/agents/settings_hub-develop.md +281 -0
  34. data/the_local/agents/settings_hub-info.md +92 -0
  35. data/the_local/agents/settings_hub-install.md +145 -0
  36. data/the_local/interface.yml +57 -0
  37. metadata +110 -0
@@ -0,0 +1,145 @@
1
+ ---
2
+ name: settings_hub-install
3
+ description: Use to hook settings_hub into a project — adding the gem, mounting the settings engine, supplying the methods it asks the host controller for, and declaring which capabilities the app recognises.
4
+ tools: Bash, Read, Edit
5
+ scope: settings — one settings page whose sections are registered by the app and by other gems
6
+ ---
7
+
8
+ This local follows the steps below exactly and invents none. Where a step names a
9
+ decision, put it to the developer and wait for an answer rather than picking one.
10
+
11
+ ## What settings_hub is
12
+
13
+ SettingsHub is a mountable Rails engine serving one settings page whose sections the
14
+ app and other gems register; hook it in when a product needs that page instead of
15
+ building one.
16
+
17
+ ## Interface
18
+
19
+ - `gem "settings_hub"` — puts the engine, the settings page and the shipped Profile
20
+ section into the app.
21
+ - `mount SettingsHub::Engine => "/settings"` — serves the settings page and every
22
+ section's address under the path you mount it at.
23
+ - `current_person` — the host's answer for who is signed in, and the only one of
24
+ these methods settings_hub always needs.
25
+ - `settings_account` — the host's answer for which account settings act on, asked
26
+ for before `current_account` and falling back to it.
27
+ - `can?(capability)` — the host's answer for whether the signed-in person holds a
28
+ capability, needed once any section names one.
29
+ - `after_settings_change(section:, person:)` — the host's hook, run after a
30
+ change submitted from the settings page succeeds and skipped when one is
31
+ refused.
32
+ - `SettingsHub.capabilities` — the list of capabilities the app recognises, which
33
+ settings_hub checks a registration's capability against once it is set.
34
+
35
+ ## How to use it
36
+
37
+ 1. **Add the gem.** Put `gem "settings_hub"` in the app's `Gemfile` and run `bundle
38
+ install`. There is no migration to run, because settings_hub owns no database table.
39
+
40
+ 2. **Check keystone_ui is hooked up.** SettingsHub draws every page with keystone_ui
41
+ and brings it in as a dependency, so a host that has not set keystone_ui up
42
+ gets a settings page that does not match the rest of the app. Hooking that up
43
+ is keystone_ui's own local, not this one.
44
+
45
+ 3. **Mount the engine.** Add one line to `config/routes.rb`:
46
+
47
+ ```ruby
48
+ mount SettingsHub::Engine => "/settings"
49
+ ```
50
+
51
+ Ask the developer which path to mount it at if the app already serves
52
+ something at `/settings`. Every settings address sits under whatever you
53
+ choose, the ones a caller outside the browser uses included, and nothing else
54
+ in the app changes when it moves.
55
+
56
+ 4. **Add `current_person` to `app/controllers/application_controller.rb`.** It
57
+ returns the signed-in person record and may be private:
58
+
59
+ ```ruby
60
+ private
61
+
62
+ def current_person
63
+ Current.person
64
+ end
65
+ ```
66
+
67
+ SettingsHub's controllers inherit from the app's `ApplicationController`, so the
68
+ app's own `before_action` filters — authentication included — already run on
69
+ the settings page. Do not add a second authentication check.
70
+
71
+ 5. **Decide which account settings act on.** Define `settings_account` on
72
+ `ApplicationController` when the settings page acts on something other than
73
+ the account the app calls `current_account`. SettingsHub asks for
74
+ `settings_account` first, uses `current_account` when it is not defined, and
75
+ passes `nil` when neither is — which is correct for a product whose settings
76
+ are all personal. Ask the developer which of the three applies; there is no
77
+ safe default.
78
+
79
+ 6. **Add `can?` once a section names a capability.** It takes one capability and
80
+ answers true or false:
81
+
82
+ ```ruby
83
+ def can?(capability)
84
+ Current.person.can?(capability)
85
+ end
86
+ ```
87
+
88
+ A section naming no capability is shown to everyone the app let in, so an app
89
+ whose sections all name none does not need this method.
90
+
91
+ 7. **Declare the app's capabilities, if it has any.** Assign `SettingsHub.capabilities`
92
+ in `config/initializers/settings_hub.rb`, creating that file if the app has none:
93
+
94
+ ```ruby
95
+ SettingsHub.capabilities = -> { Citizen.capabilities }
96
+ ```
97
+
98
+ It takes a list or something answering `call` that returns one; use the
99
+ callable form when the list comes from a class the app reloads. An app that
100
+ declares nothing is never refused a registration naming a capability, which is
101
+ what lets settings_hub be installed without the gem that would normally supply the
102
+ list. Ask the developer where the app's capability list comes from rather than
103
+ guessing at a constant.
104
+
105
+ 8. **Add `after_settings_change` only if the app needs it.** It takes `section:`
106
+ and `person:` as keywords and runs after a change succeeds:
107
+
108
+ ```ruby
109
+ def after_settings_change(section:, person:)
110
+ Audit.record(person: person, changed: section)
111
+ end
112
+ ```
113
+
114
+ Leave it out unless the developer names something the app must do on every
115
+ settings change. SettingsHub runs it for a change submitted from the settings page
116
+ and not for one submitted by a caller outside the browser, so tell the
117
+ developer this hook does not see every change if the app also has such
118
+ callers.
119
+
120
+ ## Conventions
121
+
122
+ **Check it worked.** Start the app, sign in and visit the mount path. SettingsHub
123
+ registers a Profile section itself, so a working install shows a `User` list with
124
+ `Profile` in it and a Name field beside it. An empty page means the engine is
125
+ mounted but nothing registered; a failure on the Name field means
126
+ `current_person` returns something that does not answer `name`.
127
+
128
+ **The shipped Profile section reads and writes `name` on whatever
129
+ `current_person` returns.** An app whose person record has no writable `name`
130
+ replaces that section, which is settings_hub-develop's job rather than this one's.
131
+
132
+ **`can?` and `SettingsHub.capabilities` become required later.** Installing a gem that
133
+ registers sections naming capabilities makes both necessary even though the app
134
+ did not need them at install time — a section whose capability the app does not
135
+ recognise stops the app from starting, and one whose capability nothing answers
136
+ for is never shown.
137
+
138
+ **Re-run these steps when the host changes who is signed in.** Renaming or moving
139
+ the app's current-person method, or changing which account settings act on,
140
+ breaks the settings page and nothing else reports it.
141
+
142
+ **Out of scope.** Adding the app's own sections, editing the object a submitted
143
+ change is handed to, and writing the partial a section draws all belong to
144
+ settings_hub-develop. So does replacing a section another gem registered, and so does
145
+ reading or changing settings from outside the browser.
@@ -0,0 +1,57 @@
1
+ scope: settings — one settings page whose sections are registered by the app and by other gems
2
+
3
+ install:
4
+ - gem "settings_hub"
5
+ - mount SettingsHub::Engine
6
+ - current_person
7
+ - settings_account
8
+ - can?
9
+ - after_settings_change
10
+ - SettingsHub.capabilities
11
+
12
+ develop:
13
+ - bin/rails generate settings_hub:section
14
+ - GET /settings/api/sections
15
+ - PATCH /settings/api/sections/:key/:action_name
16
+ - SettingsHub.section
17
+ - SettingsHub.replace_section
18
+ - SettingsHub.registry
19
+ - SettingsHub::Result.ok
20
+ - SettingsHub::Result.refused
21
+ - SettingsHub::BadRegistration
22
+ - section.key
23
+ - section.area
24
+ - section.title
25
+ - section.renders
26
+ - section.capability
27
+ - section.runs
28
+ - section.at
29
+ - section.action
30
+ - section.actions
31
+ - section.named_actions?
32
+ - person
33
+ - account
34
+ - selection
35
+ - submit_url
36
+ - submit_urls
37
+
38
+ sources:
39
+ - lib/settings_hub.rb
40
+ - lib/settings_hub/registry.rb
41
+ - lib/settings_hub/section.rb
42
+ - lib/settings_hub/result.rb
43
+ - lib/settings_hub/bad_registration.rb
44
+ - lib/settings_hub/settings_account.rb
45
+ - lib/settings_hub/engine.rb
46
+ - config/routes.rb
47
+ - app/controllers/settings_hub/application_controller.rb
48
+ - app/controllers/settings_hub/sections_controller.rb
49
+ - app/controllers/settings_hub/api/sections_controller.rb
50
+ - app/controllers/settings_hub/settings_controller.rb
51
+ - app/views/settings_hub/settings/show.html.erb
52
+ - app/views/settings_hub/sections/_profile.html.erb
53
+ - app/models/settings_hub/change_name.rb
54
+ - test/dummy/app/controllers/application_controller.rb
55
+ - test/dummy/app/models/dummy_settings.rb
56
+ - lib/generators/settings_hub/section/section_generator.rb
57
+ - lib/settings_hub/reference/guide.md
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: settings_hub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tylercschneider
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: keystone_ui
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ description: SettingsHub owns a settings page, the list of sections on it, the route
41
+ each section is served at, and the check for who may see a section. It ships user
42
+ sections itself, and other gems and the app register their own. Each thing a person
43
+ can do is a plain object a page or an API can call.
44
+ email:
45
+ - tylercschneider@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - MIT-LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - app/assets/stylesheets/settings_hub/application.css
54
+ - app/controllers/settings_hub/api/sections_controller.rb
55
+ - app/controllers/settings_hub/application_controller.rb
56
+ - app/controllers/settings_hub/sections_controller.rb
57
+ - app/controllers/settings_hub/settings_controller.rb
58
+ - app/helpers/settings_hub/app_routes_helper.rb
59
+ - app/helpers/settings_hub/application_helper.rb
60
+ - app/jobs/settings_hub/application_job.rb
61
+ - app/mailers/settings_hub/application_mailer.rb
62
+ - app/models/settings_hub/application_record.rb
63
+ - app/models/settings_hub/change_name.rb
64
+ - app/views/settings_hub/sections/_profile.html.erb
65
+ - app/views/settings_hub/settings/show.html.erb
66
+ - config/routes.rb
67
+ - lib/generators/settings_hub/section/section_generator.rb
68
+ - lib/generators/settings_hub/section/templates/action.rb.tt
69
+ - lib/generators/settings_hub/section/templates/action_test.rb.tt
70
+ - lib/generators/settings_hub/section/templates/partial.html.erb.tt
71
+ - lib/settings_hub.rb
72
+ - lib/settings_hub/bad_registration.rb
73
+ - lib/settings_hub/engine.rb
74
+ - lib/settings_hub/reference/guide.md
75
+ - lib/settings_hub/registry.rb
76
+ - lib/settings_hub/result.rb
77
+ - lib/settings_hub/section.rb
78
+ - lib/settings_hub/settings_account.rb
79
+ - lib/settings_hub/version.rb
80
+ - lib/tasks/settings_hub_tasks.rake
81
+ - the_local/agents/settings_hub-develop.md
82
+ - the_local/agents/settings_hub-info.md
83
+ - the_local/agents/settings_hub-install.md
84
+ - the_local/interface.yml
85
+ homepage: https://github.com/DYB-Development/settings_hub
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ allowed_push_host: https://rubygems.org
90
+ homepage_uri: https://github.com/DYB-Development/settings_hub
91
+ source_code_uri: https://github.com/DYB-Development/settings_hub
92
+ changelog_uri: https://github.com/DYB-Development/settings_hub/blob/main/CHANGELOG.md
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 4.0.20
108
+ specification_version: 4
109
+ summary: 'Settings sections for Rails apps: one shell, many registrars'
110
+ test_files: []