carioca 2.0.12 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +7 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +10 -1
- data/LICENSE.txt +21 -0
- data/README.md +562 -9
- data/Rakefile +5 -0
- data/VERSION +1 -1
- data/assets/images/carioca_output_emoji_colors.PNG +0 -0
- data/assets/images/carioca_output_emoji_no_colors.PNG +0 -0
- data/assets/images/carioca_output_no_emoji_colors.PNG +0 -0
- data/assets/images/carioca_output_no_emoji_no_colors.PNG +0 -0
- data/assets/images/description_carioca.png +0 -0
- data/assets/images/description_configuration_carioca.png +0 -0
- data/assets/images/description_container_carioca.png +0 -0
- data/assets/images/description_registry_carioca.png +0 -0
- data/assets/images/description_services_carioca.png +0 -0
- data/assets/images/logo_carioca_full_large.png +0 -0
- data/assets/images/logo_carioca_full_small.png +0 -0
- data/assets/images/logo_carioca_light_small.png +0 -0
- data/carioca.gemspec +2 -0
- data/config/locales/en.yml +34 -0
- data/config/locales/fr.yml +35 -1
- data/lib/carioca/configuration.rb +6 -2
- data/lib/carioca/constants.rb +38 -1
- data/lib/carioca/dependencies.rb +13 -0
- data/lib/carioca/services/config.rb +1 -1
- data/lib/carioca/services/finisher.rb +121 -0
- data/lib/carioca/services/sanitycheck.rb +140 -0
- data/lib/carioca/services/securestore.rb +81 -0
- data/lib/carioca/services/setup.rb +83 -0
- data/lib/carioca/services/toolbox.rb +104 -0
- data/samples/config/carioca.registry +0 -15
- data/samples/config/locales/en.yml +2 -1
- data/samples/config/settings.yml +29 -6
- data/samples/test.rb +111 -11
- metadata +48 -2
data/README.md
CHANGED
@@ -22,8 +22,8 @@ Carioca 2: is a complete rewrite who provide a full IoC/DI light Container and a
|
|
22
22
|
<noscript><a href="https://liberapay.com/ruydiaz/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a></noscript>
|
23
23
|
|
24
24
|
|
25
|
-
![
|
26
|
-
_Container And Registry with Inversion Of Control for your
|
25
|
+
![Carioca logo](assets/images/logo_carioca_full_small.png)
|
26
|
+
_Container And Registry with Inversion Of Control for your Applications_
|
27
27
|
|
28
28
|
|
29
29
|
## Installation
|
@@ -32,11 +32,28 @@ Install it yourself as:
|
|
32
32
|
|
33
33
|
$ gem install carioca
|
34
34
|
|
35
|
+
## Principe
|
36
|
+
|
37
|
+
![Carioca synoptic](assets/images/description_carioca.png)
|
38
|
+
|
35
39
|
## Usage
|
36
40
|
|
37
41
|
|
38
42
|
### Basic usage
|
39
43
|
|
44
|
+
|
45
|
+
|
46
|
+
#### Principe
|
47
|
+
|
48
|
+
![Carioca synoptic](assets/images/description_container_carioca.png)
|
49
|
+
|
50
|
+
* Carioca come with a Container Class Template
|
51
|
+
* the Container automatically inject :logger, :i18n and a :configuration service (explain in detail after)
|
52
|
+
* the Container provide a class method macro :inject
|
53
|
+
* this macro give a way to use other services defined in the registry file (service could be register inline, presented after)
|
54
|
+
|
55
|
+
### Beginning usecase new gem
|
56
|
+
|
40
57
|
Create you own gem :
|
41
58
|
|
42
59
|
$ bundle gem yourgem
|
@@ -53,7 +70,7 @@ and after :
|
|
53
70
|
$ bundle add carioca
|
54
71
|
$ mkdir -p config/locales
|
55
72
|
|
56
|
-
Edit the
|
73
|
+
Edit the Rakefile, and add the following line :
|
57
74
|
|
58
75
|
```ruby
|
59
76
|
require "carioca/rake/manage"
|
@@ -156,7 +173,7 @@ yourgem_cmd = Yourgem::YourgemCMD::new
|
|
156
173
|
yourgem_cmd.test
|
157
174
|
```
|
158
175
|
|
159
|
-
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 :
|
176
|
+
**Note** : 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 :
|
160
177
|
|
161
178
|
$ git add config/ exe/
|
162
179
|
$ rake install && yourgem_cmd
|
@@ -178,6 +195,10 @@ After this, don't forget to stage new files, and you could build & install the g
|
|
178
195
|
D, [2022-03-07T01:06:20.338381 #21513] DEBUG -- Carioca: Starting service uuid
|
179
196
|
W, [2022-03-07T01:06:20.353142 #21513] WARN -- Sample::YourGemCMD: Give me an UUID : 574cc860-7fd8-013a-2323-1e00870a7189
|
180
197
|
|
198
|
+
|
199
|
+
|
200
|
+
## Builtins services
|
201
|
+
|
181
202
|
You could see, somme interesting things :
|
182
203
|
* Carioca have an internationalisation service (this service will be explain in detail after):
|
183
204
|
* default configured on :en locale
|
@@ -185,12 +206,544 @@ You could see, somme interesting things :
|
|
185
206
|
* Carioca have a builtin logger service using regular Logger from Stdlib (also explain in detail in this document)
|
186
207
|
* default logging on STDOUT, but could be redirect in the configure bloc
|
187
208
|
* Carioca give us some usefull traces in debug
|
188
|
-
* Carioca
|
189
|
-
|
190
|
-
|
191
|
-
|
209
|
+
* Carioca provide a complete solution to manage CLI output.
|
210
|
+
|
211
|
+
### Description Registry
|
212
|
+
|
213
|
+
|
214
|
+
![Carioca synoptic](assets/images/description_registry_carioca.png)
|
215
|
+
|
216
|
+
### Description of services
|
217
|
+
|
218
|
+
![Carioca synoptic](assets/images/description_services_carioca.png)
|
219
|
+
|
220
|
+
### Generic Usage
|
221
|
+
|
222
|
+
#### Usage with the Carioca::Container template class
|
223
|
+
|
224
|
+
Considering an existing service named : my_service with a unique method named a_method
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
|
228
|
+
# frozen_string_literal: true
|
229
|
+
|
230
|
+
require 'carioca'
|
231
|
+
|
232
|
+
class MyObject < Carioca::Container
|
233
|
+
|
234
|
+
inject service: my_service
|
235
|
+
|
236
|
+
def initialize
|
237
|
+
my_service.a_method
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
my_service.a_method
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
```
|
249
|
+
the mAcro inject is already mixed in Carioca::Container
|
250
|
+
|
251
|
+
**Note** : Service cloud be used on class method wrapping and instance mecthode.
|
252
|
+
|
253
|
+
#### Usage without Carioca::Container heritage
|
254
|
+
|
255
|
+
Considering an existing service named : my_service with a unique method named a_method
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
|
259
|
+
require 'carioca'
|
260
|
+
|
261
|
+
class MyObject
|
262
|
+
|
263
|
+
extend Carioca::Injector
|
264
|
+
inject service: my_service
|
265
|
+
|
266
|
+
def initialize
|
267
|
+
my_service.a_method
|
268
|
+
end
|
269
|
+
|
270
|
+
my_service.a_method
|
271
|
+
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
276
|
+
```
|
277
|
+
|
278
|
+
### Service I18n
|
279
|
+
|
280
|
+
the I18n is loaded by default with Carioca::Container, and loaded as dependency when using others builtin services.
|
281
|
+
It's a fondation service for Carioca.
|
282
|
+
|
283
|
+
For this exemple, we show you an explicit inject of I18n
|
284
|
+
|
285
|
+
**Note** : I18n povide internationalisation for Carioca itself AND for self made services and more
|
286
|
+
|
287
|
+
**Note** : You could create all your locales files for any languages speciif to your application :
|
288
|
+
- in $PWD/config/locales/*.yml
|
289
|
+
- in $GEMPATH/config/locales/*.yml
|
290
|
+
|
291
|
+
**Note** : If you create locales in other languages than :en or :fr (atcually the 2 supported by Carioca), for internals output (Carioca itself logs, outputs or debugs), carioca fallback on default locales defined in configuration (default :en).
|
292
|
+
|
293
|
+
|
294
|
+
Considering a locale file en.yml in config/locales/ like :
|
295
|
+
|
296
|
+
```yaml
|
297
|
+
|
298
|
+
en:
|
299
|
+
sample:
|
300
|
+
string: "Display %{myvar}"
|
301
|
+
|
302
|
+
|
303
|
+
```
|
304
|
+
|
305
|
+
with the current code :
|
306
|
+
|
307
|
+
```ruby
|
308
|
+
|
309
|
+
require 'carioca'
|
310
|
+
|
311
|
+
class MyObject
|
312
|
+
|
313
|
+
extend Carioca::Injector
|
314
|
+
inject service: I18n
|
315
|
+
|
316
|
+
def initialize
|
317
|
+
puts i18n.t('sample.string', myvar: 'test')
|
318
|
+
end
|
319
|
+
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
```
|
325
|
+
|
326
|
+
output :
|
327
|
+
|
328
|
+
Display test
|
329
|
+
|
330
|
+
### Service Logger
|
331
|
+
|
332
|
+
**Note** : Logger depends on service I18n
|
333
|
+
#### Logging simply
|
334
|
+
|
335
|
+
```ruby
|
336
|
+
|
337
|
+
require 'carioca'
|
338
|
+
|
339
|
+
class MyObject
|
340
|
+
|
341
|
+
extend Carioca::Injector
|
342
|
+
inject service: logger
|
343
|
+
|
344
|
+
def initialize
|
345
|
+
logger.info(self.to_s) { "my log" }
|
346
|
+
end
|
347
|
+
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
351
|
+
|
352
|
+
```
|
353
|
+
|
354
|
+
|
355
|
+
#### Changing log strategy
|
356
|
+
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
require 'rubygems'
|
360
|
+
require 'carioca'
|
361
|
+
|
362
|
+
Carioca::Registry.configure do |spec|
|
363
|
+
spec.debug = false
|
364
|
+
spec.log_file = '/tmp/test_carioca.log' # a different log path (default STDOUT)
|
365
|
+
spec.log_level = :debug # log level base (default :info)
|
366
|
+
spec.log_target = '::Logger::new(STDOUT)' # to change completly the log object
|
367
|
+
end
|
368
|
+
```
|
369
|
+
|
370
|
+
|
371
|
+
for more information on ruby Stdlib Logger, see :
|
372
|
+
https://ruby-doc.org/3.2.2/stdlibs/logger/Logger.html
|
373
|
+
|
374
|
+
|
375
|
+
**Note** : you could totally subsitute Logger with your own logger, by the configuration, or the logger of an other service.
|
376
|
+
BUT it's necessary to be compatible with standard Logger facilities :
|
377
|
+
|
378
|
+
```ruby
|
379
|
+
logger.debug('Maximal debugging info')
|
380
|
+
logger.info('Non-error information')
|
381
|
+
logger.warn('Non-error warning')
|
382
|
+
logger.error('Non-fatal error')
|
383
|
+
logger.fatal('Fatal error')
|
384
|
+
logger.unknown('Most severe')
|
385
|
+
```
|
386
|
+
|
387
|
+
**Note** : the output service, detailled after could work in dual mode STDXXX + logger service.
|
388
|
+
|
389
|
+
### Service Configuration
|
390
|
+
|
391
|
+
|
392
|
+
#### Configuration
|
393
|
+
|
394
|
+
Configuration made with Registry.configure :
|
395
|
+
|
396
|
+
```ruby
|
397
|
+
Carioca::Registry.configure do |spec|
|
398
|
+
spec.config_file = './config/settings.yml'
|
399
|
+
spec.config_root = :myappli
|
400
|
+
spec.environment = :development
|
401
|
+
end
|
402
|
+
```
|
403
|
+
|
404
|
+
* config_file : path to the configuraion file (YAML format)
|
405
|
+
* config_root : Root of the YAML structure
|
406
|
+
* environment : current evt used for override default values
|
407
|
+
|
408
|
+
#### Configuration file format
|
409
|
+
|
410
|
+
**Note** :This file is corresponding with the presented configuration
|
411
|
+
|
412
|
+
```yaml
|
413
|
+
---
|
414
|
+
:myappli:
|
415
|
+
:production: {}
|
416
|
+
:staging:
|
417
|
+
:onstaging: staging
|
418
|
+
:test: {}
|
419
|
+
:development:
|
420
|
+
:ondev: test
|
421
|
+
:treeA:
|
422
|
+
:trunk1:
|
423
|
+
:branch1: leaf1
|
424
|
+
:trunk2:
|
425
|
+
:branch3: leaf3
|
426
|
+
:branch4: leaf4
|
427
|
+
:branch5: [ "val1","val2","val3" ]
|
428
|
+
:default:
|
429
|
+
:default_value: 'value'
|
430
|
+
:treeA:
|
431
|
+
:trunk1:
|
432
|
+
:branch2: leaf2
|
433
|
+
:trunk2:
|
434
|
+
:branch5: ["value"]
|
435
|
+
```
|
436
|
+
|
437
|
+
#### Access to Configuration
|
438
|
+
|
439
|
+
```ruby
|
440
|
+
config = Carioca::Registry.get.get_service name: :configuration
|
441
|
+
pp config.settings
|
442
|
+
```
|
443
|
+
|
444
|
+
**Note** : You could access it as usuallly, with inject, from Carioca::Container fork or mixin of Carioca::Injector in your own class.
|
445
|
+
|
446
|
+
output :
|
447
|
+
|
448
|
+
```
|
449
|
+
{:default_value=>"value",
|
450
|
+
:treeA=>
|
451
|
+
{:trunk1=>{:branch2=>"leaf2", :branch1=>"leaf1"},
|
452
|
+
:trunk2=>
|
453
|
+
{:branch5=>["value", "val1", "val2", "val3"],
|
454
|
+
:branch3=>"leaf3",
|
455
|
+
:branch4=>"leaf4"}},
|
456
|
+
:ondev=>"test"}
|
457
|
+
```
|
458
|
+
|
459
|
+
**Note** : you could see the result configuration is a merge of :development path ovec :default
|
460
|
+
|
461
|
+
|
462
|
+
#### R/W on runtime
|
463
|
+
|
464
|
+
**Note** : you could override value in runtime
|
465
|
+
|
466
|
+
```ruby
|
467
|
+
config = Carioca::Registry.get.get_service name: :configuration
|
468
|
+
config.settings.newkey = 'value'
|
469
|
+
```
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
#### Princpe
|
474
|
+
|
475
|
+
![Carioca synoptic](assets/images/description_configuration_carioca.png)
|
476
|
+
|
477
|
+
|
478
|
+
### Service Output
|
479
|
+
|
480
|
+
|
481
|
+
#### Configuration
|
482
|
+
|
483
|
+
Configuration made with Registry.configure :
|
484
|
+
|
485
|
+
```ruby
|
486
|
+
Carioca::Registry.configure do |spec|
|
487
|
+
spec.debug = false
|
488
|
+
spec.log_file = '/tmp/test.rge'
|
489
|
+
spec.log_level = :debug
|
490
|
+
spec.output_mode = :dual
|
491
|
+
spec.output_emoji = true
|
492
|
+
spec.output_colors = true
|
493
|
+
spec.output_target = STDOUT
|
494
|
+
|
495
|
+
end
|
496
|
+
```
|
497
|
+
|
498
|
+
* output_mode : choose if you want to display to output_target OR/AND Logs, mode are : :mono, dual, log
|
499
|
+
* output_emoji : display levels or alias as UTF8 EMOJI
|
500
|
+
* output_colors : display output in colors
|
501
|
+
* output_target : change output STDOUT or SDTERR
|
502
|
+
|
503
|
+
**Note** : all of this have R/W accessors on output service
|
504
|
+
|
505
|
+
#### Usage
|
506
|
+
|
507
|
+
|
508
|
+
This example show a test script for displaying all type of output
|
509
|
+
|
510
|
+
```ruby
|
511
|
+
output = Carioca::Registry.get.get_service name: :output
|
512
|
+
|
513
|
+
cycle = %i[unknown fatal error ko warn info item arrow scheduling trigger sending calling receive
|
514
|
+
ok success debug flat]
|
515
|
+
cycle.each do |verb|
|
516
|
+
output.send verb, verb.to_s
|
517
|
+
end
|
518
|
+
output.color = false
|
519
|
+
cycle.each do |verb|
|
520
|
+
output.send verb, verb.to_s
|
521
|
+
end
|
522
|
+
output.emoji = false
|
523
|
+
cycle.each do |verb|
|
524
|
+
output.send verb, verb.to_s
|
525
|
+
end
|
526
|
+
output.color = true
|
527
|
+
cycle.each do |verb|
|
528
|
+
output.send verb, verb.to_s
|
529
|
+
end
|
530
|
+
|
531
|
+
```
|
532
|
+
**Note** : list of ordered levels or alias : **unknown fatal error ko warn info item arrow scheduling trigger sending calling receive ok success debug flat**
|
533
|
+
|
534
|
+
Output :
|
535
|
+
|
536
|
+
* Without colors nor Emojies
|
537
|
+
|
538
|
+
![Carioca output](assets/images/carioca_output_no_emoji_no_colors.PNG)
|
539
|
+
|
540
|
+
* Without colors but with Emojies
|
541
|
+
|
542
|
+
![Carioca output](assets/images/carioca_output_emoji_no_colors.PNG)
|
543
|
+
|
544
|
+
* With colors but no Emojies
|
545
|
+
|
546
|
+
![Carioca output](assets/images/carioca_output_no_emoji_colors.PNG)
|
547
|
+
|
548
|
+
* With colors and Emojies
|
549
|
+
|
550
|
+
![Carioca output](assets/images/carioca_output_emoji_colors)
|
551
|
+
|
552
|
+
### Service Debug
|
553
|
+
|
554
|
+
|
555
|
+
For this example, we use a internal service defined programmaticalu on runtime, (we see it more in detail in the chapter dedicated to the registry)
|
556
|
+
At the beginning of you code, just add :
|
557
|
+
|
558
|
+
```ruby
|
559
|
+
class MyService
|
560
|
+
extend Carioca::Injector
|
561
|
+
inject service: :logger
|
562
|
+
|
563
|
+
def initialize
|
564
|
+
logger.warn(self.class.to_s) { 'Init service' }
|
565
|
+
end
|
566
|
+
|
567
|
+
def hello
|
568
|
+
logger.info(self.class.to_s) { 'Hello World' }
|
569
|
+
end
|
570
|
+
|
571
|
+
def method_test(_titi, tutu:)
|
572
|
+
@tutu = tutu
|
573
|
+
yield if block_given?
|
574
|
+
"result #{@tutu}"
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
578
|
+
spec = {
|
579
|
+
service: 'MyService::new',
|
580
|
+
type: :internal
|
581
|
+
}
|
582
|
+
|
583
|
+
Carioca::Registry.init.add service: :myservice, definition: spec
|
584
|
+
|
585
|
+
```
|
586
|
+
|
587
|
+
With a configuration like :
|
588
|
+
|
589
|
+
|
590
|
+
```ruby
|
591
|
+
Carioca::Registry.configure do |spec|
|
592
|
+
spec.debug = true
|
593
|
+
spec.log_level = :debug
|
594
|
+
spec.output_emoji = true
|
595
|
+
spec.output_colors = false
|
596
|
+
spec.debugger_tracer = :output
|
597
|
+
end
|
598
|
+
|
599
|
+
```
|
600
|
+
|
601
|
+
|
602
|
+
To help debug with services, Carioca come with a proxy class debugger :
|
603
|
+
|
604
|
+
```ruby
|
605
|
+
config = Carioca::Registry.get.get_service name: :debugger
|
606
|
+
proxy = debugger.get service: :myservice
|
607
|
+
proxy.method_test 'param', tutu: 'keyword' do
|
608
|
+
puts 'titi'
|
609
|
+
end
|
610
|
+
```
|
611
|
+
|
612
|
+
output :
|
613
|
+
|
614
|
+
```
|
615
|
+
🐛 BEGIN CALL for service #<MyService:0x00005635ed283290>
|
616
|
+
🐛 Method called: method_test
|
617
|
+
🐛 args : param
|
618
|
+
🐛 keywords : {:tutu=>"keyword"}
|
619
|
+
🐛 block given
|
620
|
+
titi
|
621
|
+
🐛 => method returned: result keyword
|
622
|
+
🐛 END CALL
|
623
|
+
```
|
624
|
+
|
625
|
+
## Carioca Configuration
|
626
|
+
|
627
|
+
Carioca use a bloc given mapping object of to configure like :
|
628
|
+
|
629
|
+
```ruby
|
630
|
+
Carioca::Registry.configure do |spec|
|
631
|
+
spec.xxxxx = <SOMETHING>
|
632
|
+
...
|
633
|
+
end
|
634
|
+
|
635
|
+
```
|
636
|
+
### list of accessors over the spec object :
|
637
|
+
|
638
|
+
```ruby
|
639
|
+
attr_accessor :filename, :name, :builtins, :log_target, :default_locale, :locales_load_path, :debugger_tracer,
|
640
|
+
:config_file, :config_root, :environment, :supported_environments, :output_mode, :log_level, :output_target
|
641
|
+
attr_writer :init_from_file, :output_colors, :output_emoji
|
642
|
+
attr_reader :log_file, :locales_availables, :debug
|
643
|
+
|
644
|
+
```
|
645
|
+
|
646
|
+
### Publique usage (with default values and possibles values)
|
647
|
+
|
648
|
+
```ruby
|
649
|
+
Carioca::Registry.configure do |spec|
|
650
|
+
|
651
|
+
spec.filename = './config/carioca.registry' # the carioca registry of services configuration
|
652
|
+
spec.name = 'Carioca' # the name of the application
|
653
|
+
spec.debug = false # activate debug, display debug Carioca message
|
654
|
+
spec.init_from_file = true # use the registry file to init services : (spec.filename)
|
655
|
+
spec.log_file = '' # path to a log file for carioca logger service
|
656
|
+
spec.config_file = './config/settings.yml' # path to the YAMl COnfiguration file for :configuration Carioca service
|
657
|
+
spec.config_root = :carioca # the config root in the YAMl COnfiguration file for :configuration Carioca service
|
658
|
+
spec.environment = :development # the current environment running with Carioca
|
659
|
+
spec.default_locale = :en # the default locales Carioca fot I18n Carioca Service
|
660
|
+
spec.log_level = :info # the current log level (see logger ) for Carioca in :debug,:info,:warn,:error,:fatal,:unknown
|
661
|
+
spec.output_mode = :mono # the current output mode in :mono, :dual, :log (see Carioca Service Output)
|
662
|
+
spec.output_emoji = true # the current output status for emoji (see Carioca Service Output)
|
663
|
+
spec.output_target = STDOUT # the current output target STDOUT or STDERR (see Carioca Service Output)
|
664
|
+
spec.output_colors = true # the current output status for colors (see Carioca Service Output)
|
665
|
+
spec.locales_load_path << Dir["#{File.expand_path('./config/locales')}/*.yml"]
|
666
|
+
spec.debugger_tracer = :output # the Debbugger service output in #log , :output
|
667
|
+
|
668
|
+
end
|
669
|
+
```
|
670
|
+
## Registry access and methods
|
671
|
+
|
672
|
+
### Init or getting Registry
|
673
|
+
|
674
|
+
Carioca::Registry is a Singleton Object
|
675
|
+
|
676
|
+
You cloud init or get it by #get, #instance or #init, like :
|
677
|
+
|
678
|
+
```ruby
|
679
|
+
registry = Carioca::Registry.init
|
680
|
+
registry = Carioca::Registry.instance
|
681
|
+
registry = Carioca::Registry.get
|
682
|
+
```
|
683
|
+
|
684
|
+
### Direct access to Registry and getting service Without Injector or Carioca::Container
|
685
|
+
|
686
|
+
Example : for output service
|
687
|
+
|
688
|
+
```ruby
|
689
|
+
output = Carioca::Registry.get.get_service name: :output
|
690
|
+
```
|
691
|
+
|
692
|
+
|
693
|
+
### Adding a service programatically
|
694
|
+
|
695
|
+
To add a service, you could insert it in the registry file (before run) or adding it programatically
|
696
|
+
|
697
|
+
```ruby
|
698
|
+
class MyService
|
699
|
+
extend Carioca::Injector
|
700
|
+
inject service: :logger
|
701
|
+
|
702
|
+
def initialize
|
703
|
+
logger.warn(self.class.to_s) { 'Init service' }
|
704
|
+
end
|
705
|
+
|
706
|
+
def hello
|
707
|
+
logger.info(self.class.to_s) { 'Hello World' }
|
708
|
+
end
|
709
|
+
|
710
|
+
def method_test(_titi, tutu:)
|
711
|
+
@tutu = tutu
|
712
|
+
yield if block_given?
|
713
|
+
"result #{@tutu}"
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
spec = {
|
718
|
+
service: 'MyService::new',
|
719
|
+
type: :internal
|
720
|
+
}
|
721
|
+
|
722
|
+
Carioca::Registry.init.add service: :myservice, definition: spec
|
723
|
+
|
724
|
+
```
|
725
|
+
|
726
|
+
|
727
|
+
### Decription of type of Service
|
728
|
+
|
729
|
+
|
730
|
+
```ruby
|
731
|
+
SERVICES_MANDATORY_SPECS = { type: Symbol, service: String }.freeze
|
732
|
+
SERVICES_FULL_LIST_SPECS = SERVICES_MANDATORY_SPECS.merge({ depends: Array, description: String,
|
733
|
+
resource: String })
|
734
|
+
```
|
735
|
+
|
736
|
+
|
737
|
+
* :type must be : :gem, :file, :stdlib all engage requirement of the resource field, tje last :internal is usable if the code is internal in your application.
|
738
|
+
|
739
|
+
* :service : is the Ruby code to access to Class for class methods service usage or object instance
|
740
|
+
example : MYCLASS or MyClass::new(params)
|
741
|
+
|
742
|
+
* :resource is respectively a name of a gem, an absolut path of a ruby file, the name of a Ruby Stdlib correspondingly to :type
|
743
|
+
* depends : is a list of requiered services for this service. (all services in depends are load before getting the wanted service (from builtin and in registry file or added at runtime ).
|
744
|
+
* Description is not mandatory
|
745
|
+
|
192
746
|
|
193
|
-
## A step further
|
194
747
|
|
195
748
|
|
196
749
|
## Development
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0
|
1
|
+
2.1.0
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/carioca.gemspec
CHANGED
@@ -41,6 +41,8 @@ Gem::Specification.new do |spec|
|
|
41
41
|
spec.add_development_dependency 'rubocop', '~> 1.32'
|
42
42
|
spec.add_development_dependency 'yard', '~> 0.9.27'
|
43
43
|
spec.add_development_dependency 'yard-rspec', '~> 0.1'
|
44
|
+
spec.add_development_dependency "bundle-audit", "~> 0.1.0"
|
44
45
|
spec.metadata['rubygems_mfa_required'] = 'false'
|
45
46
|
spec.add_dependency 'version', '~> 1.1'
|
47
|
+
spec.add_runtime_dependency 'ps-ruby','~> 0.0.4'
|
46
48
|
end
|
data/config/locales/en.yml
CHANGED
@@ -21,3 +21,37 @@ en:
|
|
21
21
|
output:
|
22
22
|
load:
|
23
23
|
context: "Output service initialized in mode : %{confset}"
|
24
|
+
finisher:
|
25
|
+
messages:
|
26
|
+
not_root: "This operation need to be run as root (use sudo or rvmsudo)"
|
27
|
+
options_incompatibility: "Options incompatibility"
|
28
|
+
service_dependence_missing: "Appifier Service dependence missing"
|
29
|
+
config_required: "Specific configuration required"
|
30
|
+
setup_error: "Setup terminated unsuccessfully"
|
31
|
+
setup_success: "Setup terminated successfully"
|
32
|
+
sanitycheck_error: "Sanitycheck terminated unsuccessfully"
|
33
|
+
sanitycheck_success: "Sanitycheck terminated successfully"
|
34
|
+
configuration_error: "Configuration Error"
|
35
|
+
success_exit: "Operation sucessfull"
|
36
|
+
error_exit: "Operation failure"
|
37
|
+
interrupt: "User operation interrupted"
|
38
|
+
not_found: "Object not found"
|
39
|
+
already_exist: "Object already exist"
|
40
|
+
status_ok: "Status OK"
|
41
|
+
status_ko: "Status KO"
|
42
|
+
bad_usage: "Case must be a return or an exit"
|
43
|
+
setup:
|
44
|
+
error: "Setup operation failed"
|
45
|
+
execute:
|
46
|
+
start: "Begining setup :"
|
47
|
+
install: "Installation of file %{file}"
|
48
|
+
mkdir: "Creation of folder %{path}"
|
49
|
+
ln: "Creation of symlink %{target} -> %{source}"
|
50
|
+
sanitycheck:
|
51
|
+
error: "Sanitycheck stop on Configuration error"
|
52
|
+
success: "Sanitycheck finish without errors"
|
53
|
+
failure: "Sanitycheck finish with errors"
|
54
|
+
run:
|
55
|
+
start: "Begining sanitycheck :"
|
56
|
+
ok: "Testcase %{testcase} on %{name} is ok"
|
57
|
+
ko: "Testcase %{testcase} on %{name} is ok, problem(s) : %{pbm}"
|