carioca 2.1.3 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99e25d909400997565234d097e571a9600cca99dca0880e493ea74a6547573ae
4
- data.tar.gz: 6c3f581e92b5e9e2f6e91f9f466f2d22ec462ef20ca6799eb1a0304d039a44b6
3
+ metadata.gz: c4324ecafd951108c6d1dc26540f0e2012b6aa5a7fc4aa903caf9c90bb8bd73d
4
+ data.tar.gz: 33950a1b11ecab8b65ca060ab12d8c282379a3d01d737ad02bc877067f219895
5
5
  SHA512:
6
- metadata.gz: b9f9bda2f074633447842b10c9cde5ffdf8c157fc9a3e78398b7a70311425b5a2ce8243ef685b03333b9be850d1103bffab5fc2dba69d51fecc6810b74dfce82
7
- data.tar.gz: 4baf6ce65f7efc84e72c13b66a8ccbacf08a68c4d783770736c5f344d6848440dc11d2894d07474da38e73b777ac668dff5cfb18f3f5f4d29b77ab115df65022
6
+ metadata.gz: 5e7333857e60fee06cfd5f9a673e71c36378384aba26b67289e5ba2ab66a533abad6483245049d79b0ce5e9315e46413edf7b632444bab298254d6687f939428
7
+ data.tar.gz: 774b6946f8d905fe0e38015fde95cdfa1ba0936b9e1c1994806fe7c9335a2a06f47b3869b2027cd4bed5e7b976bab9c54c61f5cda4f4e542cb1318766ef13cf1
data/.rubocop.yml CHANGED
@@ -48,7 +48,5 @@ Style/Documentation:
48
48
  Layout/LineLength:
49
49
  Enabled: false
50
50
 
51
-
52
-
53
-
54
-
51
+ Metrics/ParameterLists:
52
+ Max: 8
data/Gemfile CHANGED
@@ -3,4 +3,3 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
-
data/README.md CHANGED
@@ -615,6 +615,59 @@ titi
615
615
 
616
616
  ### Service Finisher
617
617
 
618
+
619
+ #### List of available return code and associated symbols :
620
+
621
+ - code : must be a clI OR HTTP return code
622
+ - key : a I18n service key in locales files (Carioca internals locales) see https://github.com/Ultragreen/carioca/tree/master/config/locales
623
+
624
+ ```ruby
625
+ # global
626
+ not_root: { code: 40, key: 'finisher.messages.not_root' },
627
+ options_incompatibility: { code: 410, key: 'finisher.messages.options_incompatibility'},
628
+ service_dependence_missing: { code: 430, key: 'finisher.messages.service_dependence_missing'},
629
+ config_required: { code: 420, key: 'finisher.messages.config_required'},
630
+ setup_error: { code: 520, key: 'finisher.messages.setup_error'},
631
+ setup_success: { code: 0, key: 'finisher.messages.setup_success'},
632
+ sanitycheck_error: { code: 510, key: 'finisher.messages.sanitycheck_error'},
633
+ sanitycheck_success: { code: 0, key: 'finisher.messages.sanitycheck_success'},
634
+ configuration_error: { code: 501, key: 'finisher.messages.configuration_error'},
635
+ success_exit: { code: 0, key: 'finisher.messages.success_exit' },
636
+ quiet_exit: { code: 0 },
637
+ error_exit: { code: 50, key: 'finisher.messages.error_exit' },
638
+
639
+ # events
640
+ interrupt: { code: 330, key: 'finisher.messages.interrupt' },
641
+
642
+ # request & API
643
+ not_found: { code: 404, key: 'finisher.messages.not_found' },
644
+ already_exist: { code: 408, key: 'finisher.messages.already_exist' },
645
+
646
+ # daemon & API
647
+ status_ok: { code: 200, key: 'finisher.messages.status_ok' },
648
+ created: { code: 201, key: 'finisher.messages.created' },
649
+ accepted: { code: 202, key: 'finisher.messages.accepted' },
650
+ bad_request: { code: 400, key: 'finisher.messages.bad_request' },
651
+ status_ko: { code: 500, key: 'finisher.messages.status_ko' },
652
+ no_content: { code: 204, key: 'finisher.messages.no_content' },
653
+ ```
654
+
655
+ This returns must be override from Config File (using Builtin Configuration Service) inbluding a key exit_cases:
656
+ like :
657
+
658
+ ```yaml
659
+ ---
660
+ :my_root:
661
+ :default:
662
+ :exit_cases:
663
+ :mystatus:
664
+ :code: 8000
665
+ key: 'my.own.i18n.key'
666
+
667
+ ```
668
+
669
+
670
+
618
671
  ### Service Setup
