carioca 2.0.1 → 2.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c349ebcb566a9571f7cd424b6cb3a95dd3b6871a99caf992ac04af996a35259a
4
- data.tar.gz: d4f4a5db811c978fe0390f41a757a352452c844f72775c21435c6ca1656213c1
3
+ metadata.gz: df2fae455d522ba26500abac0d203b29e1b173391b2e9eb9c27f9de83f282a55
4
+ data.tar.gz: 5e34e6d5b0eef09348906b45f6bb5c2db3d1874c6d4f3f05c5a017baca5f5da1
5
5
  SHA512:
6
- metadata.gz: d05baa11c7379fe052161140fef4a17dd075ce2998c600ad5023d947edf76769fe2020829438863bc4adf4ee4c62f50da2bfb73c2937a5837fe6a48be87de1fb
7
- data.tar.gz: 1e12daba542a3e103205f1f7f7fcd71f82a924b2e247fc48ca6a0ee0feb9e4fca85e3a22d2b6baf9c2b7c705b6ef71d0e70611cd9509928eb25584b423a8578a
6
+ metadata.gz: fad3b4fcbf8beb5811458891ad529a405fe85f19af613eb986369e51573eb87524d5849a566e7009a1a6c8d6f142e5a6f60a5e3ce82f9b60e82cabcfc814d02b
7
+ data.tar.gz: 1049e060ed5326a3f67acea98258fca5c2880f46ae1edc3b1d08070e7012d374d975c062e076adfb2a127e0f3027ba0117b57ba97bc06f43d1ab3f904f63a0a4
data/Gemfile CHANGED
@@ -2,8 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rake", "~> 13.0"
6
- gem "rspec", "~> 3.0"
7
- gem 'i18n', "~> 1.10"
8
- gem 'locale', "~> 2.1"
9
- gem "deep_merge", "~> 1.2"
5
+
6
+
data/Gemfile.lock CHANGED
@@ -1,13 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- carioca (2.0.0)
4
+ carioca (2.0.4)
5
+ deep_merge (~> 1.2)
6
+ i18n (~> 1.10)
7
+ locale (~> 2.1)
8
+ pastel (~> 0.8.0)
5
9
  tty-prompt (~> 0.23.1)
6
10
 
7
11
  GEM
8
12
  remote: https://rubygems.org/
9
13
  specs:
14
+ concurrent-ruby (1.1.9)
15
+ deep_merge (1.2.2)
10
16
  diff-lcs (1.5.0)
17
+ i18n (1.10.0)
18
+ concurrent-ruby (~> 1.0)
19
+ locale (2.1.3)
11
20
  pastel (0.8.0)
12
21
  tty-color (~> 0.5)
13
22
  rake (13.0.6)
data/README.md CHANGED
@@ -1,23 +1,173 @@
1
1
  # Carioca
2
2
 
3
+ Carioca : Container And Registry with Inversion Of Control for your Applications
4
+
5
+ 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
3
6
  ## Installation
4
7
 
5
- Add this line to your application's Gemfile:
8
+ Install it yourself as:
9
+
10
+ $ gem install carioca
11
+
12
+ ## Usage
13
+
14
+
15
+ ### Basic usage
16
+
17
+ Create you own gem :
18
+
19
+ $ bundle gem yourgem
20
+ $ cd yourgem
21
+ $ vi yourgem.gemspec
22
+
23
+ check all the TODO in your gemspec, specify concretly you Gem specification, add the following line :
6
24
 
7
25
  ```ruby
8
- gem 'carioca'
26
+ spec.add_dependency "carioca", "~> 2.0"
9
27
  ```
28
+ and after :
10
29
 
11
- And then execute:
30
+ $ bundle add carioca
31
+ $ mkdir -p config/locales
12
32
 
13
- $ bundle install
33
+ Edit the Rakefil, and add the following line :
14
34
 
15
- Or install it yourself as:
35
+ ```ruby
36
+ require "carioca/rake/manage"
37
+ ```
38
+ Verify, all is right with :
16
39
 
