Class: Flor::HashLoader
- Inherits:
-
CoreLoader
- Object
- CoreLoader
- Flor::HashLoader
- Defined in:
- lib/flor/unit/hloader.rb
Overview
A loader which keeps everything in a Hash, while the traditional/default Flor::Loader reads from a file tree.
Defined Under Namespace
Modules: UnitAdders
Constant Summary collapse
- HCATS =
{ 'v' => 'variables', 'var' => 'variables', 'variable' => 'variables', 'flo' => 'libraries', 'flow' => 'libraries', 'lib' => 'libraries', 'library' => 'libraries', 'sub' => 'sublibraries', 'sublib' => 'sublibraries', 'sublibrary' => 'sublibraries', 'tasker' => 'taskers', 'hook' => 'hooks' }
- CATS =
HCATS.values.uniq
Instance Attribute Summary collapse
-
#environment ⇒ Object
NB: tasker configuration entries start with “loa_”, like for Flor::Loader.
Instance Method Summary collapse
- #add(cat, path, value, &block) ⇒ Object
- #definitions(start = nil) ⇒ Object
- #domains(start = nil) ⇒ Object
- #hooks(domain) ⇒ Object
-
#initialize(unit) ⇒ HashLoader
constructor
A new instance of HashLoader.
-
#library(domain, name = nil, opts = {}) ⇒ Object
If found, returns [ source_path, path ].
- #load_hooks(exid) ⇒ Object
- #remove(cat, path) ⇒ Object
- #tasker(domain, name, message = {}) ⇒ Object
- #variables(domain) ⇒ Object
Methods inherited from CoreLoader
Constructor Details
#initialize(unit) ⇒ HashLoader
Returns a new instance of HashLoader.
22 23 24 25 26 27 28 29 |
# File 'lib/flor/unit/hloader.rb', line 22 def initialize(unit) @unit = unit class << @unit; include Flor::HashLoader::UnitAdders; end self.environment = (@unit.conf['lod_environment'] || {}) end |
Instance Attribute Details
#environment ⇒ Object
NB: tasker configuration entries start with “loa_”, like for Flor::Loader
12 13 14 |
# File 'lib/flor/unit/hloader.rb', line 12 def environment @environment end |
Instance Method Details
#add(cat, path, value, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/flor/unit/hloader.rb', line 47 def add(cat, path, value, &block) c = recat(cat) path = path.to_s path = path + '.' if c == 'hooks' && path.length > 0 && path[-1, 1] != '.' value = if block block_to_class(c, block) elsif value.is_a?(Proc) block_to_class(c, value) else Flor.to_string_keyed_hash(value) end e = (@environment[c] ||= []) e << [ *split(path), value ] e.sort_by! { |pa, _, _| pa.count('.') } end |
#definitions(start = nil) ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/flor/unit/hloader.rb', line 151 def definitions(start=nil) start ||= '' @environment.values .flatten(1) .collect { |x| x[0, 2].join('.') } .select { |fl| Flor.sub_domain?(start, fl) } .sort end |
#domains(start = nil) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/flor/unit/hloader.rb', line 138 def domains(start=nil) start ||= '' @environment.values .flatten(1) .collect { |x| x.first } .select { |dm| dm && dm.length > 0 } .select { |dm| Flor.sub_domain?(start, dm) } .uniq .sort end |
#hooks(domain) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/flor/unit/hloader.rb', line 125 def hooks(domain) entries('hooks', domain) .collect { |_, _, va| to_conf_h('hooks', domain, va, {}) } .flatten(1) end |
#library(domain, name = nil, opts = {}) ⇒ Object
If found, returns [ source_path, path ]
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/flor/unit/hloader.rb', line 94 def library(domain, name=nil, opts={}) path, key = split(domain, name) libs = entries('libraries', path) if opts[:subflows] # used by "graft"/"import" libs += entries('sublibraries', path) libs = libs.sort_by { |pa, _, _| pa.count('.') } end libs .each { |pa, ke, va| next unless ke == key return [ [ pa, ke ].join('.'), va ] } nil end |
#load_hooks(exid) ⇒ Object
132 133 134 135 136 |
# File 'lib/flor/unit/hloader.rb', line 132 def load_hooks(exid) hooks(Flor.domain(exid)) .collect { |h| Flor::Hook.new(@unit, exid, h) } end |
#remove(cat, path) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/flor/unit/hloader.rb', line 68 def remove(cat, path) c = recat(cat) e = @environment[c] return [] unless e pa, ke = split(path) e.reject! { |epa, eke, _| epa == pa && eke == ke } end |
#tasker(domain, name, message = {}) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/flor/unit/hloader.rb', line 112 def tasker(domain, name, ={}) path, key = split(domain, name) entries('taskers', path) .reverse # FIXME .each { |pa, ke, va| next unless ke == key return to_conf_h('taskers', pa, va, ) } nil end |
#variables(domain) ⇒ Object
80 81 82 83 84 |
# File 'lib/flor/unit/hloader.rb', line 80 def variables(domain) entries('variables', domain) .inject({}) { |h, (_, k, v)| h[k] = v; h } end |