carioca 2.1.3 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,104 +1,103 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # base Carioca namespace
4
4
  module Carioca
5
-
6
- module Services
7
-
8
- # Exiter namespace
9
- class Toolbox
10
-
11
- def self.describe
12
- result = {}
13
- self.methods(false).each do |meth|
14
- next if meth == :describe
15
- result[meth] = self.send meth, **{describe: true}
16
- end
17
- return result
18
- end
5
+ module Services
6
+ # Exiter namespace
7
+ class Toolbox
8
+ def self.describe
9
+ result = {}
10
+ methods(false).each do |meth|
11
+ next if meth == :describe
19
12
 
20
- # return the 'root' name
21
- # @return [String] name
22
- def self.user_root(description: "Get the local system root username ", describe: false)
23
- return description if describe
24
- return Etc.getpwuid(0).name
25
- end
26
-
27
- # return the 'root' group name : root or wheel
28
- # @return [String] name
29
- def self.group_root(description: "Get the local system root groupname ", describe: false)
30
- return description if describe
31
- return Etc.getgrgid(0).name
32
- end
33
-
34
- # facility for retreiving PID from process query
35
- # @option [String] :pattern a regexp to search
36
- # @option [Array] :patterns an array of regexp to search
37
- # @option [Bool] :full flag to retrieve all process data not only PID
38
- # @return [String|Array] PID or data structure
39
- def self.get_processes(patterns: [], pattern: nil, full: false, description: "Get the list of running processus", describe: false)
40
- return description if describe
41
- patterns << pattern if pattern
42
- res = ::PS.get_all_processes
43
- patterns.each do |item|
44
- res = res.find_processes item
45
- end
46
- if full then
47
- return res
48
- else
49
- return res.pick_attr('PID')
50
- end
51
- end
52
-
53
-
54
- # facility to find a file in gem path
55
- # @param [String] _gem a Gem name
56
- # @param [String] _file a file relative path in the gem
57
- # @return [String] the path of the file, if found.
58
- # @return [False] if not found
59
- def self.search_file_in_gem(_gem=nil,_file=nil, description: "Retrieve absolute path of a file in a specific gem", describe: false)
60
- return description if describe
61
- if Gem::Specification.respond_to?(:find_by_name)
62
- begin
63
- spec = Gem::Specification.find_by_name(_gem)
64
- rescue LoadError
65
- spec = nil
66
- end
67
- else
68
- spec = Gem.searcher.find(_gem)
69
- end
70
- if spec then
71
- if Gem::Specification.respond_to?(:find_by_name)
72
- res = spec.lib_dirs_glob.split('/')
73
- else
74
- res = Gem.searcher.lib_dirs_for(spec).split('/')
75
- end
76
- res.pop
77
- services_path = res.join('/').concat("/#{_file}")
78
- return services_path if File::exist?(services_path)
79
- return false
13
+ result[meth] = send meth, describe: true
14
+ end
15
+ result
16
+ end
17
+
18
+ # return the 'root' name
19
+ # @return [String] name
20
+ def self.user_root(description: 'Get the local system root username ', describe: false)
21
+ return description if describe
22
+
23
+ Etc.getpwuid(0).name
24
+ end
25
+
26
+ # return the 'root' group name : root or wheel
27
+ # @return [String] name
28
+ def self.group_root(description: 'Get the local system root groupname ', describe: false)
29
+ return description if describe
30
+
31
+ Etc.getgrgid(0).name
32
+ end
33
+
34
+ # facility for retreiving PID from process query
35
+ # @option [String] :pattern a regexp to search
36
+ # @option [Array] :patterns an array of regexp to search
37
+ # @option [Bool] :full flag to retrieve all process data not only PID
38
+ # @return [String|Array] PID or data structure
39
+ def self.get_processes(patterns: [], pattern: nil, full: false, description: 'Get the list of running processus', describe: false)
40
+ return description if describe
41
+
42
+ patterns << pattern if pattern
43
+ res = ::PS.get_all_processes
44
+ patterns.each do |item|
45
+ res = res.find_processes item
46
+ end
47
+ if full
48
+ res
49
+ else
50
+ res.pick_attr('PID')
51
+ end
52
+ end
53
+
54
+ # facility to find a file in gem path
55
+ # @param [String] _gem a Gem name
56
+ # @param [String] _file a file relative path in the gem
57
+ # @return [String] the path of the file, if found.
58
+ # @return [False] if not found
59
+ def self.search_file_in_gem(gem: nil, file: nil, description: 'Retrieve absolute path of a file in a specific gem', describe: false)
60
+ return description if describe
61
+
62
+ if Gem::Specification.respond_to?(:find_by_name)
63
+ begin
64
+ spec = Gem::Specification.find_by_name(gem)
65
+ rescue LoadError
66
+ spec = nil
67
+ end
68
+ else
69
+ spec = Gem.searcher.find(gem)
70
+ end
71
+ if spec
72
+ res = if Gem::Specification.respond_to?(:find_by_name)
73
+ spec.lib_dirs_glob.split('/')
80
74
  else
