bp3-core 0.1.4 → 0.2.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -3
- data/.ruby-version +1 -2
- data/CHANGELOG.md +11 -0
- data/CLAUDE.md +98 -0
- data/Gemfile.lock +94 -67
- data/README.md +9 -0
- data/Rakefile +4 -3
- data/bp3-core.gemspec +9 -8
- data/lib/bp3/core/system_logs.rb +117 -0
- data/lib/bp3/core/tenantable.rb +0 -2
- data/lib/bp3/core/test.rb +38 -0
- data/lib/bp3/core/version.rb +1 -1
- data/lib/bp3/core.rb +1 -0
- metadata +36 -36
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a9c4c0dbb3305cf4f01673f5774ec40ffc8ea92ce204cdb29a474de30fec52b
|
|
4
|
+
data.tar.gz: 1512daac46af4d57c18eb5953895f12ffafa352204792bae9865867640b0d60c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75409b743dd9c8f9fd2b9e33c585b8712599f4a0f1fb2066879a37f65105b5036264b29964f1ae635c16a468e4828640ad2474e476b8f72923a97ddb806275b5
|
|
7
|
+
data.tar.gz: 1bd7fa7234f47dea8f6871a36718a6f11ec7dbb605bd81fca38a3d6d5e99b3c2b482dc9e30138d2a9d7007ee6943fcc201bac385ed0c09ebcbf50296fc8bd38d
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
ruby-3.
|
|
2
|
-
|
|
1
|
+
ruby-3.4.6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.0] - 2026-01-09
|
|
4
|
+
|
|
5
|
+
- Add bp3-request_state dependency
|
|
6
|
+
- Add SystemLogs concern
|
|
7
|
+
- Update gems
|
|
8
|
+
- Update ruby version to 3.4.6
|
|
9
|
+
|
|
10
|
+
## [0.1.5] - 2024-11-18
|
|
11
|
+
|
|
12
|
+
- Use ruby 3.3.5 and relax gem constraints
|
|
13
|
+
|
|
3
14
|
## [0.1.3] - 2024-07-31
|
|
4
15
|
|
|
5
16
|
- Ensure use of common global request state
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
bp3-core is a Ruby gem providing core ActiveSupport concerns for BP3 (persuavis/black_phoebe_3), a multi-site multi-tenant Rails application. The gem provides reusable modules that handle common patterns like tenancy, feature flags, ransack integration, request tracking, and sequence numbering.
|
|
8
|
+
|
|
9
|
+
## Common Commands
|
|
10
|
+
|
|
11
|
+
### Testing and Linting
|
|
12
|
+
- Run tests: `bundle exec rspec` or `rake spec`
|
|
13
|
+
- Run linting: `bundle exec rubocop` or `rake rubocop`
|
|
14
|
+
- Run both tests and linting (default): `rake`
|
|
15
|
+
- Run a single test file: `bundle exec rspec spec/path/to/file_spec.rb`
|
|
16
|
+
- Run a specific test: `bundle exec rspec spec/path/to/file_spec.rb:LINE_NUMBER`
|
|
17
|
+
|
|
18
|
+
### Development
|
|
19
|
+
- Install dependencies: `bundle install`
|
|
20
|
+
- Interactive console: `bin/console`
|
|
21
|
+
- Install gem locally: `rake install`
|
|
22
|
+
- Generate documentation: `yard doc`
|
|
23
|
+
|
|
24
|
+
### Release
|
|
25
|
+
- Update version in `lib/bp3/core/version.rb`
|
|
26
|
+
- Run `rake release` to create git tag, push commits/tags, and publish to rubygems.org
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+
### Core Concerns
|
|
31
|
+
|
|
32
|
+
The gem provides several ActiveSupport::Concern modules that are included in ActiveRecord models and controllers:
|
|
33
|
+
|
|
34
|
+
**Tenantable** (`lib/bp3/core/tenantable.rb`)
|
|
35
|
+
- Handles multi-tenant architecture with sites, tenants, and workspaces
|
|
36
|
+
- Automatically sets foreign keys from GlobalRequestState
|
|
37
|
+
- Creates associations: `sites_site_id` → Sites::Site, `tenant_id` → Tenant, `workspaces_workspace_id` → Workspaces::Workspace
|
|
38
|
+
- Provides aliases: `site`/`site=`, `workspace`/`workspace=`
|
|
39
|
+
- Implements default scopes based on current site/tenant context
|
|
40
|
+
- Validates tenant and workspace belong to correct site
|
|
41
|
+
- Uses reflection to determine which columns exist and only creates relevant associations
|
|
42
|
+
- GlobalRequestState is expected to be defined in the consuming application
|
|
43
|
+
|
|
44
|
+
**Ransackable** (`lib/bp3/core/ransackable.rb`)
|
|
45
|
+
- Provides ransack integration for searchable/sortable models
|
|
46
|
+
- Implements `ransackable_attributes`, `ransackable_associations`, `ransackable_scopes`
|
|
47
|
+
- Uses global configuration for exceptions: `Bp3::Core::Ransackable.attribute_exceptions` and `Bp3::Core::Ransackable.association_exceptions`
|
|
48
|
+
- Must be configured in `config/initializers/bp3-core.rb` in consuming application
|
|
49
|
+
|
|
50
|
+
**Rqid** (`lib/bp3/core/rqid.rb`)
|
|
51
|
+
- Tracks request ID (rqid) for all records
|
|
52
|
+
- Automatically sets rqid on record creation from GlobalRequestState
|
|
53
|
+
- Creates associations to original request, response, and visit records
|
|
54
|
+
- Requires configuration of `Bp3::Core::Rqid.global_request_state_class_name` and `Bp3::Core::Rqid.global_request_state_method`
|
|
55
|
+
|
|
56
|
+
**Sqnr** (`lib/bp3/core/sqnr.rb`)
|
|
57
|
+
- Provides sequence number (sqnr) ordering
|
|
58
|
+
- Adds `sqnr` (ascending) and `rnqs` (descending) scopes
|
|
59
|
+
- Class macro `use_sqnr_for_ordering` sets `implicit_order_column` to sqnr
|
|
60
|
+
|
|
61
|
+
**Actions**, **Cookies**, **Displayable**, **FeatureFlags**, **Settings**, **SystemLogs**
|
|
62
|
+
- Additional concerns for controllers and models
|
|
63
|
+
- See README.md for usage patterns
|
|
64
|
+
|
|
65
|
+
### Module Organization
|
|
66
|
+
|
|
67
|
+
The gem follows standard Ruby gem structure:
|
|
68
|
+
- `lib/bp3-core.rb` - Main entry point, requires `lib/bp3/core.rb`
|
|
69
|
+
- `lib/bp3/core.rb` - Requires all concern modules, defines `Bp3::Core` namespace
|
|
70
|
+
- `lib/bp3/core/*.rb` - Individual concern modules
|
|
71
|
+
- Module attributes use `mattr_accessor` for configuration points that must be set by consuming applications
|
|
72
|
+
|
|
73
|
+
### Configuration Pattern
|
|
74
|
+
|
|
75
|
+
Concerns that need application-specific configuration use `mattr_accessor` and class methods:
|
|
76
|
+
- `Bp3::Core.system_exception_name` / `.system_log_name`
|
|
77
|
+
- `Bp3::Core::Ransackable.attribute_exceptions` / `.association_exceptions`
|
|
78
|
+
- `Bp3::Core::Rqid.global_request_state_class_name` / `.global_request_state_method`
|
|
79
|
+
|
|
80
|
+
These are set in the consuming application's `config/initializers/bp3-core.rb`.
|
|
81
|
+
|
|
82
|
+
### Dependencies
|
|
83
|
+
|
|
84
|
+
The gem depends on:
|
|
85
|
+
- `activesupport ~> 8.1` - For ActiveSupport::Concern and core extensions
|
|
86
|
+
- `actionview ~> 8.1` - For view helpers
|
|
87
|
+
- Development: `rspec`, `rubocop`, `rubocop-rake`, `rubocop-rspec`
|
|
88
|
+
|
|
89
|
+
## Code Style
|
|
90
|
+
|
|
91
|
+
RuboCop configuration (`.rubocop.yml`):
|
|
92
|
+
- Target Ruby version: 3.2.2
|
|
93
|
+
- Custom metrics: AbcSize max 26, MethodLength max 15, ModuleLength max 150
|
|
94
|
+
- RSpec: ExampleLength max 10, MultipleExpectations max 4
|
|
95
|
+
- Style/Documentation disabled
|
|
96
|
+
- Uses `rubocop-rake` and `rubocop-rspec` plugins
|
|
97
|
+
|
|
98
|
+
All files use `# frozen_string_literal: true`.
|
data/Gemfile.lock
CHANGED
|
@@ -1,123 +1,150 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
bp3-core (0.
|
|
5
|
-
actionview (
|
|
6
|
-
activesupport (
|
|
4
|
+
bp3-core (0.2.0)
|
|
5
|
+
actionview (~> 8.1)
|
|
6
|
+
activesupport (~> 8.1)
|
|
7
|
+
bp3-request_state (~> 0.1)
|
|
7
8
|
|
|
8
9
|
GEM
|
|
9
10
|
remote: https://rubygems.org/
|
|
10
11
|
specs:
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
actionpack (8.1.2)
|
|
13
|
+
actionview (= 8.1.2)
|
|
14
|
+
activesupport (= 8.1.2)
|
|
15
|
+
nokogiri (>= 1.8.5)
|
|
16
|
+
rack (>= 2.2.4)
|
|
17
|
+
rack-session (>= 1.0.1)
|
|
18
|
+
rack-test (>= 0.6.3)
|
|
19
|
+
rails-dom-testing (~> 2.2)
|
|
20
|
+
rails-html-sanitizer (~> 1.6)
|
|
21
|
+
useragent (~> 0.16)
|
|
22
|
+
actionview (8.1.2)
|
|
23
|
+
activesupport (= 8.1.2)
|
|
13
24
|
builder (~> 3.1)
|
|
14
25
|
erubi (~> 1.11)
|
|
15
26
|
rails-dom-testing (~> 2.2)
|
|
16
27
|
rails-html-sanitizer (~> 1.6)
|
|
17
|
-
activesupport (
|
|
28
|
+
activesupport (8.1.2)
|
|
18
29
|
base64
|
|
19
30
|
bigdecimal
|
|
20
|
-
concurrent-ruby (~> 1.0, >= 1.
|
|
31
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
21
32
|
connection_pool (>= 2.2.5)
|
|
22
33
|
drb
|
|
23
34
|
i18n (>= 1.6, < 2)
|
|
35
|
+
json
|
|
36
|
+
logger (>= 1.4.2)
|
|
24
37
|
minitest (>= 5.1)
|
|
25
|
-
|
|
26
|
-
tzinfo (~> 2.0)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
securerandom (>= 0.3)
|
|
39
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
40
|
+
uri (>= 0.13.1)
|
|
41
|
+
ast (2.4.3)
|
|
42
|
+
base64 (0.3.0)
|
|
43
|
+
bigdecimal (4.0.1)
|
|
44
|
+
bp3-request_state (0.1.3)
|
|
45
|
+
actionpack (~> 8.1)
|
|
46
|
+
activesupport (~> 8.1)
|
|
47
|
+
request_store (>= 1.5.1)
|
|
30
48
|
builder (3.3.0)
|
|
31
|
-
concurrent-ruby (1.3.
|
|
32
|
-
connection_pool (
|
|
49
|
+
concurrent-ruby (1.3.6)
|
|
50
|
+
connection_pool (3.0.2)
|
|
33
51
|
crass (1.0.6)
|
|
34
|
-
diff-lcs (1.
|
|
35
|
-
drb (2.2.
|
|
36
|
-
erubi (1.13.
|
|
37
|
-
i18n (1.14.
|
|
52
|
+
diff-lcs (1.6.2)
|
|
53
|
+
drb (2.2.3)
|
|
54
|
+
erubi (1.13.1)
|
|
55
|
+
i18n (1.14.8)
|
|
38
56
|
concurrent-ruby (~> 1.0)
|
|
39
|
-
json (2.
|
|
40
|
-
language_server-protocol (3.17.0.
|
|
41
|
-
|
|
57
|
+
json (2.18.0)
|
|
58
|
+
language_server-protocol (3.17.0.5)
|
|
59
|
+
lint_roller (1.1.0)
|
|
60
|
+
logger (1.7.0)
|
|
61
|
+
loofah (2.25.0)
|
|
42
62
|
crass (~> 1.0.2)
|
|
43
63
|
nokogiri (>= 1.12.0)
|
|
44
|
-
minitest (
|
|
45
|
-
|
|
46
|
-
nokogiri (1.
|
|
64
|
+
minitest (6.0.1)
|
|
65
|
+
prism (~> 1.5)
|
|
66
|
+
nokogiri (1.19.0-x86_64-darwin)
|
|
47
67
|
racc (~> 1.4)
|
|
48
|
-
parallel (1.
|
|
49
|
-
parser (3.3.
|
|
68
|
+
parallel (1.27.0)
|
|
69
|
+
parser (3.3.10.0)
|
|
50
70
|
ast (~> 2.4.1)
|
|
51
71
|
racc
|
|
72
|
+
prism (1.7.0)
|
|
52
73
|
racc (1.8.1)
|
|
53
|
-
|
|
74
|
+
rack (3.2.4)
|
|
75
|
+
rack-session (2.1.1)
|
|
76
|
+
base64 (>= 0.1.0)
|
|
77
|
+
rack (>= 3.0.0)
|
|
78
|
+
rack-test (2.2.0)
|
|
79
|
+
rack (>= 1.3)
|
|
80
|
+
rails-dom-testing (2.3.0)
|
|
54
81
|
activesupport (>= 5.0.0)
|
|
55
82
|
minitest
|
|
56
83
|
nokogiri (>= 1.6)
|
|
57
|
-
rails-html-sanitizer (1.6.
|
|
84
|
+
rails-html-sanitizer (1.6.2)
|
|
58
85
|
loofah (~> 2.21)
|
|
59
|
-
nokogiri (
|
|
86
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
60
87
|
rainbow (3.1.1)
|
|
61
|
-
rake (13.
|
|
62
|
-
regexp_parser (2.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
rspec (3.13.
|
|
88
|
+
rake (13.3.1)
|
|
89
|
+
regexp_parser (2.11.3)
|
|
90
|
+
request_store (1.7.0)
|
|
91
|
+
rack (>= 1.4)
|
|
92
|
+
rspec (3.13.2)
|
|
66
93
|
rspec-core (~> 3.13.0)
|
|
67
94
|
rspec-expectations (~> 3.13.0)
|
|
68
95
|
rspec-mocks (~> 3.13.0)
|
|
69
|
-
rspec-core (3.13.
|
|
96
|
+
rspec-core (3.13.6)
|
|
70
97
|
rspec-support (~> 3.13.0)
|
|
71
|
-
rspec-expectations (3.13.
|
|
98
|
+
rspec-expectations (3.13.5)
|
|
72
99
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
73
100
|
rspec-support (~> 3.13.0)
|
|
74
|
-
rspec-mocks (3.13.
|
|
101
|
+
rspec-mocks (3.13.7)
|
|
75
102
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
76
103
|
rspec-support (~> 3.13.0)
|
|
77
|
-
rspec-support (3.13.
|
|
78
|
-
rubocop (1.
|
|
104
|
+
rspec-support (3.13.6)
|
|
105
|
+
rubocop (1.82.1)
|
|
79
106
|
json (~> 2.3)
|
|
80
|
-
language_server-protocol (
|
|
107
|
+
language_server-protocol (~> 3.17.0.2)
|
|
108
|
+
lint_roller (~> 1.1.0)
|
|
81
109
|
parallel (~> 1.10)
|
|
82
110
|
parser (>= 3.3.0.2)
|
|
83
111
|
rainbow (>= 2.2.2, < 4.0)
|
|
84
|
-
regexp_parser (>= 2.
|
|
85
|
-
|
|
86
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
|
112
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
113
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
87
114
|
ruby-progressbar (~> 1.7)
|
|
88
|
-
unicode-display_width (>= 2.4.0, <
|
|
89
|
-
rubocop-ast (1.
|
|
90
|
-
parser (>= 3.3.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
rubocop (
|
|
95
|
-
rubocop-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
rubocop (~> 1.40)
|
|
99
|
-
rubocop-capybara (~> 2.17)
|
|
100
|
-
rubocop-factory_bot (~> 2.22)
|
|
101
|
-
rubocop-rspec_rails (~> 2.28)
|
|
102
|
-
rubocop-rspec_rails (2.29.1)
|
|
103
|
-
rubocop (~> 1.61)
|
|
115
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
116
|
+
rubocop-ast (1.49.0)
|
|
117
|
+
parser (>= 3.3.7.2)
|
|
118
|
+
prism (~> 1.7)
|
|
119
|
+
rubocop-rake (0.7.1)
|
|
120
|
+
lint_roller (~> 1.1)
|
|
121
|
+
rubocop (>= 1.72.1)
|
|
122
|
+
rubocop-rspec (3.9.0)
|
|
123
|
+
lint_roller (~> 1.1)
|
|
124
|
+
rubocop (~> 1.81)
|
|
104
125
|
ruby-progressbar (1.13.0)
|
|
105
|
-
|
|
126
|
+
securerandom (0.4.1)
|
|
106
127
|
tzinfo (2.0.6)
|
|
107
128
|
concurrent-ruby (~> 1.0)
|
|
108
|
-
unicode-display_width (2.
|
|
129
|
+
unicode-display_width (3.2.0)
|
|
130
|
+
unicode-emoji (~> 4.1)
|
|
131
|
+
unicode-emoji (4.2.0)
|
|
132
|
+
uri (1.1.1)
|
|
133
|
+
useragent (0.16.11)
|
|
109
134
|
|
|
110
135
|
PLATFORMS
|
|
111
136
|
x86_64-darwin-21
|
|
112
137
|
x86_64-darwin-22
|
|
138
|
+
x86_64-darwin-23
|
|
139
|
+
x86_64-darwin-24
|
|
113
140
|
|
|
114
141
|
DEPENDENCIES
|
|
115
142
|
bp3-core!
|
|
116
|
-
rake (
|
|
117
|
-
rspec (
|
|
118
|
-
rubocop (
|
|
119
|
-
rubocop-rake (
|
|
120
|
-
rubocop-rspec (
|
|
143
|
+
rake (>= 13.0)
|
|
144
|
+
rspec (>= 3.0)
|
|
145
|
+
rubocop (>= 1.21)
|
|
146
|
+
rubocop-rake (>= 0.6)
|
|
147
|
+
rubocop-rspec (>= 2.25)
|
|
121
148
|
|
|
122
149
|
BUNDLED WITH
|
|
123
|
-
2.
|
|
150
|
+
2.7.2
|
data/README.md
CHANGED
|
@@ -61,6 +61,15 @@ To use :sqnr for record ordering for a particular model, use the class macro:
|
|
|
61
61
|
```ruby
|
|
62
62
|
use_sqnr_for_ordering
|
|
63
63
|
```
|
|
64
|
+
In all models that need logging of messages and exceptions to the db, add:
|
|
65
|
+
```ruby
|
|
66
|
+
include Bp3::Core::SystemLogs
|
|
67
|
+
```
|
|
68
|
+
Then in your application's `config/initializers/bp3-core`, add:
|
|
69
|
+
```ruby
|
|
70
|
+
Bp3::Core::SystemLogs.system_log_name = 'System::Log' # any class that exposes a .log_message method
|
|
71
|
+
Bp3::Core::SystemLogs.system_exception_name = 'System::Exception' # any class that exposes a .log_exception method
|
|
72
|
+
```
|
|
64
73
|
In all ActiveRecord models (or their base class) that use site, tenant and/or workspace
|
|
65
74
|
attributes that need to be populated from global state, add:
|
|
66
75
|
```ruby
|
data/Rakefile
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'bundler/setup'
|
|
3
4
|
require 'bundler/gem_tasks'
|
|
4
5
|
require 'rspec/core/rake_task'
|
|
5
|
-
|
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
7
|
-
|
|
8
6
|
require 'rubocop/rake_task'
|
|
9
7
|
|
|
8
|
+
Dir.glob('lib/tasks/**/*.rake').each { |file| load file }
|
|
9
|
+
|
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
10
11
|
RuboCop::RakeTask.new
|
|
11
12
|
|
|
12
13
|
task default: %i[spec rubocop]
|
data/bp3-core.gemspec
CHANGED
|
@@ -31,14 +31,15 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
32
|
spec.require_paths = ['lib']
|
|
33
33
|
|
|
34
|
-
spec.add_dependency 'actionview',
|
|
35
|
-
spec.add_dependency 'activesupport',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
spec.add_development_dependency '
|
|
39
|
-
spec.add_development_dependency '
|
|
40
|
-
spec.add_development_dependency 'rubocop
|
|
41
|
-
spec.add_development_dependency 'rubocop-
|
|
34
|
+
spec.add_dependency 'actionview', '~> 8.1'
|
|
35
|
+
spec.add_dependency 'activesupport', '~> 8.1'
|
|
36
|
+
spec.add_dependency 'bp3-request_state', '~> 0.1'
|
|
37
|
+
|
|
38
|
+
spec.add_development_dependency 'rake', '>= 13.0'
|
|
39
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
|
40
|
+
spec.add_development_dependency 'rubocop', '>= 1.21'
|
|
41
|
+
spec.add_development_dependency 'rubocop-rake', '>= 0.6'
|
|
42
|
+
spec.add_development_dependency 'rubocop-rspec', '>= 2.25'
|
|
42
43
|
|
|
43
44
|
# For more information and examples about making a new gem, check out our
|
|
44
45
|
# guide at: https://bundler.io/guides/creating_gem.html
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'logger'
|
|
4
|
+
|
|
5
|
+
module Bp3
|
|
6
|
+
module Core
|
|
7
|
+
module SystemLogs
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
SYSTEM_LOG_DEFAULTS = { log_to_db: true, log_to_io: true }.freeze
|
|
11
|
+
|
|
12
|
+
mattr_accessor :system_exception_name, :system_log_name
|
|
13
|
+
|
|
14
|
+
def self.system_exception_class
|
|
15
|
+
@@system_exception_class ||= system_exception_name.constantize # rubocop:disable Style/ClassVars
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.system_log_class
|
|
19
|
+
@@system_log_class ||= system_log_name.constantize # rubocop:disable Style/ClassVars
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Class methods for use in contexts without instance methods
|
|
23
|
+
module ClassMethods
|
|
24
|
+
# rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
|
|
25
|
+
def log(level:, key:, message: nil, exception: nil, site: nil, details: {}, **system_log_options)
|
|
26
|
+
system_log_options = SYSTEM_LOG_DEFAULTS.dup.merge(system_log_options)
|
|
27
|
+
record = nil
|
|
28
|
+
if exception
|
|
29
|
+
if system_log_options[:log_to_io]
|
|
30
|
+
rails_logger.debug do
|
|
31
|
+
"SystemLogs, #{level}, #{key}, #{exception.message}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
record = exception_logger.log_exception(exception, site:, key:, details:) if system_log_options[:log_to_db]
|
|
35
|
+
end
|
|
36
|
+
return record if (message || '').strip == ''
|
|
37
|
+
|
|
38
|
+
rails_logger.debug { "SystemLogs, #{level}, #{key}, #{message}" } if system_log_options[:log_to_io]
|
|
39
|
+
begin
|
|
40
|
+
system_logger.log_message(level:, key:, message:, details:) if system_log_options[:log_to_db]
|
|
41
|
+
rescue StandardError => e
|
|
42
|
+
rails_logger.error { "SystemLogs.log failed: #{e.message}" }
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
# rubocop:enable Metrics/ParameterLists, Metrics/MethodLength
|
|
47
|
+
|
|
48
|
+
def log_debug(key:, message:, details: {}, **system_log_options)
|
|
49
|
+
log(level: 'debug', key:, message:, details:, **system_log_options)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def log_info(key:, message:, details: {}, **system_log_options)
|
|
53
|
+
log(level: 'info', key:, message:, details:, **system_log_options)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def log_warn(key:, message:, details: {}, **system_log_options)
|
|
57
|
+
log(level: 'warn', key:, message:, details:, **system_log_options)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def log_error(key:, message:, details: {}, **system_log_options)
|
|
61
|
+
log(level: 'error', key:, message:, details:, **system_log_options)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def log_exception(exception, key:, details: {}, **system_log_options)
|
|
65
|
+
if exception.nil?
|
|
66
|
+
rails_logger.error { "SystemLogs, #{key}, nil exception logged" }
|
|
67
|
+
return nil
|
|
68
|
+
end
|
|
69
|
+
log(level: 'exception', key:, exception:, details:, **system_log_options)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def rails_logger
|
|
73
|
+
return Rails.logger if defined?(Rails)
|
|
74
|
+
|
|
75
|
+
::Logger.new($stdout, level: Logger::ERROR)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def system_logger
|
|
79
|
+
::Bp3::Core::SystemLogs.system_log_class
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def exception_logger
|
|
83
|
+
::Bp3::Core::SystemLogs.system_exception_class
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# rubocop:disable Metrics/ParameterLists
|
|
88
|
+
def log(level:, key:, message: nil, exception: nil, site: nil, details: {}, **system_log_options)
|
|
89
|
+
SystemLogs.log(level:, key:, message:, exception:, site:, details:, **system_log_options)
|
|
90
|
+
end
|
|
91
|
+
# rubocop:enable Metrics/ParameterLists
|
|
92
|
+
|
|
93
|
+
def log_debug(key:, message:, details: {}, **system_log_options)
|
|
94
|
+
SystemLogs.log_debug(key:, message:, details:, **system_log_options)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def log_info(key:, message:, details: {}, **system_log_options)
|
|
98
|
+
SystemLogs.log_info(key:, message:, details:, **system_log_options)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def log_warn(key:, message:, details: {}, **system_log_options)
|
|
102
|
+
SystemLogs.log_warn(key:, message:, details:, **system_log_options)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def log_error(key:, message:, details: {}, **system_log_options)
|
|
106
|
+
SystemLogs.log_error(key:, message:, details:, **system_log_options)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def log_exception(exception, key:, details: {}, **system_log_options)
|
|
110
|
+
SystemLogs.log_exception(exception, key:, details:, **system_log_options)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Extend self to make ClassMethods available directly on SystemLogs module
|
|
114
|
+
extend ClassMethods
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
data/lib/bp3/core/tenantable.rb
CHANGED
|
@@ -51,7 +51,6 @@ module Bp3
|
|
|
51
51
|
errors.add(:workspaces_workspace, :must_match_site)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
# rubocop:disable: Metrics/BlockLength
|
|
55
54
|
class_methods do
|
|
56
55
|
def configure_tenancy(tenancy_configuration = {})
|
|
57
56
|
@tenancy_configuration = default_configuration.merge(tenancy_configuration)
|
|
@@ -137,7 +136,6 @@ module Bp3
|
|
|
137
136
|
}
|
|
138
137
|
end
|
|
139
138
|
end
|
|
140
|
-
# rubocop:disable: Metrics/BlockLength
|
|
141
139
|
end
|
|
142
140
|
end
|
|
143
141
|
end
|
data/lib/bp3/core/test.rb
CHANGED
|
@@ -4,6 +4,40 @@ module Bp3
|
|
|
4
4
|
module Core
|
|
5
5
|
# Bp3::Core::Test provides a convenience class for testing Bp3::Core
|
|
6
6
|
class Test
|
|
7
|
+
class SystemLogger
|
|
8
|
+
@log_count = 0
|
|
9
|
+
|
|
10
|
+
def self.log_message(level:, key:, message:, details:)
|
|
11
|
+
puts "Test:SystemLogger: #{level} #{key} #{message} #{details}"
|
|
12
|
+
add_count
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.add_count
|
|
16
|
+
@log_count += 1
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
attr_reader :log_count
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class ExceptionLogger
|
|
25
|
+
@log_count = 0
|
|
26
|
+
|
|
27
|
+
def self.log_exception(exception, site:, key:, details:)
|
|
28
|
+
puts "Test:ExceptionLogger: #{site&.display_name} #{key} #{exception.message} #{details}"
|
|
29
|
+
add_count
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.add_count
|
|
33
|
+
@log_count += 1
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class << self
|
|
37
|
+
attr_reader :log_count
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
7
41
|
# to test Ransackable
|
|
8
42
|
include Ransackable
|
|
9
43
|
|
|
@@ -38,6 +72,10 @@ module Bp3
|
|
|
38
72
|
# to test Sqnr
|
|
39
73
|
include Sqnr
|
|
40
74
|
|
|
75
|
+
# to test SystemLogs
|
|
76
|
+
include SystemLogs # to use log methods on an instance
|
|
77
|
+
extend SystemLogs # to use log methods on the class
|
|
78
|
+
|
|
41
79
|
# to test Tenantable
|
|
42
80
|
# first define this:
|
|
43
81
|
def self.connection; end
|
data/lib/bp3/core/version.rb
CHANGED
data/lib/bp3/core.rb
CHANGED
|
@@ -9,6 +9,7 @@ require_relative 'core/displayable'
|
|
|
9
9
|
require_relative 'core/feature_flags'
|
|
10
10
|
require_relative 'core/ransackable'
|
|
11
11
|
require_relative 'core/settings'
|
|
12
|
+
require_relative 'core/system_logs'
|
|
12
13
|
require_relative 'core/tenantable'
|
|
13
14
|
require_relative 'core/rqid'
|
|
14
15
|
require_relative 'core/sqnr'
|
metadata
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bp3-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wim den Braven
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: actionview
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: 7.1.2
|
|
20
|
-
- - "<"
|
|
16
|
+
- - "~>"
|
|
21
17
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '8'
|
|
18
|
+
version: '8.1'
|
|
23
19
|
type: :runtime
|
|
24
20
|
prerelease: false
|
|
25
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
22
|
requirements:
|
|
27
|
-
- - "
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: 7.1.2
|
|
30
|
-
- - "<"
|
|
23
|
+
- - "~>"
|
|
31
24
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '8'
|
|
25
|
+
version: '8.1'
|
|
33
26
|
- !ruby/object:Gem::Dependency
|
|
34
27
|
name: activesupport
|
|
35
28
|
requirement: !ruby/object:Gem::Requirement
|
|
36
29
|
requirements:
|
|
37
|
-
- - "
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: 7.1.2
|
|
40
|
-
- - "<"
|
|
30
|
+
- - "~>"
|
|
41
31
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: '8'
|
|
32
|
+
version: '8.1'
|
|
43
33
|
type: :runtime
|
|
44
34
|
prerelease: false
|
|
45
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
46
36
|
requirements:
|
|
47
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
48
38
|
- !ruby/object:Gem::Version
|
|
49
|
-
version:
|
|
50
|
-
|
|
39
|
+
version: '8.1'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: bp3-request_state
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0.1'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
51
52
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: '
|
|
53
|
+
version: '0.1'
|
|
53
54
|
- !ruby/object:Gem::Dependency
|
|
54
55
|
name: rake
|
|
55
56
|
requirement: !ruby/object:Gem::Requirement
|
|
56
57
|
requirements:
|
|
57
|
-
- - "
|
|
58
|
+
- - ">="
|
|
58
59
|
- !ruby/object:Gem::Version
|
|
59
60
|
version: '13.0'
|
|
60
61
|
type: :development
|
|
61
62
|
prerelease: false
|
|
62
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
63
64
|
requirements:
|
|
64
|
-
- - "
|
|
65
|
+
- - ">="
|
|
65
66
|
- !ruby/object:Gem::Version
|
|
66
67
|
version: '13.0'
|
|
67
68
|
- !ruby/object:Gem::Dependency
|
|
68
69
|
name: rspec
|
|
69
70
|
requirement: !ruby/object:Gem::Requirement
|
|
70
71
|
requirements:
|
|
71
|
-
- - "
|
|
72
|
+
- - ">="
|
|
72
73
|
- !ruby/object:Gem::Version
|
|
73
74
|
version: '3.0'
|
|
74
75
|
type: :development
|
|
75
76
|
prerelease: false
|
|
76
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
77
78
|
requirements:
|
|
78
|
-
- - "
|
|
79
|
+
- - ">="
|
|
79
80
|
- !ruby/object:Gem::Version
|
|
80
81
|
version: '3.0'
|
|
81
82
|
- !ruby/object:Gem::Dependency
|
|
82
83
|
name: rubocop
|
|
83
84
|
requirement: !ruby/object:Gem::Requirement
|
|
84
85
|
requirements:
|
|
85
|
-
- - "
|
|
86
|
+
- - ">="
|
|
86
87
|
- !ruby/object:Gem::Version
|
|
87
88
|
version: '1.21'
|
|
88
89
|
type: :development
|
|
89
90
|
prerelease: false
|
|
90
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
91
92
|
requirements:
|
|
92
|
-
- - "
|
|
93
|
+
- - ">="
|
|
93
94
|
- !ruby/object:Gem::Version
|
|
94
95
|
version: '1.21'
|
|
95
96
|
- !ruby/object:Gem::Dependency
|
|
96
97
|
name: rubocop-rake
|
|
97
98
|
requirement: !ruby/object:Gem::Requirement
|
|
98
99
|
requirements:
|
|
99
|
-
- - "
|
|
100
|
+
- - ">="
|
|
100
101
|
- !ruby/object:Gem::Version
|
|
101
102
|
version: '0.6'
|
|
102
103
|
type: :development
|
|
103
104
|
prerelease: false
|
|
104
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
105
106
|
requirements:
|
|
106
|
-
- - "
|
|
107
|
+
- - ">="
|
|
107
108
|
- !ruby/object:Gem::Version
|
|
108
109
|
version: '0.6'
|
|
109
110
|
- !ruby/object:Gem::Dependency
|
|
110
111
|
name: rubocop-rspec
|
|
111
112
|
requirement: !ruby/object:Gem::Requirement
|
|
112
113
|
requirements:
|
|
113
|
-
- - "
|
|
114
|
+
- - ">="
|
|
114
115
|
- !ruby/object:Gem::Version
|
|
115
116
|
version: '2.25'
|
|
116
117
|
type: :development
|
|
117
118
|
prerelease: false
|
|
118
119
|
version_requirements: !ruby/object:Gem::Requirement
|
|
119
120
|
requirements:
|
|
120
|
-
- - "
|
|
121
|
+
- - ">="
|
|
121
122
|
- !ruby/object:Gem::Version
|
|
122
123
|
version: '2.25'
|
|
123
|
-
description:
|
|
124
124
|
email:
|
|
125
125
|
- wimdenbraven@persuavis.com
|
|
126
126
|
executables: []
|
|
@@ -132,6 +132,7 @@ files:
|
|
|
132
132
|
- ".ruby-version"
|
|
133
133
|
- ".yardopts"
|
|
134
134
|
- CHANGELOG.md
|
|
135
|
+
- CLAUDE.md
|
|
135
136
|
- Gemfile
|
|
136
137
|
- Gemfile.lock
|
|
137
138
|
- LICENSE.txt
|
|
@@ -148,6 +149,7 @@ files:
|
|
|
148
149
|
- lib/bp3/core/rqid.rb
|
|
149
150
|
- lib/bp3/core/settings.rb
|
|
150
151
|
- lib/bp3/core/sqnr.rb
|
|
152
|
+
- lib/bp3/core/system_logs.rb
|
|
151
153
|
- lib/bp3/core/tenantable.rb
|
|
152
154
|
- lib/bp3/core/test.rb
|
|
153
155
|
- lib/bp3/core/version.rb
|
|
@@ -161,7 +163,6 @@ metadata:
|
|
|
161
163
|
source_code_uri: https://github.com/persuavis/bp3-core
|
|
162
164
|
changelog_uri: https://github.com/persuavis/bp3-core/blob/main/CHANGELOG.md
|
|
163
165
|
rubygems_mfa_required: 'true'
|
|
164
|
-
post_install_message:
|
|
165
166
|
rdoc_options: []
|
|
166
167
|
require_paths:
|
|
167
168
|
- lib
|
|
@@ -176,8 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
176
177
|
- !ruby/object:Gem::Version
|
|
177
178
|
version: '0'
|
|
178
179
|
requirements: []
|
|
179
|
-
rubygems_version: 3.
|
|
180
|
-
signing_key:
|
|
180
|
+
rubygems_version: 3.6.9
|
|
181
181
|
specification_version: 4
|
|
182
182
|
summary: bp3-core provides core concerns for BP3 (persuavis/black_phoebe_3).
|
|
183
183
|
test_files: []
|