619
672
 
620
673
  ### Service SanityCheck
data/Rakefile CHANGED
@@ -45,17 +45,17 @@ namespace :yardoc do
45
45
  end
46
46
  task clobber: 'yardoc:clobber'
47
47
 
48
- desc "Run CVE security audit over bundle"
48
+ desc 'Run CVE security audit over bundle'
49
49
  task :audit do
50
50
  system('bundle audit')
51
51
  end
52
52
 
53
- desc "Run dead line of code detection"
53
+ desc 'Run dead line of code detection'
54
54
  task :debride do
55
55
  system('debride -w .debride_withelist .')
56
56
  end
57
57
 
58
- desc "Run SBOM CycloneDX Xml format file"
58
+ desc 'Run SBOM CycloneDX Xml format file'
59
59
  task :sbom do
60
60
  system('cyclonedx-ruby -p .')
61
- end
61
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.3
1
+ 2.1.5
data/carioca.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/Ultragreen/carioca'
15
15
  spec.description = 'Carioca 2: is a complete rewrite who provide a full IoC/DI light Container and a services registry, build with logs, config and Internationalization facilities for designing your applications'
16
16
 
17
- spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
17
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.2.3')
18
18
 
19
19
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
20
 
@@ -35,15 +35,15 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency 'locale', '~> 2.1'
36
36
  spec.add_dependency 'pastel', '~>0.8.0'
37
37
  spec.add_dependency 'tty-prompt', '~>0.23.1'
38
+ spec.add_development_dependency 'bundle-audit', '~> 0.1.0'
38
39
  spec.add_development_dependency 'code_statistics', '~> 0.2.13'
39
40
  spec.add_development_dependency 'rake', '~> 13.0'
40
41
  spec.add_development_dependency 'rspec', '~> 3.0'
41
42
  spec.add_development_dependency 'rubocop', '~> 1.32'
42
43
  spec.add_development_dependency 'yard', '~> 0.9.27'
43
44
  spec.add_development_dependency 'yard-rspec', '~> 0.1'
44
- spec.add_development_dependency "bundle-audit", "~> 0.1.0"
45
45
  spec.metadata['rubygems_mfa_required'] = 'false'
46
46
  spec.add_dependency 'version', '~> 1.1'
47
- spec.add_runtime_dependency 'ps-ruby','~> 0.0.4'
48
- spec.add_development_dependency "cyclonedx-ruby", "~> 1.1"
47
+ spec.add_runtime_dependency 'ps-ruby', '~> 0.0.4'
48
+ spec.add_development_dependency 'cyclonedx-ruby', '~> 1.1'
49
49
  end
@@ -34,7 +34,7 @@ module Carioca
34
34
  @secure_store_file = DEFAULT_SECURE_STORE_FILE.dup
35
35
  path = search_file_in_gem('carioca', 'config/locales')
36
36
  @locales_load_path = Dir["#{File.expand_path(path)}/*.yml"]
37
- Dir["#{path}/*.yml"].sort.each do |file|
37
+ Dir["#{path}/*.yml"].each do |file|
38
38
  @locales_availables.push File.basename(file, '.yml').to_sym
