carioca 2.1.4 → 2.1.6

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.
@@ -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'
@@ -39,7 +39,7 @@
39
39
  :rules:
40
40
  - :test: :verify_file
41
41
  :name: "/tmp/carioca.registry"
42
- :mode: "644"
42
+ :mode: "755"
43
43
  - :test: :verify_folder
44
44
  :name: "/tmp/toto"
45
45
  :mode: "755"
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,15 +133,15 @@ 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
 
145
- puts "\nTest 10 : Service toolbox test of simple methode : :user_root"
140
+ puts "\nTest 10 : Service toolbox test of simple method : :user_root"
146
141
  pp toolbox.user_root
147
142
 
148
- 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')
143
+ puts "\nTest 11 : Service toolbox test of simple method : :search_file_in_gem"
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,58 @@ 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
+ securestore = Carioca::Registry.get.get_service name: :securestore
163
156
 
164
157
  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"
158
+ res = (securestore.data.empty?)? "first time" : securestore.data.to_s
159
+ output.info res
160
+
168
161
 
169
162
  puts "\nTest 16 : Service SecureStore setting new data"
170
- #securestore.data[:time] = Time.now
171
- #securestore.save!
172
- puts "skipped"
163
+ securestore.data[:time] = Time.now.to_s
164
+ securestore.save!
165
+
173
166
 
174
167
  puts "\nTest 17 : Service finisher : test all cases"
175
- output.item "flat api return, no-json, no-structured"
168
+ output.item 'flat api return, no-json, no-structured'
176
169
  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"
170
+ test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
171
+ 'test'
172
+ end
173
+ puts test
174
+
175
+ output.item 'api return, no-json, no-structured but with secure_raise'
176
+ test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
177
+ finisher.secure_raise message: 'error !', error_case: :status_ko
178
+ 'test'
179
179
  end
180
180
  puts test
181
181
 
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"
182
+ output.item 'api return, json, structured but with secure_raise'
183
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
184
+ finisher.secure_raise message: 'error !', error_case: :status_ko
185
+ 'test'
193
186
  end
194
187
  puts test[:status]
195
188
  puts test[:data]
196
189
 
197
- output.item "api return, json, structured"
198
- test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
199
- "test"
190
+ output.item 'api return, json, structured'
191
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
192
+ 'test'
200
193
  end
201
194
  puts test[:status]
202
195
  puts test[:data]
203
196
 
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"
197
+ output.item 'api return, json, structured with status=false'
198
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true, status: false) do
199
+ 'test'
208
200
  end
209
201
  puts test
210
202
 
211
203
  puts "\nTest 18 : Service finisher : exit case in success"
212
204
  i18n.locale = :fr
213
- finisher.secure_execute! exit_case: :success_exit do
205
+ finisher.secure_execute! exit_case: :success_exit do
214
206
  puts 'finishing action'
215
- #finisher.secure_raise message: "error !", error_case: :status_ko
207
+ # finisher.secure_raise message: "error !", error_case: :status_ko
216
208
  'message'
217
209
  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.6
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-17 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
@@ -165,19 +179,19 @@ dependencies:
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0.1'
167
181
  - !ruby/object:Gem::Dependency
168
- name: bundle-audit
182
+ name: diff-lcs
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: 0.1.0
187
+ version: 1.5.1
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: 0.1.0
194
+ version: 1.5.1
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: version
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -308,7 +322,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
308
322
  requirements:
309
323
  - - ">="
310
324
  - !ruby/object:Gem::Version
311
- version: 2.6.0
325
+ version: 3.2.3
312
326
  required_rubygems_version: !ruby/object:Gem::Requirement
313
327
  requirements:
314
328
  - - ">="