carioca 1.4 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +18 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/Gemfile +3 -1
  6. data/Gemfile.lock +58 -0
  7. data/README.md +123 -190
  8. data/Rakefile +5 -66
  9. data/bin/console +15 -0
  10. data/bin/setup +8 -0
  11. data/carioca.gemspec +37 -23
  12. data/config/locales/en.yml +23 -0
  13. data/config/locales/fr.yml +23 -0
  14. data/lib/carioca/configuration.rb +61 -0
  15. data/lib/carioca/constants.rb +68 -0
  16. data/lib/carioca/container.rb +16 -0
  17. data/lib/carioca/dependencies.rb +20 -0
  18. data/lib/carioca/helpers.rb +44 -31
  19. data/lib/carioca/mixin.rb +32 -0
  20. data/lib/carioca/{tasks/rake.rb → rake/manage.rb} +5 -4
  21. data/lib/carioca/rake/tasks/config.tasks +46 -0
  22. data/lib/carioca/rake/tasks/gem.tasks +15 -0
  23. data/lib/carioca/rake/tasks/registry.tasks +64 -0
  24. data/lib/carioca/registry.rb +94 -0
  25. data/lib/carioca/registry_file.rb +62 -0
  26. data/lib/carioca/services/config.rb +141 -0
  27. data/lib/carioca/services/debug.rb +48 -61
  28. data/lib/carioca/services/i18n.rb +20 -0
  29. data/lib/carioca/services/init.rb +2 -0
  30. data/lib/carioca/services/output.rb +189 -0
  31. data/lib/carioca/validator.rb +49 -0
  32. data/lib/carioca.rb +2 -319
  33. data/samples/Rakefile +2 -0
  34. data/samples/config/carioca.registry +22 -0
  35. data/samples/config/locales/en.yml +2 -0
  36. data/samples/config/locales/es.yml +2 -0
  37. data/samples/config/locales/fr.yml +2 -0
  38. data/samples/config/settings.yml +24 -0
  39. data/samples/test.rb +118 -0
  40. metadata +77 -143
  41. data/AUTHORS +0 -8
  42. data/COPYRIGHT +0 -24
  43. data/ChangeLog +0 -10
  44. data/INSTALL +0 -7
  45. data/doc/manual.rdoc +0 -225
  46. data/lib/carioca/exceptions.rb +0 -9
  47. data/lib/carioca/private.rb +0 -168
  48. data/lib/carioca/services/configuration.rb +0 -203
  49. data/lib/carioca/services/logger.rb +0 -58
  50. data/lib/carioca/services.rb +0 -143
  51. data/lib/carioca/tasks/registry_init.rake +0 -12
  52. data/spec/carioca_spec.rb +0 -468
  53. data/spec/config/.config +0 -14
  54. data/spec/config/services.registry +0 -55
  55. data/spec/init_spec.rb +0 -2
  56. data/spec/samples/dummy.rb +0 -11
  57. data/spec/samples/otherdummy.rb +0 -11
  58. data/spec/samples/requireddummy.rb +0 -11
  59. data/spec/spec_helper.rb +0 -18
  60. data/ultragreen_roodi_coding_convention.yml +0 -25