81
- return false
75
+ Gem.searcher.lib_dirs_for(spec).split('/')
82
76
  end
83
- end
84
-
85
-
86
-
87
- # facility to verifying if the active process run as root
88
- # @return [Bool] status
89
- def self.is_root?(description: "Verify if active current processus is running as root", describe: false)
90
- return description if describe
91
- return Process.uid == 0
92
- end
77
+ res.pop
78
+ services_path = res.join('/').concat("/#{file}")
79
+ return services_path if File.exist?(services_path)
93
80
 
94
- # check if unicode must be used with term ENV
95
- # @return [Boolean]
96
- def self.check_unicode_term(description: "Check if terminal support unicode", describe: false)
97
- return description if describe
98
- return false unless ENV.include? "TERM"
99
- return (ENV.values_at("LC_ALL","LC_CTYPE","LANG").compact.include?("UTF-8") and ENV.values_at('TERM').include? "xterm")
100
- end
101
-
102
81
  end
82
+ false
83
+ end
84
+
85
+ # facility to verifying if the active process run as root
86
+ # @return [Bool] status
87
+ def self.root?(description: 'Verify if active current processus is running as root', describe: false)
88
+ return description if describe
89
+
90
+ Process.uid.zero?
91
+ end
92
+
93
+ # check if unicode must be used with term ENV
94
+ # @return [Boolean]
95
+ def self.check_unicode_term(description: 'Check if terminal support unicode', describe: false)
96
+ return description if describe
97
+ return false unless ENV.include? 'TERM'
98
+
99
+ (ENV.values_at('LC_ALL', 'LC_CTYPE', 'LANG').compact.include?('UTF-8') and ENV.values_at('TERM').include? 'xterm')
100
+ end
103
101
  end
102
+ end
104
103
  end
data/samples/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'carioca', '~> 2.1'
6
+
7
+ gem 'uuid', '~> 2.3'
data/samples/test.rb CHANGED
@@ -47,7 +47,6 @@ spec = {
47
47
  type: :internal
48
48
  }
49
49
 
50
-
51
50
  puts "\nTest 1 : access to registry : adding a internal service MyService"
52
51
  Carioca::Registry.init.add service: :myservice, definition: spec
53
52
 
@@ -55,24 +54,21 @@ puts "\nTest 2 : list of avaible services : MyService include"
55
54
  logger = Carioca::Registry.get.get_service name: :logger
56
55
  logger.info(to_s) { "Available services : #{Carioca::Registry.get.services.keys} " }
57
56
 
58
-
59
57
  puts "\nTest 3 : using MyService "
60
58
  myservice = Carioca::Registry.get.get_service name: :myservice
61
59
  myservice.hello
62
60
 
63
-
64
-
65
61
  puts "\nTest 4 : Service I18n test :es, :fr, come back :en vi service output"
66
62
  i18n = Carioca::Registry.get.get_service name: :i18n
67
63
  output = Carioca::Registry.get.get_service name: :output
68
- [:es,:fr,:en].each do |locale|
64
+ %i[es fr en].each do |locale|
69
65
  i18n.locale = locale
70
66
  output.item i18n.t(:test)
71
67
  end
72
68
 
73
69
  puts "\nTest 5 : Service I18n test fallback :en on local :es for missing :es locale"
74
70
  i18n.locale = :es
75
- output.item i18n.t(:fallback)
71
+ output.item i18n.t(:fallback)
76
72
  i18n.locale = :en
