bp3-string 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +60 -54
- data/bp3-string.gemspec +2 -2
- data/lib/bp3/string/controllerize.rb +1 -1
- data/lib/bp3/string/mapper_base.rb +41 -0
- data/lib/bp3/string/table_controller_map.rb +33 -15
- data/lib/bp3/string/table_model_map.rb +6 -24
- data/lib/bp3/string/version.rb +1 -1
- data/lib/bp3/string.rb +1 -0
- metadata +23 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5aa34697599efbe2157aac9bd6d0d370b808ade7c341c926537a991e6e43b52
|
4
|
+
data.tar.gz: 869be1330e5be8f772c01710137d67c105e2433331122e334df17d707529acd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3368540180a9dd6ced17398086a39cf3d9d6fbf7b508ee999d03defb34609b7f4448a4b8e4edf7ac38d898f18a1158e6d167d75f54265817e9cef800e43da86
|
7
|
+
data.tar.gz: fbd9fa9d774405f4671a9fe42216fedcefe22838390442123ded91de608975a3be869ae71171f17cce419aeaf56b71acea96ceec776e0b2532fa4a3d9d1c64a0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.1.
|
3
|
+
## [0.1.2] - 2024-08-19
|
4
|
+
|
5
|
+
- Use all ActionController descendents to populate the `TableControllerMap` hash.
|
6
|
+
- Pluralize default controller class
|
7
|
+
- Refactoring
|
8
|
+
|
9
|
+
## [0.1.1] - 2024-06-03
|
4
10
|
|
5
11
|
- Tweaks and documentation
|
6
12
|
|
data/Gemfile.lock
CHANGED
@@ -1,80 +1,82 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bp3-string (0.1.
|
5
|
-
activerecord (
|
4
|
+
bp3-string (0.1.2)
|
5
|
+
activerecord (>= 7.1.2, < 8)
|
6
6
|
activesupport (>= 7.1.2, < 8)
|
7
|
-
railties (
|
7
|
+
railties (>= 7.1.2, < 8)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionpack (7.
|
13
|
-
actionview (= 7.
|
14
|
-
activesupport (= 7.
|
12
|
+
actionpack (7.2.0)
|
13
|
+
actionview (= 7.2.0)
|
14
|
+
activesupport (= 7.2.0)
|
15
15
|
nokogiri (>= 1.8.5)
|
16
16
|
racc
|
17
|
-
rack (>= 2.2.4)
|
17
|
+
rack (>= 2.2.4, < 3.2)
|
18
18
|
rack-session (>= 1.0.1)
|
19
19
|
rack-test (>= 0.6.3)
|
20
20
|
rails-dom-testing (~> 2.2)
|
21
21
|
rails-html-sanitizer (~> 1.6)
|
22
|
-
|
23
|
-
|
22
|
+
useragent (~> 0.16)
|
23
|
+
actionview (7.2.0)
|
24
|
+
activesupport (= 7.2.0)
|
24
25
|
builder (~> 3.1)
|
25
26
|
erubi (~> 1.11)
|
26
27
|
rails-dom-testing (~> 2.2)
|
27
28
|
rails-html-sanitizer (~> 1.6)
|
28
|
-
activemodel (7.
|
29
|
-
activesupport (= 7.
|
30
|
-
activerecord (7.
|
31
|
-
activemodel (= 7.
|
32
|
-
activesupport (= 7.
|
29
|
+
activemodel (7.2.0)
|
30
|
+
activesupport (= 7.2.0)
|
31
|
+
activerecord (7.2.0)
|
32
|
+
activemodel (= 7.2.0)
|
33
|
+
activesupport (= 7.2.0)
|
33
34
|
timeout (>= 0.4.0)
|
34
|
-
activesupport (7.
|
35
|
+
activesupport (7.2.0)
|
35
36
|
base64
|
36
37
|
bigdecimal
|
37
|
-
concurrent-ruby (~> 1.0, >= 1.
|
38
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
38
39
|
connection_pool (>= 2.2.5)
|
39
40
|
drb
|
40
41
|
i18n (>= 1.6, < 2)
|
42
|
+
logger (>= 1.4.2)
|
41
43
|
minitest (>= 5.1)
|
42
|
-
|
43
|
-
tzinfo (~> 2.0)
|
44
|
+
securerandom (>= 0.3)
|
45
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
44
46
|
ast (2.4.2)
|
45
47
|
base64 (0.2.0)
|
46
|
-
bigdecimal (3.1.
|
47
|
-
builder (3.
|
48
|
+
bigdecimal (3.1.8)
|
49
|
+
builder (3.3.0)
|
48
50
|
byebug (11.1.3)
|
49
|
-
concurrent-ruby (1.
|
51
|
+
concurrent-ruby (1.3.4)
|
50
52
|
connection_pool (2.4.1)
|
51
53
|
crass (1.0.6)
|
52
54
|
diff-lcs (1.5.1)
|
53
55
|
drb (2.2.1)
|
54
|
-
erubi (1.
|
55
|
-
i18n (1.14.
|
56
|
+
erubi (1.13.0)
|
57
|
+
i18n (1.14.5)
|
56
58
|
concurrent-ruby (~> 1.0)
|
57
59
|
io-console (0.7.2)
|
58
|
-
irb (1.
|
59
|
-
rdoc
|
60
|
+
irb (1.14.0)
|
61
|
+
rdoc (>= 4.0.0)
|
60
62
|
reline (>= 0.4.2)
|
61
63
|
json (2.7.2)
|
62
64
|
language_server-protocol (3.17.0.3)
|
65
|
+
logger (1.6.0)
|
63
66
|
loofah (2.22.0)
|
64
67
|
crass (~> 1.0.2)
|
65
68
|
nokogiri (>= 1.12.0)
|
66
|
-
minitest (5.
|
67
|
-
|
68
|
-
nokogiri (1.16.3-x86_64-darwin)
|
69
|
+
minitest (5.25.1)
|
70
|
+
nokogiri (1.16.7-x86_64-darwin)
|
69
71
|
racc (~> 1.4)
|
70
|
-
parallel (1.
|
71
|
-
parser (3.3.
|
72
|
+
parallel (1.26.3)
|
73
|
+
parser (3.3.4.2)
|
72
74
|
ast (~> 2.4.1)
|
73
75
|
racc
|
74
76
|
psych (5.1.2)
|
75
77
|
stringio
|
76
|
-
racc (1.
|
77
|
-
rack (3.
|
78
|
+
racc (1.8.1)
|
79
|
+
rack (3.1.7)
|
78
80
|
rack-session (2.0.0)
|
79
81
|
rack (>= 3.0.0)
|
80
82
|
rack-test (2.1.0)
|
@@ -89,70 +91,74 @@ GEM
|
|
89
91
|
rails-html-sanitizer (1.6.0)
|
90
92
|
loofah (~> 2.21)
|
91
93
|
nokogiri (~> 1.14)
|
92
|
-
railties (7.
|
93
|
-
actionpack (= 7.
|
94
|
-
activesupport (= 7.
|
95
|
-
irb
|
94
|
+
railties (7.2.0)
|
95
|
+
actionpack (= 7.2.0)
|
96
|
+
activesupport (= 7.2.0)
|
97
|
+
irb (~> 1.13)
|
96
98
|
rackup (>= 1.0.0)
|
97
99
|
rake (>= 12.2)
|
98
100
|
thor (~> 1.0, >= 1.2.2)
|
99
101
|
zeitwerk (~> 2.6)
|
100
102
|
rainbow (3.1.1)
|
101
103
|
rake (13.2.1)
|
102
|
-
rdoc (6.
|
104
|
+
rdoc (6.7.0)
|
103
105
|
psych (>= 4.0.0)
|
104
|
-
regexp_parser (2.9.
|
105
|
-
reline (0.5.
|
106
|
+
regexp_parser (2.9.2)
|
107
|
+
reline (0.5.9)
|
106
108
|
io-console (~> 0.5)
|
107
|
-
rexml (3.
|
109
|
+
rexml (3.3.5)
|
110
|
+
strscan
|
108
111
|
rspec (3.13.0)
|
109
112
|
rspec-core (~> 3.13.0)
|
110
113
|
rspec-expectations (~> 3.13.0)
|
111
114
|
rspec-mocks (~> 3.13.0)
|
112
115
|
rspec-core (3.13.0)
|
113
116
|
rspec-support (~> 3.13.0)
|
114
|
-
rspec-expectations (3.13.
|
117
|
+
rspec-expectations (3.13.2)
|
115
118
|
diff-lcs (>= 1.2.0, < 2.0)
|
116
119
|
rspec-support (~> 3.13.0)
|
117
|
-
rspec-mocks (3.13.
|
120
|
+
rspec-mocks (3.13.1)
|
118
121
|
diff-lcs (>= 1.2.0, < 2.0)
|
119
122
|
rspec-support (~> 3.13.0)
|
120
123
|
rspec-support (3.13.1)
|
121
|
-
rubocop (1.
|
124
|
+
rubocop (1.65.1)
|
122
125
|
json (~> 2.3)
|
123
126
|
language_server-protocol (>= 3.17.0)
|
124
127
|
parallel (~> 1.10)
|
125
128
|
parser (>= 3.3.0.2)
|
126
129
|
rainbow (>= 2.2.2, < 4.0)
|
127
|
-
regexp_parser (>=
|
130
|
+
regexp_parser (>= 2.4, < 3.0)
|
128
131
|
rexml (>= 3.2.5, < 4.0)
|
129
132
|
rubocop-ast (>= 1.31.1, < 2.0)
|
130
133
|
ruby-progressbar (~> 1.7)
|
131
134
|
unicode-display_width (>= 2.4.0, < 3.0)
|
132
|
-
rubocop-ast (1.
|
133
|
-
parser (>= 3.3.0
|
134
|
-
rubocop-capybara (2.
|
135
|
-
rubocop (~> 1.41)
|
136
|
-
rubocop-factory_bot (2.25.1)
|
135
|
+
rubocop-ast (1.32.1)
|
136
|
+
parser (>= 3.3.1.0)
|
137
|
+
rubocop-capybara (2.21.0)
|
137
138
|
rubocop (~> 1.41)
|
139
|
+
rubocop-factory_bot (2.26.1)
|
140
|
+
rubocop (~> 1.61)
|
138
141
|
rubocop-rake (0.6.0)
|
139
142
|
rubocop (~> 1.0)
|
140
|
-
rubocop-rspec (2.
|
143
|
+
rubocop-rspec (2.31.0)
|
141
144
|
rubocop (~> 1.40)
|
142
145
|
rubocop-capybara (~> 2.17)
|
143
146
|
rubocop-factory_bot (~> 2.22)
|
144
147
|
rubocop-rspec_rails (~> 2.28)
|
145
|
-
rubocop-rspec_rails (2.
|
146
|
-
rubocop (~> 1.
|
148
|
+
rubocop-rspec_rails (2.29.1)
|
149
|
+
rubocop (~> 1.61)
|
147
150
|
ruby-progressbar (1.13.0)
|
148
|
-
|
151
|
+
securerandom (0.3.1)
|
152
|
+
stringio (3.1.1)
|
153
|
+
strscan (3.1.0)
|
149
154
|
thor (1.3.1)
|
150
155
|
timeout (0.4.1)
|
151
156
|
tzinfo (2.0.6)
|
152
157
|
concurrent-ruby (~> 1.0)
|
153
158
|
unicode-display_width (2.5.0)
|
159
|
+
useragent (0.16.10)
|
154
160
|
webrick (1.8.1)
|
155
|
-
zeitwerk (2.6.
|
161
|
+
zeitwerk (2.6.17)
|
156
162
|
|
157
163
|
PLATFORMS
|
158
164
|
x86_64-darwin-22
|
data/bp3-string.gemspec
CHANGED
@@ -31,9 +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 'activerecord', '
|
34
|
+
spec.add_dependency 'activerecord', ['>= 7.1.2', '< 8']
|
35
35
|
spec.add_dependency 'activesupport', ['>= 7.1.2', '< 8']
|
36
|
-
spec.add_dependency 'railties', '
|
36
|
+
spec.add_dependency 'railties', ['>= 7.1.2', '< 8']
|
37
37
|
|
38
38
|
spec.add_development_dependency 'byebug'
|
39
39
|
spec.add_development_dependency 'rake', '~> 13.0'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bp3
|
4
|
+
module String
|
5
|
+
# MapperBase provides the base class for controller and model mappings
|
6
|
+
class MapperBase
|
7
|
+
include Subclassable
|
8
|
+
|
9
|
+
# override in testing if needed
|
10
|
+
def self.testing?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.reset_cached_hash
|
15
|
+
@cached_hash = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.build_hash
|
19
|
+
new.build_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.hash
|
23
|
+
cached_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def hash
|
27
|
+
self.class.hash
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def sti_subclass?(model)
|
33
|
+
self.class.sti_subclass?(model)
|
34
|
+
end
|
35
|
+
|
36
|
+
def subclassed?(model)
|
37
|
+
self.class.subclassed?(model)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -2,17 +2,11 @@
|
|
2
2
|
|
3
3
|
module Bp3
|
4
4
|
module String
|
5
|
-
# TableControllerMap provides for mappings between
|
6
|
-
class TableControllerMap
|
7
|
-
include Subclassable
|
8
|
-
|
5
|
+
# TableControllerMap provides for mappings between table-like strings and controller class names
|
6
|
+
class TableControllerMap < MapperBase
|
9
7
|
@cached_hash = nil
|
10
8
|
CACHED_HASH_MUTEX = Mutex.new
|
11
9
|
|
12
|
-
def self.testing?
|
13
|
-
Rails.env.test?
|
14
|
-
end
|
15
|
-
|
16
10
|
def self.cached_hash
|
17
11
|
return build_hash if testing?
|
18
12
|
return @cached_hash if @cached_hash.present?
|
@@ -24,11 +18,18 @@ module Bp3
|
|
24
18
|
end
|
25
19
|
end
|
26
20
|
|
27
|
-
def
|
28
|
-
@
|
21
|
+
def build_hash
|
22
|
+
@encoding = 'string'.encoding # TODO: not sure why encoding sometimes doesn't match
|
23
|
+
@ar_hash = build_hash_from_active_record
|
24
|
+
@ac_hash = build_hash_from_action_controller
|
25
|
+
@ar_hash.merge(@ac_hash)
|
29
26
|
end
|
30
27
|
|
31
|
-
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :ar_hash, :ac_hash, :encoding
|
31
|
+
|
32
|
+
def build_hash_from_active_record
|
32
33
|
hash = {}
|
33
34
|
ActiveRecord::Base.descendants.each do |model|
|
34
35
|
table_name = model.table_name
|
@@ -42,12 +43,29 @@ module Bp3
|
|
42
43
|
hash
|
43
44
|
end
|
44
45
|
|
45
|
-
def
|
46
|
-
|
46
|
+
def build_hash_from_action_controller
|
47
|
+
hash = {}
|
48
|
+
ActionController::Base.descendants.each do |controller|
|
49
|
+
hash.merge!(build_hash_from_controller(controller))
|
50
|
+
end
|
51
|
+
hash
|
47
52
|
end
|
48
53
|
|
49
|
-
def
|
50
|
-
|
54
|
+
def build_hash_from_controller(controller)
|
55
|
+
hash = {}
|
56
|
+
if controller.descendants.empty?
|
57
|
+
if controller.name.present?
|
58
|
+
controller_name = controller.name.encode(encoding)
|
59
|
+
tableish_name = controller_name.gsub(/Controller\z/, '').underscore.tr('/', '_').pluralize
|
60
|
+
hash[tableish_name] = controller_name unless @ar_hash.key?(tableish_name)
|
61
|
+
hash[tableish_name.singularize] = controller_name unless @ar_hash.key?(tableish_name.singularize)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
controller.descendants.each do |ctrlr|
|
65
|
+
hash.merge!(build_hash_from_controller(ctrlr))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
hash
|
51
69
|
end
|
52
70
|
end
|
53
71
|
end
|
@@ -4,17 +4,11 @@ require 'active_record'
|
|
4
4
|
|
5
5
|
module Bp3
|
6
6
|
module String
|
7
|
-
# TableModelMap provides for mappings between tables and
|
8
|
-
class TableModelMap
|
9
|
-
include Subclassable
|
10
|
-
|
7
|
+
# TableModelMap provides for mappings between tables and model class names
|
8
|
+
class TableModelMap < MapperBase
|
11
9
|
@cached_hash = nil
|
12
10
|
CACHED_HASH_MUTEX = Mutex.new
|
13
11
|
|
14
|
-
def self.testing?
|
15
|
-
Rails.env.test?
|
16
|
-
end
|
17
|
-
|
18
12
|
def self.cached_hash
|
19
13
|
return build_hash if testing?
|
20
14
|
return @cached_hash if @cached_hash.present?
|
@@ -26,39 +20,27 @@ module Bp3
|
|
26
20
|
end
|
27
21
|
end
|
28
22
|
|
29
|
-
def
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.build_hash
|
34
|
-
enc = 'string'.encoding # TODO: not sure why encoding sometimes doesn't match
|
23
|
+
def build_hash
|
24
|
+
encoding = 'string'.encoding # TODO: not sure why encoding sometimes doesn't match
|
35
25
|
hash = {}
|
36
26
|
ActiveRecord::Base.descendants.each do |model|
|
37
27
|
table_name = model.table_name
|
38
28
|
next if table_name.blank?
|
39
29
|
|
40
30
|
table_name = table_name.split('.').last # remove the schema
|
41
|
-
model_name = determine_model_name(model).encode(
|
31
|
+
model_name = determine_model_name(model).encode(encoding)
|
42
32
|
hash[table_name] = model_name
|
43
33
|
hash[table_name.singularize] = model_name
|
44
34
|
end
|
45
35
|
hash
|
46
36
|
end
|
47
37
|
|
48
|
-
def
|
38
|
+
def determine_model_name(model)
|
49
39
|
return determine_model_name(model.superclass) if sti_subclass?(model)
|
50
40
|
return determine_model_name(model.descendants.first) if subclassed?(model)
|
51
41
|
|
52
42
|
model.name
|
53
43
|
end
|
54
|
-
|
55
|
-
def self.hash
|
56
|
-
cached_hash
|
57
|
-
end
|
58
|
-
|
59
|
-
def hash
|
60
|
-
self.class.hash
|
61
|
-
end
|
62
44
|
end
|
63
45
|
end
|
64
46
|
end
|
data/lib/bp3/string/version.rb
CHANGED
data/lib/bp3/string.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bp3-string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wim den Braven
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.1.2
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '8'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 7.1.2
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '8'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: activesupport
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,16 +54,22 @@ dependencies:
|
|
48
54
|
name: railties
|
49
55
|
requirement: !ruby/object:Gem::Requirement
|
50
56
|
requirements:
|
51
|
-
- - "
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 7.1.2
|
60
|
+
- - "<"
|
52
61
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
62
|
+
version: '8'
|
54
63
|
type: :runtime
|
55
64
|
prerelease: false
|
56
65
|
version_requirements: !ruby/object:Gem::Requirement
|
57
66
|
requirements:
|
58
|
-
- - "
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 7.1.2
|
70
|
+
- - "<"
|
59
71
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
72
|
+
version: '8'
|
61
73
|
- !ruby/object:Gem::Dependency
|
62
74
|
name: byebug
|
63
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,6 +174,7 @@ files:
|
|
162
174
|
- lib/bp3-string.rb
|
163
175
|
- lib/bp3/string.rb
|
164
176
|
- lib/bp3/string/controllerize.rb
|
177
|
+
- lib/bp3/string/mapper_base.rb
|
165
178
|
- lib/bp3/string/modelize.rb
|
166
179
|
- lib/bp3/string/railtie.rb
|
167
180
|
- lib/bp3/string/subclassable.rb
|