class Flor::ConfExecutor
Public Class Methods
Source
# File lib/flor/core/texecutor.rb, line 295 def determine_root(path) dir = File.absolute_path(File.dirname(path)) ps = dir.split(File::SEPARATOR) ps.last == 'etc' ? File.absolute_path(File.join(dir, '..')) : dir end
Source
# File lib/flor/core/texecutor.rb, line 217 def interpret(path, source, context) path ||= '.' fs = context['payload'] || {} vs = Hash.new { |h, k| k } # vs.merge!(context['vars'] || {}) vs['root'] = determine_root(path) vs['ruby_version'] = RUBY_VERSION vs['ruby_platform'] = RUBY_PLATFORM # class << vs def has_key?(k) prc = Flor::Procedure[k] ( ! prc) || ( ! prc.core?) # ignore non-core procedures end end c = ! (ENV['FLOR_DEBUG'] || '').match(/conf/) e = self.new('conf' => c) r = e.launch(source, payload: fs, vars: vs, path: path) unless r['point'] == 'terminated' ae = ArgumentError.new( "error while reading conf: #{r['error']['msg']}") ae.set_backtrace(r['error']['trc']) fail ae end o = Flor.dup(r['payload']['ret']) if o.is_a?(Hash) o['_path'] = path o['root'] ||= Flor.relativize_path(vs['root']) elsif o.is_a?(Array) o.each { |ee| ee['_path'] = path if ee.is_a?(Hash) } end rework_conf(o) end
Source
# File lib/flor/core/texecutor.rb, line 287 def interpret_line(s) r = interpret_source(s) r.delete('root') if r.is_a?(Hash) r end
Used by “flosh” the flor shell
Source
# File lib/flor/core/texecutor.rb, line 260 def interpret_path(path, context=nil) path = File.join(path, 'etc/conf.json') if File.directory?(path) fail ArgumentError.new( "flor configuration file not found #{path.inspect}" ) unless File.exist?(path) interpret(path, load(path), context || {}) end
Source
# File lib/flor/core/texecutor.rb, line 276 def interpret_path_or_source(s, context=nil) if s.index("\n") interpret_source(load(s), context) else interpret_path(s, context) end end
Source
# File lib/flor/core/texecutor.rb, line 271 def interpret_source(source, context=nil) interpret(nil, source, context || {}) end
Source
# File lib/flor/core/texecutor.rb, line 194 def load(path) src = if path.match(/[\r\n]/) path.strip else File.readlines(path) .reject { |l| l.strip[0, 1] == '#' } .join("\n") .strip end az = "#{src[0, 1]}#{src[-1, 1]}" if az == '{}' || az == '[]' src elsif src.match(/[^\r\n{]+:/) || src == '' "{\n#{src}\n}" else "[\n#{src}\n]" end end
Protected Class Methods
Source
# File lib/flor/core/texecutor.rb, line 308 def rework_conf(o) case o when Array o.collect { |e| rework_conf(e) } when Hash o.inject({}) { |h, (k, v)| h[k] = if Flor.is_proc_tree?(v) && v[1]['proc'] == 'return' 'return' else rework_conf(v) end h } else o end end
For now, only the return procedure has to be marshalled back to the “return” string, gh-36