77
73
 
78
74
  puts "\nTest 5 : Service Configuration test merge runtime form config file"
@@ -80,7 +76,6 @@ config = Carioca::Registry.get.get_service name: :configuration
80
76
  pp config.settings.to_h
81
77
  config.settings.newkey = 'value'
82
78
 
83
-
84
79
  # template override sample
85
80
  class MyAppli < Carioca::Container
86
81
  def test
@@ -98,21 +93,21 @@ class MyAppli < Carioca::Container
98
93
  def test2
99
94
  cycle = %i[unknown fatal error ko warn info item arrow scheduling trigger sending calling receive
100
95
  ok success debug flat]
101
- puts "*** color and Emoji"
96
+ puts '*** color and Emoji'
102
97
  cycle.each do |verb|
103
98
  output.send verb, verb.to_s
104
99
  end
105
- puts "*** no-color and Emoji"
100
+ puts '*** no-color and Emoji'
106
101
  output.color = false
107
102
  cycle.each do |verb|
108
103
  output.send verb, verb.to_s
109
104
  end
110
- puts "*** no-color and no-Emoji"
105
+ puts '*** no-color and no-Emoji'
111
106
  output.emoji = false
112
107
  cycle.each do |verb|
113
108
  output.send verb, verb.to_s
114
109
  end
115
- puts "*** color and no-Emoji"
110
+ puts '*** color and no-Emoji'
116
111
  output.color = true
117
112
  cycle.each do |verb|
118
113
  output.send verb, verb.to_s
@@ -138,7 +133,7 @@ appli.test3
138
133
  output.emoji = true
139
134
  output.color = true
140
135
 
141
- puts "\nTest 9 : Service toolbox list of avaibles methodes"
136
+ puts "\nTest 9 : Service toolbox list of availables methodes"
142
137
  toolbox = Carioca::Registry.get.get_service name: :toolbox
143
138
  pp toolbox.describe
144
139
 
@@ -146,7 +141,7 @@ puts "\nTest 10 : Service toolbox test of simple methode : :user_root"
146
141
  pp toolbox.user_root
147
142
 
148
143
  puts "\nTest 11 : Service toolbox test of simple methode : :search_file_in_gem"
149
- pp toolbox.search_file_in_gem('carioca','config/locales/en.yml')
144
+ pp toolbox.search_file_in_gem(gem: 'carioca', file: 'config/locales/en.yml')
150
145
 
151
146
  puts "\nTest 12 : Service setup execute setup schema from configuration"
152
147
  setup = Carioca::Registry.get.get_service name: :setup
@@ -157,58 +152,59 @@ sanitycheck = Carioca::Registry.get.get_service name: :sanitycheck
157
152
  sanitycheck.run
158
153
 
159
154
  puts "\nTest 14 : Service SecureStore init or access"
160
- securestore = Carioca::Registry.get.get_service name: :securestore
161
-
155
+ puts 'skipped'
156
+ # securestore = Carioca::Registry.get.get_service name: :securestore
162
157
 
163
158
  puts "\nTest 15 : Service SecureStore getting previous data"
164
- res = (securestore.data.empty?)? "first time" : securestore.data.to_s
165
- output.info res
159
+ # res = (securestore.data.empty?)? "first time" : securestore.data.to_s
160
+ # output.info res
161
+ puts 'skipped'
166
162
 
167
163
  puts "\nTest 16 : Service SecureStore setting new data"
168
- securestore.data[:time] = Time.now
169
- securestore.save!
164
+ # securestore.data[:time] = Time.now
165
+ # securestore.save!
166
+ puts 'skipped'
170
167
 
171
168
  puts "\nTest 17 : Service finisher : test all cases"
172
- output.item "flat api return, no-json, no-structured"
169
+ output.item 'flat api return, no-json, no-structured'
173
170
  finisher = Carioca::Registry.get.get_service name: :finisher
174
- test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
175
- "test"
171
+ test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
172
+ 'test'
176
173
  end
177
174
  puts test
178
175
 