39
39
  end
40
40
  @debugger_tracer = DEFAULT_DEBUGGER_TRACER.dup
@@ -8,16 +8,16 @@ module Carioca
8
8
  DEFAULT_CONFIG_ROOT = :carioca
9
9
  DEFAULT_LOCALE = :en
10
10
 
11
- DEFAULT_OUTPUT_TARGET = STDOUT
11
+ DEFAULT_OUTPUT_TARGET = $stdout
12
12
  DEFAULT_OUTPUT_MODE = :mono
13
13
  DEFAULT_EMOJI_STATUS = true
14
14
  DEFAULT_COLORS_STATUS = true
15
15
  DEFAULT_LOG_LEVEL = :info
16
16
 
17
- DEFAULT_USER_CONFIG_PATH = "~/.carioca"
17
+ DEFAULT_USER_CONFIG_PATH = '~/.carioca'
18
18
 
19
- DEFAULT_MASTER_KEY_FILE = "#{DEFAULT_USER_CONFIG_PATH}/master.key"
20
- DEFAULT_SECURE_STORE_FILE = "#{DEFAULT_USER_CONFIG_PATH}/secure.Store"
19
+ DEFAULT_MASTER_KEY_FILE = "#{DEFAULT_USER_CONFIG_PATH}/master.key".freeze
20
+ DEFAULT_SECURE_STORE_FILE = "#{DEFAULT_USER_CONFIG_PATH}/secure.Store".freeze
21
21
 
22
22
  DEFAULT_DEBUGGER_TRACER = :output
23
23
 
@@ -29,9 +29,6 @@ module Carioca
29
29
 
30
30
  DEFAULT_ENVIRONMENTS_LIST = %i[production staging test development].freeze
31
31
 
