bp3-core 0.1.5 → 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 -1
- data/.ruby-version +1 -2
- data/CHANGELOG.md +7 -0
- data/CLAUDE.md +98 -0
- data/Gemfile.lock +83 -50
- data/README.md +9 -0
- data/bp3-core.gemspec +3 -2
- 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 +27 -15
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
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,109 +1,142 @@
|
|
|
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 (8.
|
|
28
|
+
activesupport (8.1.2)
|
|
18
29
|
base64
|
|
19
|
-
benchmark (>= 0.3)
|
|
20
30
|
bigdecimal
|
|
21
31
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
22
32
|
connection_pool (>= 2.2.5)
|
|
23
33
|
drb
|
|
24
34
|
i18n (>= 1.6, < 2)
|
|
35
|
+
json
|
|
25
36
|
logger (>= 1.4.2)
|
|
26
37
|
minitest (>= 5.1)
|
|
27
38
|
securerandom (>= 0.3)
|
|
28
39
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
29
40
|
uri (>= 0.13.1)
|
|
30
|
-
ast (2.4.
|
|
31
|
-
base64 (0.
|
|
32
|
-
|
|
33
|
-
|
|
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)
|
|
34
48
|
builder (3.3.0)
|
|
35
|
-
concurrent-ruby (1.3.
|
|
36
|
-
connection_pool (
|
|
49
|
+
concurrent-ruby (1.3.6)
|
|
50
|
+
connection_pool (3.0.2)
|
|
37
51
|
crass (1.0.6)
|
|
38
|
-
diff-lcs (1.
|
|
39
|
-
drb (2.2.
|
|
40
|
-
erubi (1.13.
|
|
41
|
-
i18n (1.14.
|
|
52
|
+
diff-lcs (1.6.2)
|
|
53
|
+
drb (2.2.3)
|
|
54
|
+
erubi (1.13.1)
|
|
55
|
+
i18n (1.14.8)
|
|
42
56
|
concurrent-ruby (~> 1.0)
|
|
43
|
-
json (2.
|
|
44
|
-
language_server-protocol (3.17.0.
|
|
45
|
-
|
|
46
|
-
|
|
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)
|
|
47
62
|
crass (~> 1.0.2)
|
|
48
63
|
nokogiri (>= 1.12.0)
|
|
49
|
-
minitest (
|
|
50
|
-
|
|
64
|
+
minitest (6.0.1)
|
|
65
|
+
prism (~> 1.5)
|
|
66
|
+
nokogiri (1.19.0-x86_64-darwin)
|
|
51
67
|
racc (~> 1.4)
|
|
52
|
-
parallel (1.
|
|
53
|
-
parser (3.3.
|
|
68
|
+
parallel (1.27.0)
|
|
69
|
+
parser (3.3.10.0)
|
|
54
70
|
ast (~> 2.4.1)
|
|
55
71
|
racc
|
|
72
|
+
prism (1.7.0)
|
|
56
73
|
racc (1.8.1)
|
|
57
|
-
|
|
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)
|
|
58
81
|
activesupport (>= 5.0.0)
|
|
59
82
|
minitest
|
|
60
83
|
nokogiri (>= 1.6)
|
|
61
|
-
rails-html-sanitizer (1.6.
|
|
84
|
+
rails-html-sanitizer (1.6.2)
|
|
62
85
|
loofah (~> 2.21)
|
|
63
|
-
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)
|
|
64
87
|
rainbow (3.1.1)
|
|
65
|
-
rake (13.
|
|
66
|
-
regexp_parser (2.
|
|
67
|
-
|
|
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)
|
|
68
93
|
rspec-core (~> 3.13.0)
|
|
69
94
|
rspec-expectations (~> 3.13.0)
|
|
70
95
|
rspec-mocks (~> 3.13.0)
|
|
71
|
-
rspec-core (3.13.
|
|
96
|
+
rspec-core (3.13.6)
|
|
72
97
|
rspec-support (~> 3.13.0)
|
|
73
|
-
rspec-expectations (3.13.
|
|
98
|
+
rspec-expectations (3.13.5)
|
|
74
99
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
75
100
|
rspec-support (~> 3.13.0)
|
|
76
|
-
rspec-mocks (3.13.
|
|
101
|
+
rspec-mocks (3.13.7)
|
|
77
102
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
78
103
|
rspec-support (~> 3.13.0)
|
|
79
|
-
rspec-support (3.13.
|
|
80
|
-
rubocop (1.
|
|
104
|
+
rspec-support (3.13.6)
|
|
105
|
+
rubocop (1.82.1)
|
|
81
106
|
json (~> 2.3)
|
|
82
|
-
language_server-protocol (
|
|
107
|
+
language_server-protocol (~> 3.17.0.2)
|
|
108
|
+
lint_roller (~> 1.1.0)
|
|
83
109
|
parallel (~> 1.10)
|
|
84
110
|
parser (>= 3.3.0.2)
|
|
85
111
|
rainbow (>= 2.2.2, < 4.0)
|
|
86
|
-
regexp_parser (>= 2.
|
|
87
|
-
rubocop-ast (>= 1.
|
|
112
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
113
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
88
114
|
ruby-progressbar (~> 1.7)
|
|
89
|
-
unicode-display_width (>= 2.4.0, <
|
|
90
|
-
rubocop-ast (1.
|
|
91
|
-
parser (>= 3.3.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
rubocop (
|
|
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)
|
|
96
125
|
ruby-progressbar (1.13.0)
|
|
97
|
-
securerandom (0.
|
|
126
|
+
securerandom (0.4.1)
|
|
98
127
|
tzinfo (2.0.6)
|
|
99
128
|
concurrent-ruby (~> 1.0)
|
|
100
|
-
unicode-display_width (2.
|
|
101
|
-
|
|
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)
|
|
102
134
|
|
|
103
135
|
PLATFORMS
|
|
104
136
|
x86_64-darwin-21
|
|
105
137
|
x86_64-darwin-22
|
|
106
138
|
x86_64-darwin-23
|
|
139
|
+
x86_64-darwin-24
|
|
107
140
|
|
|
108
141
|
DEPENDENCIES
|
|
109
142
|
bp3-core!
|
|
@@ -114,4 +147,4 @@ DEPENDENCIES
|
|
|
114
147
|
rubocop-rspec (>= 2.25)
|
|
115
148
|
|
|
116
149
|
BUNDLED WITH
|
|
117
|
-
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/bp3-core.gemspec
CHANGED
|
@@ -31,8 +31,9 @@ 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', '
|
|
34
|
+
spec.add_dependency 'actionview', '~> 8.1'
|
|
35
|
+
spec.add_dependency 'activesupport', '~> 8.1'
|
|
36
|
+
spec.add_dependency 'bp3-request_state', '~> 0.1'
|
|
36
37
|
|
|
37
38
|
spec.add_development_dependency 'rake', '>= 13.0'
|
|
38
39
|
spec.add_development_dependency 'rspec', '>= 3.0'
|
|
@@ -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,43 +1,56 @@
|
|
|
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
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
18
|
+
version: '8.1'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
25
|
+
version: '8.1'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: activesupport
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
32
|
+
version: '8.1'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
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
|
+
- - "~>"
|
|
39
52
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
53
|
+
version: '0.1'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
55
|
name: rake
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -108,7 +121,6 @@ dependencies:
|
|
|
108
121
|
- - ">="
|
|
109
122
|
- !ruby/object:Gem::Version
|
|
110
123
|
version: '2.25'
|
|
111
|
-
description:
|
|
112
124
|
email:
|
|
113
125
|
- wimdenbraven@persuavis.com
|
|
114
126
|
executables: []
|
|
@@ -120,6 +132,7 @@ files:
|
|
|
120
132
|
- ".ruby-version"
|
|
121
133
|
- ".yardopts"
|
|
122
134
|
- CHANGELOG.md
|
|
135
|
+
- CLAUDE.md
|
|
123
136
|
- Gemfile
|
|
124
137
|
- Gemfile.lock
|
|
125
138
|
- LICENSE.txt
|
|
@@ -136,6 +149,7 @@ files:
|
|
|
136
149
|
- lib/bp3/core/rqid.rb
|
|
137
150
|
- lib/bp3/core/settings.rb
|
|
138
151
|
- lib/bp3/core/sqnr.rb
|
|
152
|
+
- lib/bp3/core/system_logs.rb
|
|
139
153
|
- lib/bp3/core/tenantable.rb
|
|
140
154
|
- lib/bp3/core/test.rb
|
|
141
155
|
- lib/bp3/core/version.rb
|
|
@@ -149,7 +163,6 @@ metadata:
|
|
|
149
163
|
source_code_uri: https://github.com/persuavis/bp3-core
|
|
150
164
|
changelog_uri: https://github.com/persuavis/bp3-core/blob/main/CHANGELOG.md
|
|
151
165
|
rubygems_mfa_required: 'true'
|
|
152
|
-
post_install_message:
|
|
153
166
|
rdoc_options: []
|
|
154
167
|
require_paths:
|
|
155
168
|
- lib
|
|
@@ -164,8 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
164
177
|
- !ruby/object:Gem::Version
|
|
165
178
|
version: '0'
|
|
166
179
|
requirements: []
|
|
167
|
-
rubygems_version: 3.
|
|
168
|
-
signing_key:
|
|
180
|
+
rubygems_version: 3.6.9
|
|
169
181
|
specification_version: 4
|
|
170
182
|
summary: bp3-core provides core concerns for BP3 (persuavis/black_phoebe_3).
|
|
171
183
|
test_files: []
|