bp3-string 0.1.1
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +51 -0
- data/.yardopts +8 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +170 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +12 -0
- data/bp3-string.gemspec +48 -0
- data/lib/bp3/string/controllerize.rb +13 -0
- data/lib/bp3/string/modelize.rb +13 -0
- data/lib/bp3/string/railtie.rb +18 -0
- data/lib/bp3/string/subclassable.rb +34 -0
- data/lib/bp3/string/table_controller_map.rb +54 -0
- data/lib/bp3/string/table_model_map.rb +64 -0
- data/lib/bp3/string/test.rb +10 -0
- data/lib/bp3/string/version.rb +7 -0
- data/lib/bp3/string.rb +15 -0
- data/lib/bp3-string.rb +3 -0
- data/sig/bp3/string.rbs +6 -0
- metadata +201 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0a2a72aa199dac5c0afd601a19d696e3080d47481e667e177c9313ce946811b2
|
|
4
|
+
data.tar.gz: 8bf1ae10f2a4ca108419e2e3b77c0b8a330fbf0549cac06dd3825d0b42eca90e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 15d156f4895fa9340ffdefc5c0b8ba6bda70eb26b9ccec9fd701f26859a075855b3498325930027666a733860cb685a14f949e96b9feb1a6a8b614cb2e11798d
|
|
7
|
+
data.tar.gz: 82d1a3e8952cf9469b153ef92b5c6e75c9133c50625d82bc4767a7efb4d7974e0f71d9ccadbbb0650123000ea277f79893aaaa9c84acc2d2dd02fad88895845e
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rake
|
|
3
|
+
- rubocop-rspec
|
|
4
|
+
- rubocop-capybara
|
|
5
|
+
- rubocop-factory_bot
|
|
6
|
+
|
|
7
|
+
AllCops:
|
|
8
|
+
TargetRubyVersion: 3.2.2
|
|
9
|
+
NewCops: enable
|
|
10
|
+
|
|
11
|
+
Gemspec/DevelopmentDependencies:
|
|
12
|
+
EnforcedStyle: gemspec
|
|
13
|
+
|
|
14
|
+
Lint/ConstantDefinitionInBlock:
|
|
15
|
+
Exclude:
|
|
16
|
+
- lib/bp3/**/railtie.rb
|
|
17
|
+
|
|
18
|
+
Lint/Void:
|
|
19
|
+
Exclude:
|
|
20
|
+
- lib/bp3/**/railtie.rb
|
|
21
|
+
|
|
22
|
+
Metrics/AbcSize:
|
|
23
|
+
Max: 26
|
|
24
|
+
|
|
25
|
+
Metrics/BlockLength:
|
|
26
|
+
Max: 66
|
|
27
|
+
|
|
28
|
+
Metrics/CyclomaticComplexity:
|
|
29
|
+
Max: 10
|
|
30
|
+
|
|
31
|
+
Metrics/MethodLength:
|
|
32
|
+
Max: 15
|
|
33
|
+
|
|
34
|
+
Metrics/ModuleLength:
|
|
35
|
+
Max: 150
|
|
36
|
+
|
|
37
|
+
Metrics/PerceivedComplexity:
|
|
38
|
+
Max: 10
|
|
39
|
+
|
|
40
|
+
Naming/FileName:
|
|
41
|
+
Exclude:
|
|
42
|
+
- lib/bp3-*.rb
|
|
43
|
+
|
|
44
|
+
RSpec/ExampleLength:
|
|
45
|
+
Max: 10
|
|
46
|
+
|
|
47
|
+
RSpec/MultipleExpectations:
|
|
48
|
+
Max: 4
|
|
49
|
+
|
|
50
|
+
Style/Documentation:
|
|
51
|
+
Enabled: false
|
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
bp3-string (0.1.1)
|
|
5
|
+
activerecord (~> 7.1)
|
|
6
|
+
activesupport (>= 7.1.2, < 8)
|
|
7
|
+
railties (~> 7.1)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
actionpack (7.1.3.2)
|
|
13
|
+
actionview (= 7.1.3.2)
|
|
14
|
+
activesupport (= 7.1.3.2)
|
|
15
|
+
nokogiri (>= 1.8.5)
|
|
16
|
+
racc
|
|
17
|
+
rack (>= 2.2.4)
|
|
18
|
+
rack-session (>= 1.0.1)
|
|
19
|
+
rack-test (>= 0.6.3)
|
|
20
|
+
rails-dom-testing (~> 2.2)
|
|
21
|
+
rails-html-sanitizer (~> 1.6)
|
|
22
|
+
actionview (7.1.3.2)
|
|
23
|
+
activesupport (= 7.1.3.2)
|
|
24
|
+
builder (~> 3.1)
|
|
25
|
+
erubi (~> 1.11)
|
|
26
|
+
rails-dom-testing (~> 2.2)
|
|
27
|
+
rails-html-sanitizer (~> 1.6)
|
|
28
|
+
activemodel (7.1.3.2)
|
|
29
|
+
activesupport (= 7.1.3.2)
|
|
30
|
+
activerecord (7.1.3.2)
|
|
31
|
+
activemodel (= 7.1.3.2)
|
|
32
|
+
activesupport (= 7.1.3.2)
|
|
33
|
+
timeout (>= 0.4.0)
|
|
34
|
+
activesupport (7.1.3.2)
|
|
35
|
+
base64
|
|
36
|
+
bigdecimal
|
|
37
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
38
|
+
connection_pool (>= 2.2.5)
|
|
39
|
+
drb
|
|
40
|
+
i18n (>= 1.6, < 2)
|
|
41
|
+
minitest (>= 5.1)
|
|
42
|
+
mutex_m
|
|
43
|
+
tzinfo (~> 2.0)
|
|
44
|
+
ast (2.4.2)
|
|
45
|
+
base64 (0.2.0)
|
|
46
|
+
bigdecimal (3.1.7)
|
|
47
|
+
builder (3.2.4)
|
|
48
|
+
byebug (11.1.3)
|
|
49
|
+
concurrent-ruby (1.2.3)
|
|
50
|
+
connection_pool (2.4.1)
|
|
51
|
+
crass (1.0.6)
|
|
52
|
+
diff-lcs (1.5.1)
|
|
53
|
+
drb (2.2.1)
|
|
54
|
+
erubi (1.12.0)
|
|
55
|
+
i18n (1.14.4)
|
|
56
|
+
concurrent-ruby (~> 1.0)
|
|
57
|
+
io-console (0.7.2)
|
|
58
|
+
irb (1.12.0)
|
|
59
|
+
rdoc
|
|
60
|
+
reline (>= 0.4.2)
|
|
61
|
+
json (2.7.2)
|
|
62
|
+
language_server-protocol (3.17.0.3)
|
|
63
|
+
loofah (2.22.0)
|
|
64
|
+
crass (~> 1.0.2)
|
|
65
|
+
nokogiri (>= 1.12.0)
|
|
66
|
+
minitest (5.22.3)
|
|
67
|
+
mutex_m (0.2.0)
|
|
68
|
+
nokogiri (1.16.3-x86_64-darwin)
|
|
69
|
+
racc (~> 1.4)
|
|
70
|
+
parallel (1.24.0)
|
|
71
|
+
parser (3.3.0.5)
|
|
72
|
+
ast (~> 2.4.1)
|
|
73
|
+
racc
|
|
74
|
+
psych (5.1.2)
|
|
75
|
+
stringio
|
|
76
|
+
racc (1.7.3)
|
|
77
|
+
rack (3.0.10)
|
|
78
|
+
rack-session (2.0.0)
|
|
79
|
+
rack (>= 3.0.0)
|
|
80
|
+
rack-test (2.1.0)
|
|
81
|
+
rack (>= 1.3)
|
|
82
|
+
rackup (2.1.0)
|
|
83
|
+
rack (>= 3)
|
|
84
|
+
webrick (~> 1.8)
|
|
85
|
+
rails-dom-testing (2.2.0)
|
|
86
|
+
activesupport (>= 5.0.0)
|
|
87
|
+
minitest
|
|
88
|
+
nokogiri (>= 1.6)
|
|
89
|
+
rails-html-sanitizer (1.6.0)
|
|
90
|
+
loofah (~> 2.21)
|
|
91
|
+
nokogiri (~> 1.14)
|
|
92
|
+
railties (7.1.3.2)
|
|
93
|
+
actionpack (= 7.1.3.2)
|
|
94
|
+
activesupport (= 7.1.3.2)
|
|
95
|
+
irb
|
|
96
|
+
rackup (>= 1.0.0)
|
|
97
|
+
rake (>= 12.2)
|
|
98
|
+
thor (~> 1.0, >= 1.2.2)
|
|
99
|
+
zeitwerk (~> 2.6)
|
|
100
|
+
rainbow (3.1.1)
|
|
101
|
+
rake (13.2.1)
|
|
102
|
+
rdoc (6.6.3.1)
|
|
103
|
+
psych (>= 4.0.0)
|
|
104
|
+
regexp_parser (2.9.0)
|
|
105
|
+
reline (0.5.0)
|
|
106
|
+
io-console (~> 0.5)
|
|
107
|
+
rexml (3.2.6)
|
|
108
|
+
rspec (3.13.0)
|
|
109
|
+
rspec-core (~> 3.13.0)
|
|
110
|
+
rspec-expectations (~> 3.13.0)
|
|
111
|
+
rspec-mocks (~> 3.13.0)
|
|
112
|
+
rspec-core (3.13.0)
|
|
113
|
+
rspec-support (~> 3.13.0)
|
|
114
|
+
rspec-expectations (3.13.0)
|
|
115
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
116
|
+
rspec-support (~> 3.13.0)
|
|
117
|
+
rspec-mocks (3.13.0)
|
|
118
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
119
|
+
rspec-support (~> 3.13.0)
|
|
120
|
+
rspec-support (3.13.1)
|
|
121
|
+
rubocop (1.62.1)
|
|
122
|
+
json (~> 2.3)
|
|
123
|
+
language_server-protocol (>= 3.17.0)
|
|
124
|
+
parallel (~> 1.10)
|
|
125
|
+
parser (>= 3.3.0.2)
|
|
126
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
127
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
128
|
+
rexml (>= 3.2.5, < 4.0)
|
|
129
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
|
130
|
+
ruby-progressbar (~> 1.7)
|
|
131
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
132
|
+
rubocop-ast (1.31.2)
|
|
133
|
+
parser (>= 3.3.0.4)
|
|
134
|
+
rubocop-capybara (2.20.0)
|
|
135
|
+
rubocop (~> 1.41)
|
|
136
|
+
rubocop-factory_bot (2.25.1)
|
|
137
|
+
rubocop (~> 1.41)
|
|
138
|
+
rubocop-rake (0.6.0)
|
|
139
|
+
rubocop (~> 1.0)
|
|
140
|
+
rubocop-rspec (2.29.1)
|
|
141
|
+
rubocop (~> 1.40)
|
|
142
|
+
rubocop-capybara (~> 2.17)
|
|
143
|
+
rubocop-factory_bot (~> 2.22)
|
|
144
|
+
rubocop-rspec_rails (~> 2.28)
|
|
145
|
+
rubocop-rspec_rails (2.28.2)
|
|
146
|
+
rubocop (~> 1.40)
|
|
147
|
+
ruby-progressbar (1.13.0)
|
|
148
|
+
stringio (3.1.0)
|
|
149
|
+
thor (1.3.1)
|
|
150
|
+
timeout (0.4.1)
|
|
151
|
+
tzinfo (2.0.6)
|
|
152
|
+
concurrent-ruby (~> 1.0)
|
|
153
|
+
unicode-display_width (2.5.0)
|
|
154
|
+
webrick (1.8.1)
|
|
155
|
+
zeitwerk (2.6.13)
|
|
156
|
+
|
|
157
|
+
PLATFORMS
|
|
158
|
+
x86_64-darwin-22
|
|
159
|
+
|
|
160
|
+
DEPENDENCIES
|
|
161
|
+
bp3-string!
|
|
162
|
+
byebug
|
|
163
|
+
rake (~> 13.0)
|
|
164
|
+
rspec (~> 3.0)
|
|
165
|
+
rubocop (~> 1.21)
|
|
166
|
+
rubocop-rake (~> 0.6)
|
|
167
|
+
rubocop-rspec (~> 2.25)
|
|
168
|
+
|
|
169
|
+
BUNDLED WITH
|
|
170
|
+
2.5.11
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Wim den Braven
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Bp3::String
|
|
2
|
+
|
|
3
|
+
bp3-string adapts the `String` class for BP3, the persuavis/black_phoebe_3
|
|
4
|
+
multi-site multi-tenant rails application. In particular, it adds the following methods:
|
|
5
|
+
- `#modelize` - Converts a string to its matching model name, taking into account
|
|
6
|
+
that a model may be namespaced
|
|
7
|
+
- `#controllerize` - Converts a string to its matching controller name, taking into account
|
|
8
|
+
that a controller may be namespaced
|
|
9
|
+
|
|
10
|
+
To take namespacing into account, it uses a list of table names and models obtained from the db.
|
|
11
|
+
|
|
12
|
+
For this to work correctly, the app must be eager loaded.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Add this line to your application's Gemfile:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'bp3-string'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
And then execute:
|
|
23
|
+
|
|
24
|
+
$ bundle install
|
|
25
|
+
|
|
26
|
+
Or install it yourself as:
|
|
27
|
+
|
|
28
|
+
$ gem install bp3-string
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
Just add the gem to your BP3 app.
|
|
33
|
+
|
|
34
|
+
## Development
|
|
35
|
+
|
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
37
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
|
38
|
+
prompt that will allow you to experiment.
|
|
39
|
+
|
|
40
|
+
To install this gem onto your local machine, run `rake install`. To release a
|
|
41
|
+
new version, update the version number in `version.rb`, and then run
|
|
42
|
+
`rake release`, which will create a git tag for the version, push git
|
|
43
|
+
commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
44
|
+
|
|
45
|
+
## Testing
|
|
46
|
+
Run `rake` to run rspec tests and rubocop linting.
|
|
47
|
+
|
|
48
|
+
## Documentation
|
|
49
|
+
A `.yardopts` file is provided to support yard documentation.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bp3-string.gemspec
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/bp3/string/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'bp3-string'
|
|
7
|
+
spec.version = Bp3::String::VERSION
|
|
8
|
+
spec.authors = ['Wim den Braven']
|
|
9
|
+
spec.email = ['wimdenbraven@persuavis.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'bp3-string adapts the String class for BP3 (persuavis/black_phoebe_3).'
|
|
12
|
+
# spec.description = "TODO: Write a longer description or delete this line."
|
|
13
|
+
spec.homepage = 'https://www.black-phoebe.com'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.2.0'
|
|
16
|
+
|
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
18
|
+
|
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/persuavis/bp3-string'
|
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/persuavis/bp3-string/blob/main/CHANGELOG.md'
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = 'exe'
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ['lib']
|
|
33
|
+
|
|
34
|
+
spec.add_dependency 'activerecord', '~> 7.1'
|
|
35
|
+
spec.add_dependency 'activesupport', ['>= 7.1.2', '< 8']
|
|
36
|
+
spec.add_dependency 'railties', '~> 7.1'
|
|
37
|
+
|
|
38
|
+
spec.add_development_dependency 'byebug'
|
|
39
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
40
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
41
|
+
spec.add_development_dependency 'rubocop', '~> 1.21'
|
|
42
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.6'
|
|
43
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.25'
|
|
44
|
+
|
|
45
|
+
# For more information and examples about making a new gem, check out our
|
|
46
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
47
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
48
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/railtie'
|
|
4
|
+
|
|
5
|
+
module Bp3
|
|
6
|
+
module String
|
|
7
|
+
class Railtie < Rails::Railtie
|
|
8
|
+
initializer 'bp3.string.railtie.register' do |app|
|
|
9
|
+
app.config.after_initialize do
|
|
10
|
+
class ::String
|
|
11
|
+
include Bp3::String::Modelize
|
|
12
|
+
include Bp3::String::Controllerize
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bp3
|
|
4
|
+
module String
|
|
5
|
+
module Subclassable
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
class_methods do
|
|
9
|
+
# look for any ancestors of *model* that share the same table name *and* the model
|
|
10
|
+
# is an STI model, as determined by the presence of a 'type' column
|
|
11
|
+
def sti_subclass?(model)
|
|
12
|
+
table_name = model.table_name
|
|
13
|
+
model.ancestors[1..].any? do |class_or_module|
|
|
14
|
+
if class_or_module.is_a?(Module) && !class_or_module.is_a?(Class)
|
|
15
|
+
false
|
|
16
|
+
elsif class_or_module.table_name == table_name
|
|
17
|
+
sti_model?(class_or_module)
|
|
18
|
+
end
|
|
19
|
+
rescue StandardError
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def sti_model?(klass)
|
|
25
|
+
klass.columns.map(&:name).any? { |name| name == 'type' }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def subclassed?(model)
|
|
29
|
+
model.descendants.any? && !sti_model?(model)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bp3
|
|
4
|
+
module String
|
|
5
|
+
# TableControllerMap provides for mappings between tables and controllers
|
|
6
|
+
class TableControllerMap
|
|
7
|
+
include Subclassable
|
|
8
|
+
|
|
9
|
+
@cached_hash = nil
|
|
10
|
+
CACHED_HASH_MUTEX = Mutex.new
|
|
11
|
+
|
|
12
|
+
def self.testing?
|
|
13
|
+
Rails.env.test?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.cached_hash
|
|
17
|
+
return build_hash if testing?
|
|
18
|
+
return @cached_hash if @cached_hash.present?
|
|
19
|
+
|
|
20
|
+
CACHED_HASH_MUTEX.synchronize do
|
|
21
|
+
return @cached_hash if @cached_hash.present?
|
|
22
|
+
|
|
23
|
+
@cached_hash = build_hash
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.reset_cached_hash
|
|
28
|
+
@cached_hash = nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.build_hash
|
|
32
|
+
hash = {}
|
|
33
|
+
ActiveRecord::Base.descendants.each do |model|
|
|
34
|
+
table_name = model.table_name
|
|
35
|
+
next if table_name.blank?
|
|
36
|
+
|
|
37
|
+
table_name = model.name.tableize.tr('/', '_') if sti_subclass?(model)
|
|
38
|
+
controller_name = "#{model.name.pluralize}Controller"
|
|
39
|
+
hash[table_name] = controller_name
|
|
40
|
+
hash[table_name.singularize] = controller_name
|
|
41
|
+
end
|
|
42
|
+
hash
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.hash
|
|
46
|
+
cached_hash
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def hash
|
|
50
|
+
self.class.hash
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_record'
|
|
4
|
+
|
|
5
|
+
module Bp3
|
|
6
|
+
module String
|
|
7
|
+
# TableModelMap provides for mappings between tables and models
|
|
8
|
+
class TableModelMap
|
|
9
|
+
include Subclassable
|
|
10
|
+
|
|
11
|
+
@cached_hash = nil
|
|
12
|
+
CACHED_HASH_MUTEX = Mutex.new
|
|
13
|
+
|
|
14
|
+
def self.testing?
|
|
15
|
+
Rails.env.test?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.cached_hash
|
|
19
|
+
return build_hash if testing?
|
|
20
|
+
return @cached_hash if @cached_hash.present?
|
|
21
|
+
|
|
22
|
+
CACHED_HASH_MUTEX.synchronize do
|
|
23
|
+
return @cached_hash if @cached_hash.present?
|
|
24
|
+
|
|
25
|
+
@cached_hash = build_hash
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.reset_cached_hash
|
|
30
|
+
@cached_hash = nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.build_hash
|
|
34
|
+
enc = 'string'.encoding # TODO: not sure why encoding sometimes doesn't match
|
|
35
|
+
hash = {}
|
|
36
|
+
ActiveRecord::Base.descendants.each do |model|
|
|
37
|
+
table_name = model.table_name
|
|
38
|
+
next if table_name.blank?
|
|
39
|
+
|
|
40
|
+
table_name = table_name.split('.').last # remove the schema
|
|
41
|
+
model_name = determine_model_name(model).encode(enc)
|
|
42
|
+
hash[table_name] = model_name
|
|
43
|
+
hash[table_name.singularize] = model_name
|
|
44
|
+
end
|
|
45
|
+
hash
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.determine_model_name(model)
|
|
49
|
+
return determine_model_name(model.superclass) if sti_subclass?(model)
|
|
50
|
+
return determine_model_name(model.descendants.first) if subclassed?(model)
|
|
51
|
+
|
|
52
|
+
model.name
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.hash
|
|
56
|
+
cached_hash
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def hash
|
|
60
|
+
self.class.hash
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/bp3/string.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_support/concern'
|
|
4
|
+
require_relative 'string/subclassable'
|
|
5
|
+
require_relative 'string/table_model_map'
|
|
6
|
+
require_relative 'string/table_controller_map'
|
|
7
|
+
require_relative 'string/modelize'
|
|
8
|
+
require_relative 'string/controllerize'
|
|
9
|
+
require_relative 'string/railtie'
|
|
10
|
+
require_relative 'string/version'
|
|
11
|
+
|
|
12
|
+
module Bp3
|
|
13
|
+
module String
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/bp3-string.rb
ADDED
data/sig/bp3/string.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bp3-string
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Wim den Braven
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-06-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activerecord
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '7.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '7.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activesupport
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 7.1.2
|
|
34
|
+
- - "<"
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '8'
|
|
37
|
+
type: :runtime
|
|
38
|
+
prerelease: false
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 7.1.2
|
|
44
|
+
- - "<"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '8'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: railties
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '7.1'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '7.1'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: byebug
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: rake
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '13.0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '13.0'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: rspec
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '3.0'
|
|
96
|
+
type: :development
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '3.0'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: rubocop
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '1.21'
|
|
110
|
+
type: :development
|
|
111
|
+
prerelease: false
|
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '1.21'
|
|
117
|
+
- !ruby/object:Gem::Dependency
|
|
118
|
+
name: rubocop-rake
|
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0.6'
|
|
124
|
+
type: :development
|
|
125
|
+
prerelease: false
|
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - "~>"
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0.6'
|
|
131
|
+
- !ruby/object:Gem::Dependency
|
|
132
|
+
name: rubocop-rspec
|
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - "~>"
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '2.25'
|
|
138
|
+
type: :development
|
|
139
|
+
prerelease: false
|
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - "~>"
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '2.25'
|
|
145
|
+
description:
|
|
146
|
+
email:
|
|
147
|
+
- wimdenbraven@persuavis.com
|
|
148
|
+
executables: []
|
|
149
|
+
extensions: []
|
|
150
|
+
extra_rdoc_files: []
|
|
151
|
+
files:
|
|
152
|
+
- ".rspec"
|
|
153
|
+
- ".rubocop.yml"
|
|
154
|
+
- ".yardopts"
|
|
155
|
+
- CHANGELOG.md
|
|
156
|
+
- Gemfile
|
|
157
|
+
- Gemfile.lock
|
|
158
|
+
- LICENSE.txt
|
|
159
|
+
- README.md
|
|
160
|
+
- Rakefile
|
|
161
|
+
- bp3-string.gemspec
|
|
162
|
+
- lib/bp3-string.rb
|
|
163
|
+
- lib/bp3/string.rb
|
|
164
|
+
- lib/bp3/string/controllerize.rb
|
|
165
|
+
- lib/bp3/string/modelize.rb
|
|
166
|
+
- lib/bp3/string/railtie.rb
|
|
167
|
+
- lib/bp3/string/subclassable.rb
|
|
168
|
+
- lib/bp3/string/table_controller_map.rb
|
|
169
|
+
- lib/bp3/string/table_model_map.rb
|
|
170
|
+
- lib/bp3/string/test.rb
|
|
171
|
+
- lib/bp3/string/version.rb
|
|
172
|
+
- sig/bp3/string.rbs
|
|
173
|
+
homepage: https://www.black-phoebe.com
|
|
174
|
+
licenses:
|
|
175
|
+
- MIT
|
|
176
|
+
metadata:
|
|
177
|
+
allowed_push_host: https://rubygems.org
|
|
178
|
+
homepage_uri: https://www.black-phoebe.com
|
|
179
|
+
source_code_uri: https://github.com/persuavis/bp3-string
|
|
180
|
+
changelog_uri: https://github.com/persuavis/bp3-string/blob/main/CHANGELOG.md
|
|
181
|
+
rubygems_mfa_required: 'true'
|
|
182
|
+
post_install_message:
|
|
183
|
+
rdoc_options: []
|
|
184
|
+
require_paths:
|
|
185
|
+
- lib
|
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
|
+
requirements:
|
|
188
|
+
- - ">="
|
|
189
|
+
- !ruby/object:Gem::Version
|
|
190
|
+
version: 3.2.0
|
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
|
+
requirements:
|
|
193
|
+
- - ">="
|
|
194
|
+
- !ruby/object:Gem::Version
|
|
195
|
+
version: '0'
|
|
196
|
+
requirements: []
|
|
197
|
+
rubygems_version: 3.5.11
|
|
198
|
+
signing_key:
|
|
199
|
+
specification_version: 4
|
|
200
|
+
summary: bp3-string adapts the String class for BP3 (persuavis/black_phoebe_3).
|
|
201
|
+
test_files: []
|