@@ -0,0 +1,23 @@
1
+ fr:
2
+ service:
3
+ adding: "Service %{name} Ajouté"
4
+ starting: "Démarrage du service %{name}"
5
+ getting: "Appel du service %{name}"
6
+ depends: "Dépendence du service %{name}"
7
+ notify:
8
+ locale: "Service pré-chargé :i18n sur la locale : %{loc}"
9
+ logger: "Service pré-chargé :logger sur la cible : %{target}"
10
+ useless_entry: "Entrée inutile dans le registre (service pré-defini) %{altered} dans %{filename}"
11
+ init:
12
+ carioca: "Initialisation du registre Carioca"
13
+ builtins: "Préparation des services pré-définis"
14
+ registry:
15
+ processing: "Initialisation du registre depuis le fichier : %{filename}"
16
+ success: "Registre initialisé avec succès"
17
+ config:
18
+ load:
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}"
@@ -0,0 +1,61 @@
1
+ module Carioca
2
+ class Configuration
3
+ include Carioca::Constants
4
+ include Carioca::Helpers
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 :debug, :init_from_file, :output_colors, :output_emoji
8
+ attr_reader :log_file, :locales_availables
9
+ def initialize
10
+ @init_from_file = true
11
+ @filename = DEFAULT_REGISTRY_FILE.dup
12
+ @debug = false
13
+ @name = 'Carioca'
14
+ @builtins = BUILTINS
15
+ @log_file = ''
16
+ @log_level = DEFAULT_LOG_LEVEL.dup
17
+ @log_level = :info if @debug == false and @log_level == :debug
18
+ @config_file = DEFAULT_CONFIG_FILE.dup
19
+ @environment = DEFAULT_ENVIRONMENT.dup
20
+ @config_root = DEFAULT_CONFIG_ROOT.dup
21
+ @log_target = '::Logger::new(STDOUT)'
22
+ @supported_environment = DEFAULT_ENVIRONMENTS_LIST.dup
23
+ @default_locale = DEFAULT_LOCALE
24
+ @locales_availables = []
25
+ @output_mode = DEFAULT_OUTPUT_MODE.dup
26
+ @output_colors = DEFAULT_COLORS_STATUS.dup
27
+ @output_emoji = DEFAULT_EMOJI_STATUS.dup
28
+ path = search_file_in_gem('carioca',"config/locales")
29
+ @locales_load_path = Dir[File.expand_path(path) + "/*.yml"]
30
+ Dir[path + '/*.yml'].sort.each do |file|
31
+ @locales_availables.push File::basename(file,'.yml').to_sym
32
+ end
33
+ @debugger_tracer = DEFAULT_DEBUGGER_TRACER.dup
34
+ end
35
+
36
+ def debug?
37
+ return @debug
38
+ end
39
+
40
+ def output_colors?
41
+ return @output_colors
42
+ end
43
+
44
+ def output_emoji?
45
+ return @output_emoji
46
+ end
47
+
48
+ def init_from_file?
49
+ return @init_from_file
50
+ end
51
+
52
+ def log_file?
53
+ return !@log_file.empty?
54
+ end
55
+
56
+ def log_file=(name)
57
+ @log_file = name
58
+ @log_target = "::Logger::new('#{name}')"
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,68 @@
1
+ module Carioca
2
+ module Constants
3
+
4
+ VERSION = '2.0.3'
5
+ DEFAULT_REGISTRY_FILE = './config/carioca.registry'
6
+ DEFAULT_CONFIG_FILE = './config/settings.yml'
7
+ DEFAULT_ENVIRONMENT = :development
8
+ DEFAULT_CONFIG_ROOT = :carioca
9
+ DEFAULT_LOCALE = :en
10
+
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
+
20
+ # service definitions specs
21
+ SERVICES_MANDATORY_SPECS = {type: Symbol, service: String}
22
+ SERVICES_FULL_LIST_SPECS = SERVICES_MANDATORY_SPECS.merge({depends: Array, description: String, resource: String })
23
+ SERVICES_SPECS_DETAIL = {type: [:gem, :stdlib, :file, :internal]}
24
+
25
+ DEFAULT_ENVIRONMENTS_LIST = [:production, :staging, :test, :development]
26
+
27
+ BUILTINS = {
28
+ configuration: {
29
+ type: :internal,
30
+ depends: [:logger],
31
+ description: "The configuration service of Carioca",
32
+ service: "Carioca::Services::Config::Factory::new(
33
+ config_filename: Carioca::Registry.config.config_file,
34
+ stage: Carioca::Registry.config.environment,
35
+ root: Carioca::Registry.config.config_root)" },
36
+ logger: {
37
+ type: :stdlib,
38
+ resource: "logger",
39
+ description: "The Logger service of Carioca",
40
+ depends: [:i18n]
41
+ },
42
+ i18n:{
43
+ type: :internal,
44
+ description: "The Internalisation service of Carocia",
45
+ service: "Carioca::Services::I18n.get(
46
+ default_locale: Carioca::Registry.config.default_locale,
47
+ load_path: Carioca::Registry.config.locales_load_path,
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"
64
+ }
65
+ }
66
+
67
+ end
68
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module Carioca
3
+ class Container
4
+
5
+ extend Carioca::Injector
6
+
7
+ inject service: :logger
8
+ inject service: :configuration
9
+
10
+ def initialize(name: 'Carioca')
11
+ @name = name
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,20 @@
1
+ require 'yaml'
2
+ require 'forwardable'
3
+ require 'singleton'
4
+
5
+ require 'rubygems'
6
+ require 'i18n'
7
+ require 'locale'
8
+ require 'deep_merge'
9
+ require 'pastel'
10
+
11
+ require_relative 'constants'
12
+ require_relative 'validator'
13
+ require_relative 'mixin'
14
+ require_relative 'container'
15
+ require_relative 'helpers'
16
+ require_relative 'configuration'
17
+
18
+ require_relative 'registry_file'
19
+ require_relative 'registry'
20
+ require_relative 'services/init'
@@ -1,35 +1,48 @@
1
- # coding: utf-8
2
- #---
3
- # Author : Romain GEORGES
4
- # type : gem component library
5
- # obj : Carioca Helpers definition Module
6
- #---
1
+ module Carioca
2
+ module Helpers
7
3
 
