carioca 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/locales/en.yml +4 -0
- data/config/locales/fr.yml +5 -1
- data/lib/carioca/configuration.rb +2 -1
- data/lib/carioca/constants.rb +9 -1
- data/lib/carioca/rake/manage.rb +3 -0
- data/lib/carioca/rake/tasks/config.tasks +46 -0
- data/lib/carioca/rake/tasks/gem.tasks +15 -0
- data/lib/carioca/rake/tasks/registry.tasks +17 -10
- data/lib/carioca/registry.rb +1 -1
- data/lib/carioca/services/config.rb +3 -2
- data/lib/carioca/services/debug.rb +58 -0
- data/lib/carioca/services/output.rb +25 -11
- data/samples/test.rb +23 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99fbf2409631fe5afb97b9807059612f5eaa0e237bf44685a8f9aa993db1b87b
|
4
|
+
data.tar.gz: 36636acf529dc8610985e3bd96310482a0e0f9003836c6a902411cf908735166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9dccd95e578ea578f226c273c132f6021a23b856a25606557044cbaa0aea3403e0522b236c87a581a69653fc0264c8c3c38eb643baf4e9538db5534ffe0a316
|
7
|
+
data.tar.gz: b64096695a61f14423ca8d90363b3fd1d09317aa3eac742e4e9aef4b4ff0381cfd0f443fca2d498092673fd122d639e8b93f182ba1854d38fe138e742e19dc5d
|
data/Gemfile.lock
CHANGED
data/config/locales/en.yml
CHANGED
data/config/locales/fr.yml
CHANGED
@@ -16,4 +16,8 @@ fr:
|
|
16
16
|
success: "Registre initialisé avec succès"
|
17
17
|
config:
|
18
18
|
load:
|
19
|
-
error: "Fichier de configuration ignoré, erreur : %{message}"
|
19
|
+
error: "Fichier de configuration ignoré, erreur : %{message}"
|
20
|
+
success: "Service de configuration initialisé avec succès depuis : %{from}"
|
21
|
+
output:
|
22
|
+
load:
|
23
|
+
context: "Service output initialisé en mode : %{confset}"
|
@@ -2,7 +2,7 @@ module Carioca
|
|
2
2
|
class Configuration
|
3
3
|
include Carioca::Constants
|
4
4
|
include Carioca::Helpers
|
5
|
-
attr_accessor :filename, :name, :builtins, :log_target, :default_locale, :locales_load_path
|
5
|
+
attr_accessor :filename, :name, :builtins, :log_target, :default_locale, :locales_load_path, :debugger_tracer
|
6
6
|
attr_accessor :config_file, :config_root, :environment, :supported_environment, :output_mode, :log_level
|
7
7
|
attr_writer :debug, :init_from_file, :output_colors, :output_emoji
|
8
8
|
attr_reader :log_file, :locales_availables
|
@@ -30,6 +30,7 @@ module Carioca
|
|
30
30
|
Dir[path + '/*.yml'].sort.each do |file|
|
31
31
|
@locales_availables.push File::basename(file,'.yml').to_sym
|
32
32
|
end
|
33
|
+
@debugger_tracer = DEFAULT_DEBUGGER_TRACER.dup
|
33
34
|
end
|
34
35
|
|
35
36
|
def debug?
|
data/lib/carioca/constants.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Carioca
|
2
2
|
module Constants
|
3
3
|
|
4
|
-
VERSION = '2.0.
|
4
|
+
VERSION = '2.0.3'
|
5
5
|
DEFAULT_REGISTRY_FILE = './config/carioca.registry'
|
6
6
|
DEFAULT_CONFIG_FILE = './config/settings.yml'
|
7
7
|
DEFAULT_ENVIRONMENT = :development
|
@@ -14,6 +14,9 @@ module Carioca
|
|
14
14
|
DEFAULT_COLORS_STATUS = true
|
15
15
|
DEFAULT_LOG_LEVEL = :info
|
16
16
|
|
17
|
+
|
18
|
+
DEFAULT_DEBUGGER_TRACER = :output
|
19
|
+
|
17
20
|
# service definitions specs
|
18
21
|
SERVICES_MANDATORY_SPECS = {type: Symbol, service: String}
|
19
22
|
SERVICES_FULL_LIST_SPECS = SERVICES_MANDATORY_SPECS.merge({depends: Array, description: String, resource: String })
|
@@ -53,6 +56,11 @@ module Carioca
|
|
53
56
|
colors: Carioca::Registry.config.output_colors?,
|
54
57
|
level: Carioca::Registry.config.log_level
|
55
58
|
)"
|
59
|
+
},
|
60
|
+
debugger:{
|
61
|
+
type: :internal,
|
62
|
+
description: "The Debugger Service of Carioca",
|
63
|
+
service: "Carioca::Services::Debugger"
|
56
64
|
}
|
57
65
|
}
|
58
66
|
|
data/lib/carioca/rake/manage.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
namespace :carioca do
|
2
|
+
namespace :services do
|
3
|
+
namespace :config do
|
4
|
+
desc "Initialise Service configuration file ./config/settings.yml file"
|
5
|
+
task :init do
|
6
|
+
begin
|
7
|
+
prompt = TTY::Prompt.new
|
8
|
+
pastel = ::Pastel.new
|
9
|
+
|
10
|
+
if File::exist? "./config/settings.yml" then
|
11
|
+
puts pastel.yellow "WARNING : config file already exist, if you continue, you will destroy it !"
|
12
|
+
continue = prompt.yes?("continue ? ") do |q|
|
13
|
+
q.default false
|
14
|
+
end
|
15
|
+
print "Carioca : "
|
16
|
+
unless continue then
|
17
|
+
puts pastel.yellow "canceled"
|
18
|
+
exit 5
|
19
|
+
else
|
20
|
+
File::unlink "./config/settings.yml"
|
21
|
+
puts pastel.cyan "Reset File"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
unless File::exist? "./config" then
|
26
|
+
puts pastel.red "Carioca is not initialized for Gem usage, perhaps need to run :"
|
27
|
+
puts pastel.red "$ rake carioca:gem:init_path"
|
28
|
+
exit 10
|
29
|
+
end
|
30
|
+
puts "Carioca : initializing default config file (./config/settings.yml): "
|
31
|
+
root = prompt.ask("Root config name ? (like your gem/App name)") { |q|
|
32
|
+
q.modify :down
|
33
|
+
q.required true }.to_sym
|
34
|
+
print "Carioca : Generating config file : "
|
35
|
+
structure = {root => {:production => {}, :staging => {}, :development => {}, :test => {}, :default => {}}}
|
36
|
+
File.open('./config/settings.yml', 'w') { |file| file.write(structure.to_yaml) }
|
37
|
+
puts pastel.green 'done'
|
38
|
+
rescue TTY::Reader::InputInterrupt
|
39
|
+
print "Carioca : "
|
40
|
+
puts pastel.yellow 'interrupted'
|
41
|
+
exit 5
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
namespace :carioca do
|
2
|
+
namespace :gem do
|
3
|
+
desc "prepare Gem vitals path for Carioca"
|
4
|
+
task :init_path do
|
5
|
+
pastel = Pastel.new
|
6
|
+
if File::exist? "./config/locales"
|
7
|
+
puts pastel.yellow "Carioca path already initialized"
|
8
|
+
else
|
9
|
+
print 'Carioca : Initialising vitals gem path : '
|
10
|
+
FileUtils.mkdir_p "./config/locales"
|
11
|
+
puts pastel.green "done"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,15 +1,18 @@
|
|
1
|
-
require "tty-prompt"
|
2
|
-
require "pastel"
|
3
|
-
|
4
1
|
namespace :carioca do
|
5
2
|
namespace :registry do
|
6
3
|
desc "Adding service to Carioca Registry file"
|
7
4
|
task :add_service do
|
5
|
+
prompt = TTY::Prompt.new
|
6
|
+
pastel = ::Pastel.new
|
8
7
|
begin
|
8
|
+
unless File::exist? "./config" then
|
9
|
+
|
10
|
+
puts pastel.yellow "Carioca is not initialized for Gem usage, perhaps need to run :"
|
11
|
+
puts pastel.yellow "$ rake carioca:gem:init_path"
|
12
|
+
exit unless prompt.yes?("Do you want to continue, with a standalone registry (not recommanded). ? ")
|
13
|
+
end
|
9
14
|
puts "Carioca : registering service :"
|
10
15
|
config = Carioca::Configuration::new
|
11
|
-
prompt = TTY::Prompt.new
|
12
|
-
pastel = Pastel.new
|
13
16
|
filename = prompt.ask("Registry File path ?", default: config.filename)
|
14
17
|
registry_file = Carioca::RegistryFile::new filename: filename
|
15
18
|
name = prompt.ask("Service name ?") { |q| q.required true }.to_sym
|
@@ -36,22 +39,26 @@ namespace :carioca do
|
|
36
39
|
end
|
37
40
|
is_correct = prompt.yes?("Is it correct ? ")
|
38
41
|
rescue TTY::Reader::InputInterrupt
|
39
|
-
|
42
|
+
print "Carioca : "
|
43
|
+
puts pastel.yellow 'interrupted'
|
40
44
|
exit 5
|
41
45
|
end
|
46
|
+
print "Carioca : Registry saving : "
|
42
47
|
if is_correct then
|
43
48
|
begin
|
44
49
|
registry_file.add service: name, definition: definition
|
45
50
|
registry_file.save!
|
46
51
|
rescue => e
|
47
|
-
|
52
|
+
print pastel.red "failed"
|
53
|
+
puts " error : #{e}"
|
48
54
|
exit 10
|
49
55
|
end
|
50
56
|
|
51
|
-
puts
|
57
|
+
puts pastel.green "done"
|
52
58
|
else
|
53
|
-
puts
|
59
|
+
puts pastel.yellow 'canceled'
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
57
|
-
|
63
|
+
|
64
|
+
end
|
data/lib/carioca/registry.rb
CHANGED
@@ -25,7 +25,7 @@ module Carioca
|
|
25
25
|
|
26
26
|
raise "Service not found: #{name}" unless @services.include? name
|
27
27
|
if @active_services.include? name then
|
28
|
-
debug message: i18n.t('service.getting', name: name) if @active_services.include? :logger and ![:logger, :i18n].include? name and @@config.debug?
|
28
|
+
debug message: i18n.t('service.getting', name: name) if @active_services.include? :logger and ![:logger, :i18n, :output].include? name and @@config.debug?
|
29
29
|
else
|
30
30
|
service = @services[name]
|
31
31
|
service[:depends].each do|dep|
|
@@ -85,7 +85,7 @@ class Hash
|
|
85
85
|
registry = Carioca::Registry.get
|
86
86
|
@logger = registry.get_service name: :logger
|
87
87
|
@i18n = registry.get_service name: :i18n
|
88
|
-
|
88
|
+
@debug = Carioca::Registry.config.debug?
|
89
89
|
@stage = stage
|
90
90
|
@root = root
|
91
91
|
@config_file = Carioca::Services::Config::ConfigFile::new filename: config_filename
|
@@ -101,7 +101,7 @@ class Hash
|
|
101
101
|
private
|
102
102
|
def initconf
|
103
103
|
newsets = {}
|
104
|
-
@logger.debug("Carioca->Config") { @i18n.t('config.load.error', message: @config_file.error) } if @config_file.error?
|
104
|
+
@logger.debug("Carioca->Config") { @i18n.t('config.load.error', message: @config_file.error) } if @config_file.error? and @debug
|
105
105
|
@content = @config_file.data
|
106
106
|
|
107
107
|
unless @stage then
|
@@ -112,6 +112,7 @@ class Hash
|
|
112
112
|
self.deep_merge! data
|
113
113
|
|
114
114
|
end
|
115
|
+
@logger.debug("Carioca->Config") { @i18n.t('config.load.success', from: @config_file.filename) } if @debug
|
115
116
|
|
116
117
|
|
117
118
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Carioca
|
2
|
+
module Services
|
3
|
+
class Debugger
|
4
|
+
|
5
|
+
def Debugger.get(service:, trace: Carioca::Registry.config.debugger_tracer)
|
6
|
+
return ProxyDebug::new service: service, trace: trace
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class ProxyDebug
|
13
|
+
def initialize(service:, trace:)
|
14
|
+
registry = Carioca::Registry.get
|
15
|
+
@service = registry.get_service name: service
|
16
|
+
@tracers = [:output, :logger]
|
17
|
+
raise "Debugger :trace is not valid : #{trace}, must be in : #{@tracers.to_s}" unless @tracers.include? trace
|
18
|
+
@tracer = registry.get_service name: trace
|
19
|
+
@tracer_type = trace
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(methodname, *args, **keywords,&block)
|
23
|
+
|
24
|
+
trace message: "BEGIN CALL for service #{@service} "
|
25
|
+
trace message: "Method called: #{methodname} "
|
26
|
+
trace message: "args : #{args.join " "}"
|
27
|
+
trace message: "keywords : #{keywords.to_s}"
|
28
|
+
if block_given? then
|
29
|
+
trace message: "block given"
|
30
|
+
a = @service.send(methodname, *args, **keywords,&block)
|
31
|
+
else
|
32
|
+
a = @service.send(methodname, *args, **keywords)
|
33
|
+
end
|
34
|
+
trace message: "=> method returned: #{a} "
|
35
|
+
trace message: 'END CALL'
|
36
|
+
|
37
|
+
return a
|
38
|
+
end
|
39
|
+
|
40
|
+
def trace(message: )
|
41
|
+
if @tracer_type == :output then
|
42
|
+
save = @tracer.mode
|
43
|
+
@tracer.mode = :mono
|
44
|
+
@tracer.debug message
|
45
|
+
@tracer.mode = save
|
46
|
+
else
|
47
|
+
@tracer.debug("Carioca->ProxyDebug") { message }
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -70,13 +70,13 @@ module Carioca
|
|
70
70
|
MODE = [:mono, :dual]
|
71
71
|
|
72
72
|
LEVELS.each do |method|
|
73
|
-
define_method(method) do |message, session = ''|
|
74
|
-
self.display(level: method, message: message, session: session)
|
73
|
+
define_method(method) do |message, session = '', source = 'Carioca->Output'|
|
74
|
+
self.display(level: method, message: message, session: session, source: source)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
@@alias.keys.each do |method|
|
78
|
-
define_method(method) do |message, session = ''|
|
79
|
-
self.display( level: method, message: message, session: session)
|
78
|
+
define_method(method) do |message, session = '',source = 'Carioca->Output'|
|
79
|
+
self.display( level: method, message: message, session: session, source: source)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -104,14 +104,16 @@ module Carioca
|
|
104
104
|
|
105
105
|
# constructor
|
106
106
|
def initialize(level: :debug, mode: :mono , emoji: true, colors: true)
|
107
|
+
registry = Carioca::Registry.get
|
108
|
+
@logger = registry.get_service name: :logger
|
109
|
+
@i18n = registry.get_service name: :i18n
|
110
|
+
@debug = Carioca::Registry.config.debug?
|
107
111
|
self.level = level
|
108
112
|
@mode = mode
|
109
|
-
@emoji = emoji
|
113
|
+
@emoji = (check_unicode_term)? emoji : false
|
110
114
|
@color = colors
|
111
|
-
if @
|
112
|
-
|
113
|
-
@logger = registry.get_service name: :logger
|
114
|
-
end
|
115
|
+
set = []; set.push mode; set.push :emoji if @emoji ; set.push :colors if @color
|
116
|
+
@logger.debug("Carioca->Output") { @i18n.t('output.load.context', confset: set.to_s ) } if @debug
|
115
117
|
raise "Unknown output mode : #{@mode}" unless MODE.include? @mode
|
116
118
|
end
|
117
119
|
|
@@ -136,12 +138,23 @@ module Carioca
|
|
136
138
|
@active_levels.shift(LEVELS.index(level))
|
137
139
|
end
|
138
140
|
|
141
|
+
# check if unicode must be used with term ENV
|
142
|
+
# @return [Boolean]
|
143
|
+
def check_unicode_term
|
144
|
+
return false unless ENV.include? "TERM"
|
145
|
+
if ENV.values_at("LC_ALL","LC_CTYPE","LANG").compact.first.include?("UTF-8") and ENV.values_at('TERM').first.include? "xterm" then
|
146
|
+
return true
|
147
|
+
else
|
148
|
+
return false
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
139
152
|
|
140
153
|
# abstract method for log wrapper
|
141
154
|
# @param [Hash] params
|
142
155
|
# @option params [Symbol] :level, a valid level in LEVELS or ALIAS
|
143
156
|
# @option params [String] :message text
|
144
|
-
def display(level: , message: , session:)
|
157
|
+
def display(level: , message: , session:, source:)
|
145
158
|
save = message.dup
|
146
159
|
target_level = (@@alias.keys.include? level)? @@alias[level] : level
|
147
160
|
if @active_levels.include? target_level then
|
@@ -160,7 +173,8 @@ module Carioca
|
|
160
173
|
unless LEVELS.include? level
|
161
174
|
save = "#{@@emoji[level][:text]} #{save}" if @@emoji[level].include? :text
|
162
175
|
end
|
163
|
-
|
176
|
+
block = Proc::new {save}
|
177
|
+
@logger.send target_level, source, &block
|
164
178
|
end
|
165
179
|
puts message
|
166
180
|
end
|
data/samples/test.rb
CHANGED
@@ -4,7 +4,7 @@ require 'carioca'
|
|
4
4
|
|
5
5
|
Carioca::Registry.configure do |spec|
|
6
6
|
spec.filename = './config/carioca.registry'
|
7
|
-
spec.debug =
|
7
|
+
spec.debug = true
|
8
8
|
spec.init_from_file = true
|
9
9
|
# spec.log_file = '/tmp/test.rge'
|
10
10
|
spec.config_file = './config/settings.yml'
|
@@ -13,8 +13,10 @@ Carioca::Registry.configure do |spec|
|
|
13
13
|
spec.default_locale = :fr
|
14
14
|
spec.log_level = :debug
|
15
15
|
spec.output_mode = :mono
|
16
|
-
|
16
|
+
spec.output_emoji = true
|
17
|
+
spec.output_colors = true
|
17
18
|
spec.locales_load_path << Dir[File.expand_path('./config/locales') + "/*.yml"]
|
19
|
+
spec.debugger_tracer = :output
|
18
20
|
end
|
19
21
|
|
20
22
|
|
@@ -29,6 +31,12 @@ class MyService
|
|
29
31
|
def hello
|
30
32
|
logger.info(self.class.to_s) {'Hello World'}
|
31
33
|
end
|
34
|
+
|
35
|
+
def method_test(titi, tutu: )
|
36
|
+
yield if block_given?
|
37
|
+
return "result"
|
38
|
+
end
|
39
|
+
|
32
40
|
end
|
33
41
|
|
34
42
|
|
@@ -62,6 +70,7 @@ class MonAppli < Carioca::Container
|
|
62
70
|
logger.info(self.to_s) { uuid.generate }
|
63
71
|
|
64
72
|
inject service: :output
|
73
|
+
inject service: :debugger
|
65
74
|
|
66
75
|
def test2
|
67
76
|
cycle = [:unknown,:fatal,:error,:ko,:warn,:info,:item,:arrow,:scheduling,:trigger,:sending, :calling,:receive,:ok,:success,:debug,:flat]
|
@@ -83,6 +92,13 @@ class MonAppli < Carioca::Container
|
|
83
92
|
|
84
93
|
end
|
85
94
|
|
95
|
+
def test3
|
96
|
+
proxy = debugger.get service: :myservice
|
97
|
+
proxy.method_test "param", tutu: "keyword" do
|
98
|
+
puts 'titi'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
86
102
|
end
|
87
103
|
|
88
104
|
|
@@ -91,7 +107,11 @@ end
|
|
91
107
|
|
92
108
|
appli = MonAppli::new
|
93
109
|
appli.test
|
94
|
-
appli.test2
|
110
|
+
#appli.test2
|
111
|
+
appli.test3
|
112
|
+
|
113
|
+
|
114
|
+
|
95
115
|
|
96
116
|
|
97
117
|
|
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.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romain GEORGES
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-prompt
|
@@ -137,10 +137,13 @@ files:
|
|
137
137
|
- lib/carioca/helpers.rb
|
138
138
|
- lib/carioca/mixin.rb
|
139
139
|
- lib/carioca/rake/manage.rb
|
140
|
+
- lib/carioca/rake/tasks/config.tasks
|
141
|
+
- lib/carioca/rake/tasks/gem.tasks
|
140
142
|
- lib/carioca/rake/tasks/registry.tasks
|
141
143
|
- lib/carioca/registry.rb
|
142
144
|
- lib/carioca/registry_file.rb
|
143
145
|
- lib/carioca/services/config.rb
|
146
|
+
- lib/carioca/services/debug.rb
|
144
147
|
- lib/carioca/services/i18n.rb
|
145
148
|
- lib/carioca/services/init.rb
|
146
149
|
- lib/carioca/services/output.rb
|