32
-
33
-
34
-
35
32
  BUILTINS = {
36
33
  configuration: {
37
34
  type: :internal,
@@ -71,30 +68,30 @@ module Carioca
71
68
  type: :internal,
72
69
  service: 'Carioca::Services::Finisher::new',
73
70
  description: 'The Finisher service of Carioca',
74
- depends: [:i18n,:logger, :configuration]
71
+ depends: %i[i18n logger configuration]
75
72
  },
76
73
  toolbox: {
77
74
  type: :internal,
78
75
  service: 'Carioca::Services::Toolbox',
79
- description: 'The Misceleanous Toolbox service of Carioca',
76
+ description: 'The Misceleanous Toolbox service of Carioca'
80
77
  },
81
78
  setup: {
82
79
  type: :internal,
83
80
  service: 'Carioca::Services::Setup::new',
84
81
  description: 'The Setup service of Carioca',
85
- depends: [:i18n,:logger, :configuration ]
82
+ depends: %i[i18n logger configuration]
86
83
  },
87
84
  sanitycheck: {
88
85
  type: :internal,
89
86
  service: 'Carioca::Services::Sanitycheck::new',
90
87
  description: 'The Sanitycheck service of Carioca',
91
- depends: [:i18n,:logger, :configuration ]
88
+ depends: %i[i18n logger configuration]
92
89
  },
93
90
  securestore: {
94
91
  type: :internal,
95
92
  service: 'Carioca::Services::SecureStore::new',
96
93
  description: 'The SecureStore service of Carioca',
97
- depends: [:i18n,:logger, :configuration ]
94
+ depends: %i[i18n logger configuration]
98
95
  },
99
96
  debugger: {
100
97
  type: :internal,
@@ -5,8 +5,6 @@ require 'forwardable'
5
5
  require 'singleton'
6
6
 
7
7
  require 'socket'
8
- require 'yaml'
9
- require 'thread'
10
8
  require 'fileutils'
11
9
  require 'etc'
12
10
  require 'json'
@@ -14,8 +12,6 @@ require 'uri'
14
12
  require 'openssl'
15
13
  require 'base64'
16
14
 
17
-
18
-
19
15
  require 'rubygems'
20
16
  require 'i18n'
21
17
  require 'locale'
data/lib/carioca/mixin.rb CHANGED
@@ -6,8 +6,8 @@ module Carioca
6
6
  create_methods(service) { return Carioca::Registry.get.get_service name: service }
7
7
  end
8
8
 
9
- def register(service:, definition:)
10
- Carioca::Registry.get.add service: service, definition: definition
9
+ def add(service:, definition:)
10
+ Carioca::Registry.get.add service:, definition:
11
11
  end
12
12
 
13
13
  def services
@@ -18,9 +18,9 @@ module Carioca
18
18
  Carioca::Registry.get.active_services
19
19
  end
20
20
 
21
- def create_methods(name, &block)
22
- define_method name, &block
23
- self.class.send(:define_method, name, &block)
21
+ def create_methods(name, &)
22
+ define_method(name, &)
23
+ self.class.send(:define_method, name, &)
24
24
  end
25
25
 
26
26
  def self.extended(base)
@@ -25,8 +25,8 @@ module Carioca
25
25
  raise "Service not found: #{name}" unless @services.include? name
26
26
 
27
27
  if @active_services.include? name
28
- debug message: i18n.t('service.getting', name: name) if @active_services.include?(:logger) && !%i[logger
29
- i18n output].include?(name) && @@config.debug?
28
+ debug message: i18n.t('service.getting', name:) if @active_services.include?(:logger) && !%i[logger
29
+ i18n output].include?(name) && @@config.debug?
30
30
  else
31
31
  service = @services[name]
32
32
  if service.include? :depends
@@ -36,9 +36,9 @@ module Carioca
36
36
  get_service(name: dep) unless @active_services.include? dep
37
37
  end
38
38
  end
39
- debug message: i18n.t('service.starting', name: name) if @active_services.include?(:logger) && !%i[logger
40
- i18n].include?(name) && @@config.debug?
41
- require service[:resource] if %i[gem file stdlib].include? service[:type]
39
+ debug message: i18n.t('service.starting', name:) if @active_services.include?(:logger) && !%i[logger
40
+ i18n].include?(name) && @@config.debug?
41
+ require service[:resource] if %i[gem file stdlib].include? service[:type]
42
42
  @active_services[name] ||= eval("lambda { #{service[:service]} }").call # lambda { Aservice::new }
43
43
  end
44
44
  @active_services[name]
@@ -55,7 +55,7 @@ module Carioca
55
55
  debug message: i18n.t('service.adding',
56
56
  name: service)
57
57
  end
58
- checker = Carioca::Services::Validator.new service: service, definition: definition
58
+ checker = Carioca::Services::Validator.new(service:, definition:)
59
59
  checker.validate! unless skip_validation
60
60
  @services[service] = checker.definition
61
61
  end
@@ -78,7 +78,7 @@ module Carioca
78
78
  locale = @@config.default_locale
79
79
  target = @@config.log_file? ? @@config.log_file : 'STDOUT'
80
80
  debug message: i18n.t('notify.locale', loc: locale) if @@config.debug?
81
- debug message: i18n.t('notify.logger', target: target) if @@config.debug?
81
+ debug message: i18n.t('notify.logger', target:) if @@config.debug?
82
82
  debug message: i18n.t('init.carioca') if @@config.debug?
83
83
  debug message: i18n.t('init.builtins') if @@config.debug?
84
84
  @@config.builtins.each do |service, spec|
@@ -95,7 +95,7 @@ module Carioca
95
95
  file_name: @@config.filename)
96
96
  end
97
97
  registry_file.validated.each do |service, spec|
98
- add service: service, definition: spec
98
+ add service:, definition: spec
99
99
  end
100
100
  debug message: i18n.t('init.registry.success') if @@config.debug?
101
101
  end
@@ -29,7 +29,7 @@ module Carioca
29
29
  end
30
30
 
31
31
  def add(service:, definition:)
32
- checker = Carioca::Services::Validator.new service: service, definition: definition
32
+ checker = Carioca::Services::Validator.new(service:, definition:)
33
33
  checker.validate!
34
34
  @validated[service] = checker.definition
35
35
  end
@@ -50,7 +50,7 @@ module Carioca
50
50
  @candidates.delete_if { |key, _value| BUILTINS.keys.include? key }
51
51
  @altered = save.keys - @candidates.keys
52
52
  @candidates.each do |service, definition|
53
- checker = Carioca::Services::Validator.new service: service, definition: definition
53
+ checker = Carioca::Services::Validator.new(service:, definition:)
54
54
  checker.validate!
55
55
  @validated[service] = checker.definition
56
56
  end
@@ -4,7 +4,7 @@ module Carioca
4
4
  module Services
5
5
  class Debugger
6
6
  def self.get(service:, trace: Carioca::Registry.config.debugger_tracer)
7
- ProxyDebug.new service: service, trace: trace
7
+ ProxyDebug.new service:, trace:
8
8
  end
9
9
  end
10
10
 
@@ -19,14 +19,14 @@ module Carioca
19
19
  @tracer_type = trace
20
20
  end
21
21
 
22
- def method_missing(methodname, *args, **keywords, &block)
22
+ def method_missing(methodname, *args, **keywords, &)
23
23
  trace message: "BEGIN CALL for service #{@service} "
24
24
  trace message: "Method called: #{methodname} "
25
25
  trace message: "args : #{args.join ' '}"
26
26
  trace message: "keywords : #{keywords}"
27
27
  if block_given?
28
28
  trace message: 'block given'
29
- a = @service.send(methodname, *args, **keywords, &block)
29
+ a = @service.send(methodname, *args, **keywords, &)
30
30
  else
31
31
  a = @service.send(methodname, *args, **keywords)
32
32
  end
@@ -1,131 +1,124 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # base Carioca namespace
4
4
  module Carioca
5
+ module Services
6
+ class SpecificError < StandardError
7
+ attr_reader :error_case
5
8
 
6
- module Services
9
+ def initialize(*arg, error_case: :status_ko)
10
+ super(*arg)
11
+ @error_case = error_case
12
+ end
13
+ end
7
14
 
8
- class SpecificError < Exception
9
- attr_reader :error_case
10
- def initialize(*arg, error_case: :status_ko)
11
- super(*arg)
12
- @error_case = error_case
13
- end
14
- end
15
+ # Exiter namespace
16
+ class Finisher
17
+ DEFAULT_FINISHERS_SPECS = {
18
+ # global
19
+ not_root: { code: 40, key: 'finisher.messages.not_root' },
20
+ options_incompatibility: { code: 410, key: 'finisher.messages.options_incompatibility' },
21
+ service_dependence_missing: { code: 430, key: 'finisher.messages.service_dependence_missing' },
22
+ config_required: { code: 420, key: 'finisher.messages.config_required' },
23
+ setup_error: { code: 520, key: 'finisher.messages.setup_error' },
24
+ setup_success: { code: 0, key: 'finisher.messages.setup_success' },
25
+ sanitycheck_error: { code: 510, key: 'finisher.messages.sanitycheck_error' },
26
+ sanitycheck_success: { code: 0, key: 'finisher.messages.sanitycheck_success' },
27
+ configuration_error: { code: 501, key: 'finisher.messages.configuration_error' },
28
+ success_exit: { code: 0, key: 'finisher.messages.success_exit' },
29
+ quiet_exit: { code: 0 },
30
+ error_exit: { code: 50, key: 'finisher.messages.error_exit' },
31
+ # events
32
+ interrupt: { code: 330, key: 'finisher.messages.interrupt' },
33
+ # request & API
34
+ not_found: { code: 404, key: 'finisher.messages.not_found' },
35
+ already_exist: { code: 408, key: 'finisher.messages.already_exist' },
36
+ # daemon & API
37
+ status_ok: { code: 200, key: 'finisher.messages.status_ok' },
38
+ created: { code: 201, key: 'finisher.messages.created' },
39
+ accepted: { code: 202, key: 'finisher.messages.accepted' },
40
+ bad_request: { code: 400, key: 'finisher.messages.bad_request' },
41
+ status_ko: { code: 500, key: 'finisher.messages.status_ko' },
42
+ no_content: { code: 204, key: 'finisher.messages.no_content' }
43
+ }.freeze
15
44
 
16
- # Exiter namespace
17
- class Finisher
18
-
19
- DEFAULT_FINISHERS_SPECS = {
20
- # global
21
- not_root: { code: 40, key: 'finisher.messages.not_root' },
22
- options_incompatibility: { code: 410, key: 'finisher.messages.options_incompatibility'},
23
- service_dependence_missing: { code: 430, key: 'finisher.messages.service_dependence_missing'},
24
- config_required: { code: 420, key: 'finisher.messages.config_required'},
25
- setup_error: { code: 520, key: 'finisher.messages.setup_error'},
26
- setup_success: { code: 0, key: 'finisher.messages.setup_success'},
27
- sanitycheck_error: { code: 510, key: 'finisher.messages.sanitycheck_error'},
28
- sanitycheck_success: { code: 0, key: 'finisher.messages.sanitycheck_success'},
29
- configuration_error: { code: 501, key: 'finisher.messages.configuration_error'},
30
- success_exit: { code: 0, key: 'finisher.messages.success_exit' },
31
- quiet_exit: { code: 0 },
32
- error_exit: { code: 50, key: 'finisher.messages.error_exit' },
33
- # events
34
- interrupt: { code: 330, key: 'finisher.messages.interrupt' },
35
- # request & API
36
- not_found: { code: 404, key: 'finisher.messages.not_found' },
37
- already_exist: { code: 408, key: 'finisher.messages.already_exist' },
38
- # daemon & API
39
- status_ok: { code: 200, key: 'finisher.messages.status_ok' },
40
- created: { code: 201, key: 'finisher.messages.created' },
41
- accepted: { code: 202, key: 'finisher.messages.accepted' },
42
- bad_request: { code: 400, key: 'finisher.messages.bad_request' },
43
- status_ko: { code: 500, key: 'finisher.messages.status_ko' },
44
- no_content: { code: 204, key: 'finisher.messages.no_content' },
45
- }
45
+ def initialize
46
+ registry = Carioca::Registry.get
47
+ @output = registry.get_service name: :output
48
+ @i18n = registry.get_service name: :i18n
49
+ @configuration = registry.get_service name: :configuration
50
+ @exit_map = {}.merge DEFAULT_FINISHERS_SPECS
51
+ @exit_map.merge! @configuration.settings.exit_cases if @configuration.settings.exit_cases
52
+ end
46
53
 
47
-
48
- def initialize
49
- registry = Carioca::Registry.get
50
- @output = registry.get_service name: :output
51
- @i18n = registry.get_service name: :i18n
52
- @configuration = registry.get_service name: :configuration
53
- @exit_map = DEFAULT_FINISHERS_SPECS
54
- @exit_map.merge! @configuration.settings.exit_cases if @configuration.settings.exit_cases
55
- end
54
+ def terminate(return_case: nil, exit_case: nil, more: nil)
55
+ raise 'Case must be a return or an exit' if return_case && exit_case
56
56
 
57
- def terminate(return_case: nil, exit_case: nil, more: nil )
58
- raise "Case must be a return or an exit" if return_case and exit_case
59
- do_exit!( exit_case: exit_case, more: more) if exit_case
60
- do_return(return_case: return_case, more: more) if return_case
61
- end
62
-
63
- # exiter
64
- # @option [Symbol] :case an exit case
65
- # @option [String] :more a complementary string to display
66
- def do_exit!(exit_case: :quiet_exit, more: nil )
67
- mess = ""
68
- mess = @i18n.t(@exit_map[exit_case][:key]) if @exit_map[exit_case].include? :key
69
- mess << " : " unless mess.empty? or not more
70
- mess << "#{more}" if more
71
- if @exit_map[exit_case][:code] == 0 then
72
- @output.success mess unless mess.empty?
73
- exit 0
74
- else
75
- @output.fatal mess unless mess.empty?
76
- exit @exit_map[exit_case][:code]
77
- end
78
- end
79
-
80
- def do_return(return_case: :status_ok, more: nil )
81
- data = @exit_map[return_case].clone
82
- if data.include? :key then
83
- data[:message] = @i18n.t(data[:key])
84
- data.delete :key
85
- end
86
- data[:more] = more if more
87
- return data
88
- end
57
+ do_exit!(exit_case:, more:) if exit_case
58
+ do_return(return_case:, more:) if return_case
59
+ end
89
60
 
90
- def secure_raise(message: "unknown error", error_case: :status_ko)
91
- raise SpecificError::new message, error_case: error_case
61
+ # exiter
62
+ # @option [Symbol] :case an exit case
63
+ # @option [String] :more a complementary string to display
64
+ def do_exit!(exit_case: :quiet_exit, more: nil)
65
+ mess = ''
66
+ mess = @i18n.t(@exit_map[exit_case][:key]) if @exit_map[exit_case].include? :key
67
+ mess << ' : ' unless mess.empty? || !more
68
+ mess << more.to_s if more
69
+ if (@exit_map[exit_case][:code]).zero?
70
+ @output.success mess unless mess.empty?
71
+ exit 0
72
+ else
73
+ @output.fatal mess unless mess.empty?
74
+ exit @exit_map[exit_case][:code]
92
75
  end
76
+ end
93
77
 
78
+ def do_return(return_case: :status_ok, more: nil)
79
+ data = @exit_map[return_case].clone
80
+ if data.include? :key
81
+ data[:message] = @i18n.t(data[:key])
82
+ data.delete :key
83
+ end
84
+ data[:more] = more if more
85
+ data
86
+ end
94
87
 
95
- def secure_api_return(data: nil, return_case: nil, structured: false, json: true, status: true)
96
- result = {}
97
- begin
98
- data = yield if block_given?
99
- result = (structured)? do_return(return_case: return_case).merge({data: data }) : data
100
- rescue Exception => e
101
- key = (e.respond_to? :error_case)? e.error_case : :status_ko
102
- more = (e.respond_to? :error_case)? e.message : "#{e.class.to_s} : #{e.message}"
103
- result = do_return return_case: key, more: more
104
- end
105
- if status and structured and json then
106
- p result
107
- return {status: result[:code], data: JSON.pretty_generate(JSON.parse(result.to_json))}
108
- elsif json then
109
- return JSON.pretty_generate(JSON.parse(result.to_json)) if json
110
- else
111
- return result
112
- end
113
- end
88
+ def secure_raise(message: 'unknown error', error_case: :status_ko)
89
+ raise SpecificError.new(message, error_case:)
90
+ end
114
91
 
92
+ def secure_api_return(data: nil, return_case: nil, structured: false, json: true, status: true)
93
+ result = {}
94
+ begin
95
+ data = yield if block_given?
96
+ result = structured ? do_return(return_case:).merge({ data: }) : data
97
+ rescue StandardError => e
98
+ key = e.respond_to?(:error_case) ? e.error_case : :status_ko
99
+ more = e.respond_to?(:error_case) ? e.message : "#{e.class} : #{e.message}"
100
+ result = do_return return_case: key, more:
101
+ end
102
+ if status && structured && json
103
+ p result
104
+ { status: result[:code], data: JSON.pretty_generate(JSON.parse(result.to_json)) }
105
+ elsif json
106
+ JSON.pretty_generate(JSON.parse(result.to_json)) if json
107
+ else
108
+ result
109
+ end
110
+ end
115
111
 
116
- def secure_execute!( exit_case: :success_exit )
117
- result = {}
118
- begin
119
- more = yield
120
-
121
- rescue Exception => e
122
- key = (e.respond_to? :error_case)? e.error_case : :error_exit
123
- more = (e.respond_to? :error_case)? e.message : "#{e.class.to_s} : #{e.message}"
124
- exit_case = key
125
- end
126
- do_exit! exit_case: exit_case, more: more
127
- end
128
-
112
+ def secure_execute!(exit_case: :success_exit)
113
+ begin
114
+ more = yield
115
+ key = exit_case
116
+ rescue StandardError => e
117
+ key = e.respond_to?(:error_case) ? e.error_case : :error_exit
118
+ more = e.respond_to?(:error_case) ? e.message : "#{e.class} : #{e.message}"
119
+ end
120
+ do_exit! exit_case: key, more:
129
121
  end
130
122
  end
131
- end
123
+ end
124
+ end
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Dir["#{File.dirname(__FILE__)}/*.rb"].sort.each { |file| require file unless File.basename(file) == 'init.rb' }
3
+ Dir["#{File.dirname(__FILE__)}/*.rb"].each { |file| require file unless File.basename(file) == 'init.rb' }
@@ -43,7 +43,7 @@ module Carioca
43
43
  success: { value: "\u{1F4AA}", alt: '[+]', text: '(SUCCESS)' },
44
44
  debug: { value: "\u{1F41B}", alt: '[D]', text: '(DEBUG)' },
45
45
  flat: { value: '', alt: '' },
46
- skipped: { value: "\u{23E9}", alt: '[I]', text: '(SKIPPED)'}
46
+ skipped: { value: "\u{23E9}", alt: '[I]', text: '(SKIPPED)' }
47
47
  }.freeze