8
- class Class
9
- # Usage:
10
- # prelaod_service :name => 'service', :params => { :arg => 'value'}
11
- def preload_service(_options = {})
12
- Carioca::Services::Registry.init.start_service _options
13
- end
4
+ def log
5
+ return self.get_service name: :logger
6
+ end
14
7
 
15
- def use_configuration(_options = {})
16
- options = Methodic.get_options(_options)
17
- options.specify_classes_of :with_file => String
18
- options.specify_default_value_for :with_file => 'services/registry.yml'
19
- options.merge
20
- options.validate!
21
- Carioca::Services::Registry.init.start_service :name => 'configuration', :params => { :config_file => options[:with_file]}
22
- end
23
- end
8
+ def i18n
9
+ return self.get_service name: :i18n
10
+ end
24
11
 
12
+ def debug(message: )
13
+ log.debug(self.config.name) { "#{message}" }
14
+ end
25
15
 
26
- Module.class_eval do
27
- def init_registry _options={}
28
- options = Methodic.get_options(_options)
29
- options.specify_classes_of :with_file => String
30
- options.specify_default_value_for :with_file => 'services/registry.yml'
31
- options.merge
32
- options.validate!
33
- Carioca::Services::Registry.init :file => options[:with_file]
34
- end
35
- end
16
+ # facility to find a file in gem path
17
+ # @param [String] _gem a Gem name
18
+ # @param [String] _file a file relative path in the gem
19
+ # @return [String] the path of the file, if found.
20
+ # @return [False] if not found
21
+ def search_file_in_gem(_gem,_file)
22
+ if Gem::Specification.respond_to?(:find_by_name)
23
+ begin
24
+ spec = Gem::Specification.find_by_name(_gem)
25
+ rescue LoadError
26
+ spec = nil
27
+ end
28
+ else
29
+ spec = Gem.searcher.find(_gem)
30
+ end
31
+ if spec then
32
+ if Gem::Specification.respond_to?(:find_by_name)
33
+ res = spec.lib_dirs_glob.split('/')
34
+ else
35
+ res = Gem.searcher.lib_dirs_for(spec).split('/')
36
+ end
37
+ res.pop
38
+ services_path = res.join('/').concat("/#{_file}")
39
+ return services_path if File::exist?(services_path)
40
+ return false
41
+ else
42
+ return false
43
+ end
44
+ end
45
+
46
+
47
+ end
48
+ end
@@ -0,0 +1,32 @@
1
+ module Carioca
2
+ module Injector
3
+ def inject(service: )
4
+ self.create_methods(service){return Carioca::Registry.get.get_service name: service }
5
+ end
6
+
7
+ def register(service: , definition:)
8
+ Carioca::Registry.get.add service: service, definition: definition
9
+ end
10
+
11
+ def services
12
+ Carioca::Registry.get.services
13
+ end
14
+
15
+ def active_services
16
+ Carioca::Registry.get.active_services
17
+ end
18
+
19
+ def create_methods(name, &block)
20
+ self.define_method name, &block
21
+ self.class.send(:define_method, name, &block)
22
+ end
23
+
24
+ def self.extended(base)
25
+ base.include self
26
+ end
27
+
28
+
29
+
30
+ end
31
+
32
+ end
@@ -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)
@@ -17,7 +20,5 @@ else
17
20
  end
18
21
 
