Module: Carioca::Services
- Defined in:
- lib/carioca.rb,
lib/carioca/services.rb,
lib/carioca/services/debug.rb,
lib/carioca/services/logger.rb,
lib/carioca/services/configuration.rb
Overview
namespace Services for Registry AND buitlins
Defined Under Namespace
Classes: Configuration, InternalLogger, ProxyDebug, Registry, Settings
Class Method Summary collapse
-
.discover_builtins ⇒ Hash
class method returning the [Carioca::Services::Registry]@list complement for builtins service found for a carioca gem version.
-
.search_builtins(_name) ⇒ String, false
class method returning full path in Carioca gem for builtin services files according to installed gem path.
-
.search_file_in_gem(_gem, _file) ⇒ String|FalseClass
class method returning the path of a file in gem if exist or false.
- .validate_service(file, res) ⇒ Object
Class Method Details
.discover_builtins ⇒ Hash
do not use directly for generale purpose (expert/hacks only)
class method returning the [Carioca::Services::Registry]@list complement for builtins service found for a carioca gem version
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/carioca/services.rb', line 80 def Services::discover_builtins if Gem::Specification.respond_to?(:find_by_name) begin spec = Gem::Specification.find_by_name('carioca') rescue LoadError spec = nil end else spec = Gem.searcher.find('carioca') end if spec then if Gem::Specification.respond_to?(:find_by_name) res = spec.lib_dirs_glob.split('/') else res = Gem.searcher.lib_dirs_for(spec).split('/') end res.pop services_path = res.join('/').concat('/lib/carioca/services') else services_path = "./lib/carioca/services" end map = Dir["#{services_path}/*"] map.delete_if { |item| not File::file?(item) } map.delete_if { |item| File::basename(item) == 'logger.rb' } res = {} map.each do |file| Services::validate_service(file,res) end return res end |
.search_builtins(_name) ⇒ String, false
do not use directly for generale purpose (expert/hacks only)
class method returning full path in Carioca gem for builtin services files according to installed gem path.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/carioca/services.rb', line 18 def Services::search_builtins(_name) if Gem::Specification.respond_to?(:find_by_name) begin spec = Gem::Specification.find_by_name('carioca') rescue LoadError spec = nil end else spec = Gem.searcher.find('carioca') end if spec then if Gem::Specification.respond_to?(:find_by_name) res = spec.lib_dirs_glob.split('/') else res = Gem.searcher.lib_dirs_for(spec).split('/') end res.pop services_path = res.join('/').concat('/lib/carioca/services') else services_path = "./lib/carioca/services" end _file ="#{services_path}/#{_name}.rb" if ( File::exist? _file or File::exist? "lib/#{_file}" ) then return _file else return false end end |
.search_file_in_gem(_gem, _file) ⇒ String|FalseClass
do not use directly for generale purpose (expert/hacks only)
class method returning the path of a file in gem if exist or false
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/carioca/services.rb', line 51 def Services::search_file_in_gem(_gem,_file) if Gem::Specification.respond_to?(:find_by_name) begin spec = Gem::Specification.find_by_name(_gem) rescue LoadError spec = nil end else spec = Gem.searcher.find(_gem) end if spec then if Gem::Specification.respond_to?(:find_by_name) res = spec.lib_dirs_glob.split('/') else res = Gem.searcher.lib_dirs_for(spec).split('/') end res.pop services_path = res.join('/').concat("/#{_file}") return services_path if File::exist?(services_path) return false else return false end end |
.validate_service(file, res) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/carioca/services.rb', line 114 def Services::validate_service(file,res) = {} if open(file).grep(/^# \$BUILTIN/).size > 0 then service = open(file).grep(/# \$SERVICE/).first.split[2] resource = open(file).grep(/# \$RESOURCE/).first.split[2] desc = open(file).grep(/# \$DESCRIPTION/).first desc = desc.split(' ') desc.shift(2) description= desc.join(' ') open(file).grep(/# \$INIT_OPTIONS/).each do |opt| prev = opt.split [prev[2].to_sym] = prev[4] end distributed = (open(file).grep(/# \$DISTRIBUTED/))? true : false req = open(file).grep(/# \$REQUIRES/) if req.empty? then requires = [] else requires = req.split requires.shift end end unless service.nil? or resource.nil? or description.nil? then res[resource] = { :service => service, :type => :builtin, :description => description, :resource => resource} res[resource][:init_options] = unless .empty? end end |