48
48
  LEVELS = %i[debug info warn error fatal unknown].freeze
49
49
  ALIAS = {
@@ -76,12 +76,12 @@ module Carioca
76
76
 
77
77
  LEVELS.each do |method|
78
78
  define_method(method) do |message, session = nil, source = 'Carioca->Output'|
79
- display(level: method, message: message, session: session, source: source)
79
+ display(level: method, message:, session:, source:)
80
80
  end
81
81
  end
82
82
  @@alias.each_key do |method|
83
83
  define_method(method) do |message, session = nil, source = 'Carioca->Output'|
84
- display(level: method, message: message, session: session, source: source)
84
+ display(level: method, message:, session:, source:)
85
85
  end
86
86
  end
87
87
 
@@ -104,12 +104,12 @@ module Carioca
104
104
  raise "Bad Level : #{level}" unless LEVELS.include? level
105
105
 
106
106
  self.class.define_method(newalias) do |message, session = nil|
107
- display({ level: newalias, message: message, session: session })
107
+ display({ level: newalias, message:, session: })
108
108
  end
109
109
  end
110
110
 
111
111
  # constructor
112
- def initialize(level: :debug, mode: :mono, emoji: true, colors: true, target: STDOUT)
112
+ def initialize(level: :debug, mode: :mono, emoji: true, colors: true, target: $stdout)
113
113
  registry = Carioca::Registry.get
114
114
  @logger = registry.get_service name: :logger
115
115
  @i18n = registry.get_service name: :i18n
@@ -183,7 +183,7 @@ module Carioca
183
183
  block = proc { save }
184
184
  @logger.send target_level, source, &block
185
185
  end
186
- @target.puts message if @mode == :mono or @mode == :dual
186
+ @target.puts message if (@mode == :mono) || (@mode == :dual)
187
187
  end
188
188
  end
189
189
  end