179
- output.item "api return, no-json, no-structured but with secure_raise"
180
- test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
181
- finisher.secure_raise message: "error !", error_case: :status_ko
182
- "test"
183
- end
184
- puts test
185
-
186
- output.item "api return, json, structured but with secure_raise"
187
- test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
188
- finisher.secure_raise message: "error !", error_case: :status_ko
189
- "test"
176
+ output.item 'api return, no-json, no-structured but with secure_raise'
177
+ test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
178
+ finisher.secure_raise message: 'error !', error_case: :status_ko
179
+ 'test'
180
+ end
181
+ puts test
182
+
183
+ output.item 'api return, json, structured but with secure_raise'
184
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
185
+ finisher.secure_raise message: 'error !', error_case: :status_ko
186
+ 'test'
190
187
  end
191
188
  puts test[:status]
192
189
  puts test[:data]
193
190
 
194
- output.item "api return, json, structured"
195
- test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
196
- "test"
191
+ output.item 'api return, json, structured'
192
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
193
+ 'test'
197
194
  end
198
195
  puts test[:status]
199
196
  puts test[:data]
200
197
 
201
-
202
- output.item "api return, json, structured with status=false"
203
- test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true, status: false) do
204
- "test"
198
+ output.item 'api return, json, structured with status=false'
199
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true, status: false) do
200
+ 'test'
205
201
  end
206
202
  puts test
207
203
 
208
204
  puts "\nTest 18 : Service finisher : exit case in success"
209
205
  i18n.locale = :fr
210
- finisher.secure_execute! exit_case: :success_exit do
206
+ finisher.secure_execute! exit_case: :success_exit do
211
207
  puts 'finishing action'
212
- #finisher.secure_raise message: "error !", error_case: :status_ko
208
+ # finisher.secure_raise message: "error !", error_case: :status_ko
213
209
  'message'
214
- end
210
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-06 00:00:00.000000000 Z
11
+ date: 2024-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.23.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundle-audit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: code_statistics
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +178,6 @@ dependencies:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0.1'
167
- - !ruby/object:Gem::Dependency
168
- name: bundle-audit
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: 0.1.0
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: 0.1.0
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: version
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -235,7 +235,6 @@ files:
235
235
  - ".rspec"
236
236
  - ".rubocop.yml"
237
237
  - Gemfile
238
- - Gemfile.lock
239
238
  - LICENSE.txt
240
239
  - README.md
241
240
  - Rakefile
@@ -284,6 +283,7 @@ files:
284
283
  - lib/carioca/services/toolbox.rb
285
284
  - lib/carioca/validator.rb
286
285
  - lib/carioca/version.rb
286
+ - samples/Gemfile
287
287
  - samples/Rakefile
288
288
  - samples/config/carioca.registry
289
289
  - samples/config/locales/en.yml
@@ -308,14 +308,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
308
308
  requirements:
309
309
  - - ">="
310
310
  - !ruby/object:Gem::Version
311
- version: 2.6.0
311
+ version: 3.2.3
312
312
  required_rubygems_version: !ruby/object:Gem::Requirement
313
313
  requirements:
314
314
  - - ">="
315
315
  - !ruby/object:Gem::Version
316
316
  version: '0'
317
317
  requirements: []
318
- rubygems_version: 3.3.5
318
+ rubygems_version: 3.4.19
319
319
  signing_key:
320
320
  specification_version: 4
321
321
  summary: 'Carioca : Container And Registry with Inversion Of Control for your Applications'