19
22
  res.pop
20
- tasks_path = res.join('/').concat('/lib/carioca/tasks/')
21
-
22
-
23
- Dir["#{tasks_path}/*.rake"].each { |ext| load ext }
23
+ tasks_path = res.join('/').concat('/lib/carioca/rake/tasks/')
24
+ Dir["#{tasks_path}/*.task*"].each { |ext| load ext }
@@ -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
@@ -0,0 +1,64 @@
1
+ namespace :carioca do
2
+ namespace :registry do
3
+ desc "Adding service to Carioca Registry file"
4
+ task :add_service do
5
+ prompt = TTY::Prompt.new
6
+ pastel = ::Pastel.new
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
14
+ puts "Carioca : registering service :"
15
+ config = Carioca::Configuration::new
16
+ filename = prompt.ask("Registry File path ?", default: config.filename)
17
+ registry_file = Carioca::RegistryFile::new filename: filename
18
+ name = prompt.ask("Service name ?") { |q| q.required true }.to_sym
19
+ if config.builtins.include? name or registry_file.validated.include? name then
20
+ puts 'Carioca : service already defined or Builtins'
21
+ exit 1
22
+ end
23
+ definition = {
24
+ :type => prompt.select("Choose the service type ?", [:gem, :stdlib, :file, :internal]),
25
+ :description => prompt.ask("Description ?", default: "The #{name} service"),
26
+ :service => prompt.ask("Service [#{name}] inline Proc Ruby code ?", default: name.to_s.capitalize)
27
+ }
28
+ map = {:gem => "Rubygem name", :stdlib => "StdLib name", :file => "absolut path of the Ruby file"}
29
+ definition[:resource] = prompt.ask("Give the #{map[definition[:type]]} ? ", default: name.to_s ) if map.keys.include? definition[:type]
30
+ have_depends = prompt.yes?("Did this service have dependencies ? ")
31
+ if have_depends then
32
+ potentials = config.builtins.merge(registry_file.validated).keys
33
+ definition[:depends] = prompt.multi_select("Choose your depends ?", potentials, min: 1)
34
+ end
35
+ puts "\n => Service : #{name}"
36
+ puts "Definition "
37
+ definition.each do |key,value|
38
+ puts " * #{key}: #{value}"
39
+ end
40
+ is_correct = prompt.yes?("Is it correct ? ")
41
+ rescue TTY::Reader::InputInterrupt
42
+ print "Carioca : "
43
+ puts pastel.yellow 'interrupted'
44
+ exit 5
45
+ end
46
+ print "Carioca : Registry saving : "
47
+ if is_correct then
48
+ begin
49
+ registry_file.add service: name, definition: definition
50
+ registry_file.save!
51
+ rescue => e
52
+ print pastel.red "failed"
53
+ puts " error : #{e}"
54
+ exit 10
55
+ end
56
+
57
+ puts pastel.green "done"
58
+ else
59
+ puts pastel.yellow 'canceled'
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,94 @@
1
+ module Carioca
2
+ class Registry
3
+ include Carioca::Helpers
4
+ include Singleton
5
+ @@config = Configuration::new
6
+
7
+ def Registry.config
8
+ return @@config
9
+ end
10
+
11
+ def Registry.configure(&block)
12
+ yield(@@config)
13
+ end
14
+
15
+ class << self
16
+ alias_method :get, :instance
17
+ alias_method :init, :instance
18
+
19
+ end
20
+
21
+ attr_accessor :services
22
+ attr_accessor :active_services
23
+
24
+ def get_service(name: )
25
+
26
+ raise "Service not found: #{name}" unless @services.include? name
27
+ if @active_services.include? name then
28
+ debug message: i18n.t('service.getting', name: name) if @active_services.include? :logger and ![:logger, :i18n, :output].include? name and @@config.debug?
29
+ else
30
+ service = @services[name]
31
+ service[:depends].each do|dep|
32
+ debug message: i18n.t('service.depends', name: dep) if @active_services.include? :logger and ![:logger, :i18n].include? dep and @@config.debug?
33
+ get_service(name: dep) unless @active_services.include? dep
34
+ end if service.include? :depends
35
+ debug message: i18n.t('service.starting', name: name) if @active_services.include? :logger and ![:logger, :i18n].include? name and @@config.debug?
36
+ require service[:resource] if [:gem, :file, :stdlib].include? service[:type]
37
+ @active_services[name] ||= eval("lambda { #{service[:service]} }").call
38
+ end
39
+ return @active_services[name]
40
+ end
41
+
42
+ def config
43
+ return @@config
44
+ end
45
+
46
+ def add(service: , definition:, skip_validation: false )
47
+ mess =
48
+ raise "Service #{service} already exist." if @services.include? service and skip_validation == false
49
+ debug message: i18n.t('service.adding', name: service) if @active_services.include? :logger and @@config.debug?
50
+ checker = Carioca::Services::Validator::new service: service , definition: definition
51
+ checker.validate! unless skip_validation
52
+ @services[service] = checker.definition
53
+ end
54
+
55
+ private
56
+ def prepare_logger
57
+ conf_i18n = @@config.builtins[:i18n]
58
+ add service: :i18n, definition: @@config.builtins[:i18n], skip_validation: true
59
+ conf_logger = @@config.builtins[:logger]
60
+ conf_logger[:service] = @@config.log_target
61
+ add service: :logger, definition: @@config.builtins[:logger], skip_validation: true
62
+ log = get_service name: :logger
63
+ log.level = @@config.log_level
64
+ end
65
+
66
+ def initialize
67
+ @services = Hash::new
68
+ @active_services = Hash::new
69
+ prepare_logger
70
+ locale = @@config.default_locale
71
+ target = (@@config.log_file?)? @@config.log_file : "STDOUT"
72
+ debug message: i18n.t('notify.locale', loc: locale) if @@config.debug?
73
+ debug message: i18n.t('notify.logger', target: target) if @@config.debug?
74
+ debug message: i18n.t('init.carioca') if @@config.debug?
75
+ debug message: i18n.t('init.builtins') if @@config.debug?
76
+ @@config.builtins.each do |service, spec|
77
+ add service: service, definition: spec, skip_validation: true unless service == :logger
78
+ end
79
+ open_registry_file if File::exist? @@config.filename and @@config.init_from_file?
80
+ end
81
+
82
+ def open_registry_file
83
+ debug message: i18n.t('init.registry.processing', filename: @@config.filename) if @@config.debug?
84
+ registry_file = Carioca::RegistryFile::new filename: @@config.filename
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?
86
+ registry_file.validated.each do |service,spec|
87
+ add service: service, definition: spec
88
+ end
89
+ debug message: i18n.t('init.registry.success') if @@config.debug?
90
+ end
91
+
92
+
93
+ end
94
+ end
@@ -0,0 +1,62 @@
1
+ module Carioca
2
+
3
+
4
+
5
+
6
+ class RegistryFile
7
+
8
+ attr_accessor :validated, :altered
9
+ include Carioca::Constants
10
+
11
+ def initialize(filename:)
12
+ @filename = filename
13
+ @candidates = Hash::new
14
+ @validated = Hash::new
15
+ @altered = []
16
+ open
17
+ end
18
+
19
+ def altered?
20
+ return !@altered.empty?
21
+ end
22
+
23
+ def create!(force: false)
24
+ write_ok = true
25
+ write_ok = force if File::exist? @filename
26
+ File.open(@filename, 'w') { |file| file.write(@validated.to_yaml) } if write_ok
27
+ end
28
+
29
+ def save!
30
+ create! force: true
31
+ end
32
+
33
+ def add(service:, definition: )
34
+ checker = Carioca::Services::Validator::new service: service , definition: definition
35
+ checker.validate!
36
+ @validated[service] = checker.definition
37
+ end
38
+
39
+ def open
40
+ if File::exist?(@filename) then
41
+ @candidates = YAML.load_file(@filename)
42
+ else
43
+ create!
44
+ end
45
+ prepare!
46
+ end
47
+
48
+ private
49
+ def prepare!
50
+ save = @candidates.dup
51
+ @candidates.delete_if {|key, value| BUILTINS.keys.include? key }
52
+ @altered = save.keys - @candidates.keys
53
+ @candidates.each do |service, definition|
54
+ checker = Carioca::Services::Validator::new service: service , definition: definition
55
+ checker.validate!
56
+ @validated[service] = checker.definition
57
+ end
58
+ end
59
+
60
+
61
+ end
62
+ end