carioca 2.1.4 → 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 CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- gem "carioca", "~> 2.1"
5
+ gem 'carioca', '~> 2.1'
4
6
 
5
- gem "uuid", "~> 2.3"
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,61 +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
- puts "skipped"
161
- #securestore = Carioca::Registry.get.get_service name: :securestore
162
-
155
+ puts 'skipped'
156
+ # securestore = Carioca::Registry.get.get_service name: :securestore
163
157
 
164
158
  puts "\nTest 15 : Service SecureStore getting previous data"
165
- #res = (securestore.data.empty?)? "first time" : securestore.data.to_s
166
- #output.info res
167
- puts "skipped"
159
+ # res = (securestore.data.empty?)? "first time" : securestore.data.to_s
160
+ # output.info res
161
+ puts 'skipped'
168
162
 
169
163
  puts "\nTest 16 : Service SecureStore setting new data"
170
- #securestore.data[:time] = Time.now
171
- #securestore.save!
172
- puts "skipped"
164
+ # securestore.data[:time] = Time.now
165
+ # securestore.save!
166
+ puts 'skipped'
173
167
 
174
168
  puts "\nTest 17 : Service finisher : test all cases"
175
- output.item "flat api return, no-json, no-structured"
169
+ output.item 'flat api return, no-json, no-structured'
176
170
  finisher = Carioca::Registry.get.get_service name: :finisher
177
- test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
178
- "test"
171
+ test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
172
+ 'test'
179
173
  end
180
174
  puts test
181
175
 
182
- output.item "api return, no-json, no-structured but with secure_raise"
183
- test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
184
- finisher.secure_raise message: "error !", error_case: :status_ko
185
- "test"
186
- end
187
- puts test
188
-
189
- output.item "api return, json, structured but with secure_raise"
190
- test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
191
- finisher.secure_raise message: "error !", error_case: :status_ko
192
- "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'
193
187
  end
194
188
  puts test[:status]
195
189
  puts test[:data]
196
190
 
197
- output.item "api return, json, structured"
198
- test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
199
- "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'
200
194
  end
201
195
  puts test[:status]
202
196
  puts test[:data]
203
197
 
204
-
205
- output.item "api return, json, structured with status=false"
206
- test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true, status: false) do
207
- "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'
208
201
  end
209
202
  puts test
210
203
 
211
204
  puts "\nTest 18 : Service finisher : exit case in success"
212
205
  i18n.locale = :fr
213
- finisher.secure_execute! exit_case: :success_exit do
206
+ finisher.secure_execute! exit_case: :success_exit do
214
207
  puts 'finishing action'
215
- #finisher.secure_raise message: "error !", error_case: :status_ko
208
+ # finisher.secure_raise message: "error !", error_case: :status_ko
216
209
  'message'
217
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.4
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: 2024-04-15 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
@@ -308,7 +308,7 @@ 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
  - - ">="