17
- $ gem install carioca
40
+ $ rake -T
41
+ rake build # Build sample-0.1.0.gem into the pkg directory
42
+ rake carioca:gem:init_path # prepare Gem vitals path for Carioca
43
+ rake carioca:registry:add_service # Adding service to Carioca Registry file
44
+ rake carioca:services:config:init # Initialise Service configuration file ./config/settings.yml file
45
+ rake clean # Remove any temporary products
46
+ rake clobber # Remove any generated files
47
+ rake install # Build and install sample-0.1.0.gem into system gems
48
+ rake install:local # Build and install sample-0.1.0.gem into system gems without network access
49
+ rake release[remote] # Create tag v0.1.0 and build and push sample-0.1.0.gem to Set to 'http://mygemserver.com'
50
+ rake spec # Run RSpec code examples
18
51
 
19
- ## Usage
52
+ You could now initialize the Carioca registry following the wizard, with (sample with a simple UUID generator gem):
53
+
54
+ $ rake carioca:gem:init_path
55
+ Carioca : Initialising vitals gem path : done
56
+ $ rake carioca:registry:add_service
57
+ Carioca : registering service :
58
+ Registry File path ? ./config/carioca.registry
59
+ Service name ? uuid
60
+ Choose the service type ? gem
61
+ Description ? The uuid service
62
+ Service [uuid] inline Proc Ruby code ? UUID
63
+ Give the Rubygem name ? uuid
64
+ Did this service have dependencies ? no
65
+
66
+ => Service : uuid
67
+ Definition
68
+ * type: gem
69
+ * description: The uuid service
70
+ * service: UUID
71
+ * resource: uuid
72
+ Is it correct ? Yes
73
+ Carioca : Registry saving : done
74
+
75
+ This will initiate a Carioca Registry (YAML file, the format will be describe after, the wizard support all type of services, managed by Carioca, all keys are Symbols):
76
+
77
+ $ cat config/carioca.registry
78
+ ---
79
+ :uuid:
80
+ :type: :gem
81
+ :description: The uuid service
82
+ :service: UUID
83
+ :resource: uuid
84
+
85
+ Now your are ready to use Carioca :
86
+
87
+ In this sample, we are going th create a demo command.
88
+ Firstly, we have to configure a basic usage of Carioca, this could be made in the lib path, in the root gem library.
89
+
90
+ $ emacs lib/yourgem.rb
91
+
92
+ content of the destination file
93
+
94
+ ```ruby
95
+
96
+ # frozen_string_literal: true
97
+
98
+ require_relative "yourgem/version"
99
+ require 'carioca'
100
+
101
+
102
+ Carioca::Registry.configure do |spec|
103
+ spec.debug = true
104
+ end
105
+
106
+ module Yourgem
107
+ class Error < StandardError; end
108
+
109
+ class YourgemCMD < Carioca::Container
110
+ def test
111
+ logger.info(self.to_s) { "Log me as an instance method" }
112
+ logger.warn(self.class.to_s) {"Give me an UUID : " + uuid.generate}
113
+ end
114
+
115
+ inject service: :uuid
116
+
117
+ logger.info(self.to_s) { "Log me as class method" }
118
+
119
+ end
120
+
121
+ end
122
+
123
+ ```
124
+
125
+ $ emacs exe/yourgem_cmd
126
+
127
+ content of the file
128
+
129
+ ```ruby
130
+ require 'yourgem'
131
+
132
+ yourgem_cmd = Yourgem::YourgemCMD::new
133
+ yourgem_cmd.test
134
+ ```
135
+
136
+ After this, don't forget to stage new files, and you could build & install the gem before running your new command for the first time :
137
+
138
+ $ git add config/ exe/
139
+ $ rake install && yourgem_cmd
140
+ yourgem 0.1.0 built to pkg/yourgem-0.1.0.gem.
141
+ yourgem (0.1.0) installed.
142
+ D, [2022-03-07T01:06:20.337961 #21513] DEBUG -- Carioca: Preloaded service :i18n on locale : en
143
+ D, [2022-03-07T01:06:20.338020 #21513] DEBUG -- Carioca: Preloaded service :logger ready on STDOUT
144
+ D, [2022-03-07T01:06:20.338037 #21513] DEBUG -- Carioca: Initializing Carioca registry
145
+ D, [2022-03-07T01:06:20.338049 #21513] DEBUG -- Carioca: Preparing builtins services
146
+ D, [2022-03-07T01:06:20.338079 #21513] DEBUG -- Carioca: Adding service configuration
147
+ D, [2022-03-07T01:06:20.338107 #21513] DEBUG -- Carioca: Adding service i18n
148
+ D, [2022-03-07T01:06:20.338133 #21513] DEBUG -- Carioca: Adding service output
149
+ D, [2022-03-07T01:06:20.338156 #21513] DEBUG -- Carioca: Adding service debugger
150
+ D, [2022-03-07T01:06:20.338191 #21513] DEBUG -- Carioca: Initializing registry from file : ./config/carioca.registry
151
+ D, [2022-03-07T01:06:20.338312 #21513] DEBUG -- Carioca: Adding service uuid
152
+ D, [2022-03-07T01:06:20.338333 #21513] DEBUG -- Carioca: Registry initialized successfully
153
+ I, [2022-03-07T01:06:20.338340 #21513] INFO -- Sample::YourGemCMD: Log me as class method
154
+ I, [2022-03-07T01:06:20.338351 #21513] INFO -- #<Sample::YourGemCMD:0x0000000148270698>: Log me as an instance method
155
+ D, [2022-03-07T01:06:20.338381 #21513] DEBUG -- Carioca: Starting service uuid
156
+ W, [2022-03-07T01:06:20.353142 #21513] WARN -- Sample::YourGemCMD: Give me an UUID : 574cc860-7fd8-013a-2323-1e00870a7189
157
+
158
+ You could see, somme interesting things :
159
+ * Carioca have an internationalisation service (this service will be explain in detail after):
160
+ * default configured on :en locale
161
+ * must be in French (:fr) or English (:en), other traductions are welcome
162
+ * Carioca have a builtin logger service using regular Logger from Stdlib (also explain in detail in this document)
163
+ * default logging on STDOUT, but could be redirect in the configure bloc
164
+ * Carioca give us some usefull traces in debug
165
+ * Carioca come with a Container Class Template
166
+ * the Container automatically inject :logger, :i18n and a :configuration service (explain in detail after)
167
+ * the Container provide a class method macro :inject
168
+ * this macro give a way to use other services defined in the registry file (service could be register inline, presented after)
20
169
 
170
+ ## A step further
21
171
 
22
172
 
23
173
  ## Development
data/carioca.gemspec CHANGED
@@ -13,9 +13,9 @@ Gem::Specification.new do |spec|
13
13
 
14
14
  spec.license = "BSD-3-Clause"
15
15
 
16
- spec.summary = %q{Carioca : Configuration Agent and Registry with Inversion Of Control for your Applications}
16
+ spec.summary = %q{Carioca : Container And Registry with Inversion Of Control for your Applications}
17
17
  spec.homepage = %q{https://github.com/Ultragreen/carioca}
18
- spec.description = %q{Carioca : provide a full IoC light Container for designing your applications}
18
+ spec.description = %q{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}
19
19
 
20
20
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
21
21
 
@@ -36,6 +36,11 @@ Gem::Specification.new do |spec|
36
36
  # Uncomment to register a new dependency of your gem
37
37
  spec.add_dependency "tty-prompt", "~>0.23.1"
38
38
  spec.add_dependency "pastel", "~>0.8.0"
39
+ spec.add_dependency 'i18n', "~> 1.10"
40
+ spec.add_dependency 'locale', "~> 2.1"
41
+ spec.add_dependency "deep_merge", "~> 1.2"
42
+ spec.add_development_dependency "rake", "~> 13.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
39
44
 
40
45
 
41
46
  end
@@ -7,9 +7,17 @@ en:
7
7
  notify:
8
8
  locale: "Preloaded service :i18n on locale : %{loc}"
9
9
  logger: "Preloaded service :logger ready on %{target}"
10
+ useless_entry: "Useless entry in registry (builtin service) %{altered} in %{filename}"
10
11
  init:
11
12
  carioca: "Initializing Carioca registry"
12
13
  builtins: "Preparing builtins services"
13
14
  registry:
14
- processing: "Initializing registry from file : %{filename}"
15
- success: "Registry initialized successfully"
15
+ processing: "Initializing registry from file : %{filename}"
16
+ success: "Registry initialized successfully"
17
+ config:
18
+ load:
19
+ error: "Config file ignored, error : %{message}"
20
+ success: "Configuration Service successfully initialized from : %{from}"
21
+ output:
22
+ load:
23
+ context: "Output service initialized in mode : %{confset}"
@@ -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,10 +2,10 @@ 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
6
- attr_accessor :config_file, :config_root, :environment, :supported_environment
7
- attr_writer :debug, :init_from_file
8
- attr_reader :log_file, :locales_availables
5
+ attr_accessor :filename, :name, :builtins, :log_target, :default_locale, :locales_load_path, :debugger_tracer
6
+ attr_accessor :config_file, :config_root, :environment, :supported_environment, :output_mode, :log_level
7
+ attr_writer :init_from_file, :output_colors, :output_emoji
8
+ attr_reader :log_file, :locales_availables, :debug
9
9
  def initialize
10
10
  @init_from_file = true
11
11
  @filename = DEFAULT_REGISTRY_FILE.dup
@@ -13,6 +13,7 @@ module Carioca
13
13
  @name = 'Carioca'
14
14
  @builtins = BUILTINS
15
15
  @log_file = ''
16
+ @log_level = DEFAULT_LOG_LEVEL.dup
16
17
  @config_file = DEFAULT_CONFIG_FILE.dup
17
18
  @environment = DEFAULT_ENVIRONMENT.dup
18
19
  @config_root = DEFAULT_CONFIG_ROOT.dup
@@ -20,17 +21,35 @@ module Carioca
20
21
  @supported_environment = DEFAULT_ENVIRONMENTS_LIST.dup
21
22
  @default_locale = DEFAULT_LOCALE
22
23
  @locales_availables = []
24
+ @output_mode = DEFAULT_OUTPUT_MODE.dup
25
+ @output_colors = DEFAULT_COLORS_STATUS.dup
26
+ @output_emoji = DEFAULT_EMOJI_STATUS.dup
23
27
  path = search_file_in_gem('carioca',"config/locales")
24
28
  @locales_load_path = Dir[File.expand_path(path) + "/*.yml"]
25
29
  Dir[path + '/*.yml'].sort.each do |file|
26
30
  @locales_availables.push File::basename(file,'.yml').to_sym
27
31
  end
32
+ @debugger_tracer = DEFAULT_DEBUGGER_TRACER.dup
33
+ end
34
+
35
+ def debug=(state)
36
+ @debug = state
37
+ @log_level = :info if @debug == false and @log_level == :debug
38
+ @log_level = :debug if @debug == true
28
39
  end
29
40
 
30
41
  def debug?
31
42
  return @debug
32
43
  end
33
44
 
45
+ def output_colors?
46
+ return @output_colors
47
+ end
48
+
49
+ def output_emoji?
50
+ return @output_emoji
51
+ end
52
+
34
53
  def init_from_file?
35
54
  return @init_from_file
36
55
  end
@@ -1,7 +1,7 @@
1
1
  module Carioca
2
2
  module Constants
3
3
 
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.4'
5
5
  DEFAULT_REGISTRY_FILE = './config/carioca.registry'
6
6
  DEFAULT_CONFIG_FILE = './config/settings.yml'
7
7
  DEFAULT_ENVIRONMENT = :development
@@ -9,6 +9,14 @@ module Carioca
9
9
  DEFAULT_LOCALE = :en
10
10
 
11
11
 
12
+ DEFAULT_OUTPUT_MODE = :mono
13
+ DEFAULT_EMOJI_STATUS = true
14
+ DEFAULT_COLORS_STATUS = true
15
+ DEFAULT_LOG_LEVEL = :info
16
+
17
+
18
+ DEFAULT_DEBUGGER_TRACER = :output
19
+
12
20
  # service definitions specs
13
21
  SERVICES_MANDATORY_SPECS = {type: Symbol, service: String}
14
22
  SERVICES_FULL_LIST_SPECS = SERVICES_MANDATORY_SPECS.merge({depends: Array, description: String, resource: String })
@@ -38,6 +46,21 @@ module Carioca
38
46
  default_locale: Carioca::Registry.config.default_locale,
39
47
  load_path: Carioca::Registry.config.locales_load_path,
40
48
  locales_availables: Carioca::Registry.config.locales_availables)"
49
+ },
50
+ output:{
51
+ type: :internal,
52
+ description: "The Output serice of Carioca",
53
+ service: "Carioca::Services::Output::Provider::new(
54
+ mode: Carioca::Registry.config.output_mode,
55
+ emoji: Carioca::Registry.config.output_emoji?,
56
+ colors: Carioca::Registry.config.output_colors?,
57
+ level: Carioca::Registry.config.log_level
58
+ )"
59
+ },
60
+ debugger:{
61
+ type: :internal,
62
+ description: "The Debugger Service of Carioca",
63
+ service: "Carioca::Services::Debugger"
41
64
  }
42
65
  }
43
66
 
@@ -6,12 +6,13 @@ require 'rubygems'
6
6
  require 'i18n'
7
7
  require 'locale'
8
8
  require 'deep_merge'
9
+ require 'pastel'
9
10
 
11
+ require_relative 'helpers'
10
12
  require_relative 'constants'
11
13
  require_relative 'validator'
12
14
  require_relative 'mixin'
13
15
  require_relative 'container'
14
- require_relative 'helpers'
15
16
  require_relative 'configuration'
16
17
 
17
18
  require_relative 'registry_file'
@@ -2,6 +2,9 @@
2
2
  require 'rake'
3
3
  require 'rubygems'
4
4
  require 'carioca'
5
+ require "tty-prompt"
6
+ require "pastel"
7
+
5
8
 
6
9
  $VERBOSE = nil
7
10
  if Gem::Specification.respond_to?(:find_by_name)
@@ -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
- puts 'Carioca : interrupted'
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
- puts "Carioca: Can't save : #{e}"
52
+ print pastel.red "failed"
53
+ puts " error : #{e}"
48
54
  exit 10
49
55
  end
50
56
 
51
- puts "Carioca : Registry saved"
57
+ puts pastel.green "done"
52
58
  else
53
- puts 'Carioca : Nothing saved'
59
+ puts pastel.yellow 'canceled'
54
60
  end
55
61
  end
56
62
  end
57
- end
63
+
64
+ end
@@ -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|
@@ -59,7 +59,8 @@ module Carioca
59
59
  conf_logger = @@config.builtins[:logger]
60
60
  conf_logger[:service] = @@config.log_target
61
61
  add service: :logger, definition: @@config.builtins[:logger], skip_validation: true
62
- get_service name: :logger
62
+ log = get_service name: :logger
63
+ log.level = @@config.log_level
63
64
  end
64
65
 
65
66
  def initialize
@@ -81,11 +82,11 @@ module Carioca
81
82
  def open_registry_file
82
83
  debug message: i18n.t('init.registry.processing', filename: @@config.filename) if @@config.debug?
83
84
  registry_file = Carioca::RegistryFile::new filename: @@config.filename
84
- debug message: i18n.t('notify.useless_entry', altered: registry_file.altered.to_s, filename: @@config.filename ) if registry_file.altered? and @@config.debug?
85
+ debug message: i18n.t('notify.useless_entry', altered: registry_file.altered.to_s, file_name: @@config.filename ) if registry_file.altered? and @@config.debug?
85
86
  registry_file.validated.each do |service,spec|
86
87
  add service: service, definition: spec
87
88
  end
88
- debug message: i18n.t('init.registry.processing') if @@config.debug?
89
+ debug message: i18n.t('init.registry.success') if @@config.debug?
89
90
  end
90
91
 
91
92
 
@@ -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
@@ -0,0 +1,189 @@
1
+ module Carioca
2
+ module Services
3
+ module Output
4
+
5
+ module FormatsMapping
6
+ COLORS = {
7
+ :unknown => :red,
8
+ :fatal => :red,
9
+ :error => :red,
10
+ :ko => :yellow,
11
+ :warn => :yellow,
12
+ :item => :white,
13
+ :arrow => :white,
14
+ :sending => :white,
15
+ :calling => :white,
16
+ :scheduling => :white,
17
+ :trigger => :white,
18
+ :receive => :white,
19
+ :info => :cyan,
20
+ :ok => :green,
21
+ :success => :green,
22
+ :debug => :magenta,
23
+ :flat => :white
24
+ }
25
+
26
+ EMOJI = {
27
+ :unknown => {:value => "\u{1F4A5}", :alt => '[!!]', :text => "(UNKNOWN)"},
28
+ :fatal => {:value => "\u{26D4}", :alt => '[!!]', :text => "(FATAL)"},
29
+ :error => {:value => "\u{1F6AB}", :alt => '[!]', :text => "(ERROR)"},
30
+ :ko => {:value => "\u{1F44E}", :alt => '[-]', :text => "(KO)"},
31
+ :warn => {:value => "\u{26A0}", :alt => '[/!\]', :text => "(WARNING)"},
32
+ :info => {:value => "\u{2139}", :alt => '[i]', :text => "(INFO)"},
33
+ :item => {:value => " \u{1F539}", :alt => '', :text => " *"},
34
+ :arrow => {:value => " \u{27A1}", :alt => '', :text => " =>"},
35
+ :calling => {:value => "\u{1F4DE}" , :alt => '[C]', :text => "(CALLING)"},
36
+ :scheduling => {:value => "\u{23F2}" , :alt => '[S]', :text => "{SCHEDULING})"},
37
+ :trigger => {:value => "\u{23F0}", :alt => '[T]', :text => "(TRIGGER)"},
38
+ :sending => {:value => "\u{1F4E4}", :alt => '[>]', :text => "(SENDING)"},
39
+ :receive => {:value => "\u{1F4E5}" , :alt => '[<]', :text => "(RECEIVE)"},
40
+ :ok => {:value => "\u{1F44D}" , :alt => '[+]', :text => "(OK)"},
41
+ :success => {:value => "\u{1F4AA}" , :alt => '[+]', :text => "(SUCCESS)"},
42
+ :debug => {:value => "\u{1F41B}" , :alt => '[D]', :text => "(DEBUG)"},
43
+ :flat => {:value => "", :alt => ""}
44
+ }
45
+ LEVELS = [:debug, :info, :warn, :error, :fatal, :unknown ]
46
+ ALIAS = {
47
+ :flat => :info,
48
+ :item => :info,
49
+ :ok => :info,
50
+ :ko => :error,
51
+ :trigger => :info,
52
+ :scheduling => :info,
53
+ :arrow => :info,
54
+ :sending => :info,
55
+ :calling => :info,
56
+ :receive => :info,
57
+ :success => :info
58
+
59
+ }
60
+ end
61
+ class Provider
62
+ include FormatsMapping
63
+
64
+ attr_accessor :mode, :emoji, :color
65
+
66
+ @@alias = ALIAS.dup
67
+ @@colors = COLORS.dup
68
+ @@emoji = EMOJI.dup
69
+
70
+ MODE = [:mono, :dual]
71
+
72
+ LEVELS.each do |method|
73
+ define_method(method) do |message, session = '', source = 'Carioca->Output'|
74
+ self.display(level: method, message: message, session: session, source: source)
75
+ end
76
+ end
77
+ @@alias.keys.each do |method|
78
+ define_method(method) do |message, session = '',source = 'Carioca->Output'|
79
+ self.display( level: method, message: message, session: session, source: source)
80
+ end
81
+ end
82
+
83
+ def map_color(color: , analias: )
84
+ raise "Color must be a Symbol" unless color.class == Symbol
85
+ raise "Missing alias : #{analias}" unless LEVELS.include? analias
86
+ @@alias[analias] = color
87
+ end
88
+
89
+ def map_emoji(emoji: , analias: )
90
+ raise "Emoji must be a String" unless color.class == String
91
+ raise "Missing alias : #{analias}" unless LEVELS.include? analias
92
+ @@alias[analias] = emoji
93
+ end
94
+
95
+
96
+ def add_alias(newalias:, level:)
97
+ raise "Alias must be a Symbol" unless newalias.class == Symbol
98
+ raise "Bad Level : #{level}" unless LEVELS.include? level
99
+ self.class.define_method(newalias) do |message, session = ''|
100
+ self.display({ level: newalias, message: message, session: session})
101
+ end
102
+ end
103
+
104
+
105
+ # constructor
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?
111
+ self.level = level
112
+ @mode = mode
113
+ @emoji = (check_unicode_term)? emoji : false
114
+ @color = colors
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
117
+ raise "Unknown output mode : #{@mode}" unless MODE.include? @mode
118
+ end
119
+
120
+ # build a session number
121
+ # @return [String] Session number
122
+ def get_session
123
+ return "#{Time.now.to_i.to_s}#{rand(999)}"
124
+ end
125
+
126
+ # getter for the current level
127
+ # @return [Symbol] level
128
+ def level
129
+ return @active_levels.first
130
+ end
131
+
132
+ # virtual setter for level, set the current level
133
+ # @raise a badLevel in case of bad level
134
+ # @param [Symbol] level
135
+ def level=(level)
136
+ raise "Bad Level : #{level}" unless LEVELS.include? level
137
+ @active_levels = LEVELS.dup
138
+ @active_levels.shift(LEVELS.index(level))
139
+ end
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
+
152
+
153
+ # abstract method for log wrapper
154
+ # @param [Hash] params
155
+ # @option params [Symbol] :level, a valid level in LEVELS or ALIAS
156
+ # @option params [String] :message text
157
+ def display(level: , message: , session:, source:)
158
+ save = message.dup
159
+ target_level = (@@alias.keys.include? level)? @@alias[level] : level
160
+ if @active_levels.include? target_level then
161
+ if @color then
162
+ pastel = ::Pastel.new
163
+ message = pastel.send @@colors[level], message
164
+ end
165
+ if @@emoji.include? level
166
+ pattern = (@emoji)? @@emoji[level][:value] : @@emoji[level][:alt]
167
+ pattern = "#{pattern} #{@@emoji[level][:text]}" if @@emoji[level].include? :text and !@emoji
168
+ message = pattern + " " + message unless pattern.empty?
169
+ end
170
+ if @mode == :dual
171
+
172
+ pattern = @@emoji[level][:alt]
173
+ unless LEVELS.include? level
174
+ save = "#{@@emoji[level][:text]} #{save}" if @@emoji[level].include? :text
175
+ end
176
+ block = Proc::new {save}
177
+ @logger.send target_level, source, &block
178
+ end
179
+ puts message
180
+ end
181
+ end
182
+
183
+ end
184
+
185
+
186
+ end
187
+ end
188
+ end
189
+
data/samples/test.rb CHANGED
@@ -11,7 +11,12 @@ Carioca::Registry.configure do |spec|
11
11
  spec.config_root = :monappli
12
12
  spec.environment = :development
13
13
  spec.default_locale = :fr
14
+ spec.log_level = :debug
15
+ spec.output_mode = :mono
16
+ spec.output_emoji = true
17
+ spec.output_colors = true
14
18
  spec.locales_load_path << Dir[File.expand_path('./config/locales') + "/*.yml"]
19
+ spec.debugger_tracer = :output
15
20
  end
16
21
 
17
22
 
@@ -26,6 +31,12 @@ class MyService
26
31
  def hello
27
32
  logger.info(self.class.to_s) {'Hello World'}
28
33
  end
34
+
35
+ def method_test(titi, tutu: )
36
+ yield if block_given?
37
+ return "result"
38
+ end
39
+
29
40
  end
30
41
 
31
42
 
@@ -58,13 +69,49 @@ class MonAppli < Carioca::Container
58
69
  inject service: :myservice
59
70
  logger.info(self.to_s) { uuid.generate }
60
71
 
72
+ inject service: :output
73
+ inject service: :debugger
74
+
75
+ def test2
76
+ cycle = [:unknown,:fatal,:error,:ko,:warn,:info,:item,:arrow,:scheduling,:trigger,:sending, :calling,:receive,:ok,:success,:debug,:flat]
77
+ cycle.each do |verb|
78
+ output.send verb, verb.to_s
79
+ end
80
+ output.color = false
81
+ cycle.each do |verb|
82
+ output.send verb, verb.to_s
83
+ end
84
+ output.emoji = false
85
+ cycle.each do |verb|
86
+ output.send verb, verb.to_s
87
+ end
88
+ output.color = true
89
+ cycle.each do |verb|
90
+ output.send verb, verb.to_s
91
+ end
92
+
93
+ end
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
+
61
102
  end
62
103
 
63
104
 
64
105
 
65
106
 
107
+
66
108
  appli = MonAppli::new
67
109
  appli.test
110
+ #appli.test2
111
+ appli.test3
112
+
113
+
114
+
68
115
 
69
116
 
70
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.1
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-04 00:00:00.000000000 Z
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-prompt
@@ -38,7 +38,79 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.8.0
41
- description: 'Carioca : provide a full IoC light Container for designing your applications'
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: locale
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: deep_merge
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: 'Carioca 2: is a complete rewrite who provide a full IoC/DI light Container
112
+ and a services registry, build with logs, config and Internationalization facilities
113
+ for designing your applications'
42
114
  email:
43
115
  - romain@ultragreen.net
44
116
  executables: []
@@ -65,12 +137,16 @@ files:
65
137
  - lib/carioca/helpers.rb
66
138
  - lib/carioca/mixin.rb
67
139
  - lib/carioca/rake/manage.rb
140
+ - lib/carioca/rake/tasks/config.tasks
141
+ - lib/carioca/rake/tasks/gem.tasks
68
142
  - lib/carioca/rake/tasks/registry.tasks
69
143
  - lib/carioca/registry.rb
70
144
  - lib/carioca/registry_file.rb
71
145
  - lib/carioca/services/config.rb
146
+ - lib/carioca/services/debug.rb
72
147
  - lib/carioca/services/i18n.rb
73
148
  - lib/carioca/services/init.rb
149
+ - lib/carioca/services/output.rb
74
150
  - lib/carioca/validator.rb
75
151
  - samples/Rakefile
76
152
  - samples/config/carioca.registry
@@ -87,7 +163,7 @@ metadata:
87
163
  homepage_uri: https://github.com/Ultragreen/carioca
88
164
  source_code_uri: https://github.com/Ultragreen/carioca
89
165
  changelog_uri: https://github.com/Ultragreen/carioca
90
- post_install_message:
166
+ post_install_message:
91
167
  rdoc_options: []
92
168
  require_paths:
93
169
  - lib
@@ -102,9 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
178
  - !ruby/object:Gem::Version
103
179
  version: '0'
104
180
  requirements: []
105
- rubygems_version: 3.1.2
106
- signing_key:
181
+ rubygems_version: 3.2.3
182
+ signing_key:
107
183
  specification_version: 4
108
- summary: 'Carioca : Configuration Agent and Registry with Inversion Of Control for
109
- your Applications'
184
+ summary: 'Carioca : Container And Registry with Inversion Of Control for your Applications'
110
185
  test_files: []