data/Gemfile.lock DELETED
@@ -1,132 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- carioca (2.1.0)
5
- deep_merge (~> 1.2)
6
- i18n (~> 1.10)
7
- locale (~> 2.1)
8
- pastel (~> 0.8.0)
9
- ps-ruby (~> 0.0.4)
10
- tty-prompt (~> 0.23.1)
11
- version (~> 1.1)
12
-
13
- GEM
14
- remote: https://rubygems.org/
15
- specs:
16
- ast (2.4.2)
17
- bundle-audit (0.1.0)
18
- bundler-audit
19
- bundler-audit (0.9.1)
20
- bundler (>= 1.2.0, < 3)
21
- thor (~> 1.0)
22
- code_statistics (0.2.13)
23
- concurrent-ruby (1.2.2)
24
- cyclonedx-ruby (1.1.0)
25
- json (~> 2.2)
26
- nokogiri (~> 1.8)
27
- ostruct (~> 0.1)
28
- rest-client (~> 2.0)
29
- deep_merge (1.2.2)
30
- diff-lcs (1.5.0)
31
- domain_name (0.5.20190701)
32
- unf (>= 0.0.5, < 1.0.0)
33
- http-accept (1.7.0)
34
- http-cookie (1.0.5)
35
- domain_name (~> 0.5)
36
- i18n (1.14.1)
37
- concurrent-ruby (~> 1.0)
38
- json (2.6.2)
39
- locale (2.1.3)
40
- mime-types (3.4.1)
41
- mime-types-data (~> 3.2015)
42
- mime-types-data (3.2023.0218.1)
43
- mini_portile2 (2.8.2)
44
- netrc (0.11.0)
45
- nokogiri (1.15.2)
46
- mini_portile2 (~> 2.8.2)
47
- racc (~> 1.4)
48
- nokogiri (1.15.2-arm64-darwin)
49
- racc (~> 1.4)
50
- ostruct (0.5.5)
51
- parallel (1.22.1)
52
- parser (3.1.2.0)
53
- ast (~> 2.4.1)
54
- pastel (0.8.0)
55
- tty-color (~> 0.5)
56
- ps-ruby (0.0.4)
57
- racc (1.7.1)
58
- rainbow (3.1.1)
59
- rake (13.0.6)
60
- regexp_parser (2.5.0)
61
- rest-client (2.1.0)
62
- http-accept (>= 1.7.0, < 2.0)
63
- http-cookie (>= 1.0.2, < 2.0)
64
- mime-types (>= 1.16, < 4.0)
65
- netrc (~> 0.8)
66
- rexml (3.2.5)
67
- rspec (3.9.0)
68
- rspec-core (~> 3.9.0)
69
- rspec-expectations (~> 3.9.0)
70
- rspec-mocks (~> 3.9.0)
71
- rspec-core (3.9.3)
72
- rspec-support (~> 3.9.3)
73
- rspec-expectations (3.9.4)
74
- diff-lcs (>= 1.2.0, < 2.0)
75
- rspec-support (~> 3.9.0)
76
- rspec-mocks (3.9.1)
77
- diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.9.0)
79
- rspec-support (3.9.4)
80
- rubocop (1.32.0)
81
- json (~> 2.3)
82
- parallel (~> 1.10)
83
- parser (>= 3.1.0.0)
84
- rainbow (>= 2.2.2, < 4.0)
85
- regexp_parser (>= 1.8, < 3.0)
86
- rexml (>= 3.2.5, < 4.0)
87
- rubocop-ast (>= 1.19.1, < 2.0)
88
- ruby-progressbar (~> 1.7)
89
- unicode-display_width (>= 1.4.0, < 3.0)
90
- rubocop-ast (1.19.1)
91
- parser (>= 3.1.1.0)
92
- ruby-progressbar (1.11.0)
93
- thor (1.2.2)
94
- tty-color (0.6.0)
95
- tty-cursor (0.7.1)
96
- tty-prompt (0.23.1)
97
- pastel (~> 0.8)
98
- tty-reader (~> 0.8)
99
- tty-reader (0.9.0)
100
- tty-cursor (~> 0.7)
101
- tty-screen (~> 0.8)
102
- wisper (~> 2.0)
103
- tty-screen (0.8.1)
104
- unf (0.1.4)
105
- unf_ext
106
- unf_ext (0.0.8.2)
107
- unicode-display_width (2.2.0)
108
- version (1.1.1)
109
- webrick (1.7.0)
110
- wisper (2.0.1)
111
- yard (0.9.28)
112
- webrick (~> 1.7.0)
113
- yard-rspec (0.1)
114
- yard
115
-
116
- PLATFORMS
117
- arm64-darwin-20
118
- ruby
119
-
120
- DEPENDENCIES
121
- bundle-audit (~> 0.1.0)
122
- carioca!
123
- code_statistics (~> 0.2.13)
124
- cyclonedx-ruby (~> 1.1)
125
- rake (~> 13.0)
126
- rspec (~> 3.0)
127
- rubocop (~> 1.32)
128
- yard (~> 0.9.27)
129
- yard-rspec (~> 0.1)
130
-
131
- BUNDLED WITH
132
- 2.3.24