Class: Disloku::Config::Mapping
- Inherits:
-
Object
- Object
- Disloku::Config::Mapping
- Defined in:
- lib/disloku/config/Mapping.rb
Instance Method Summary collapse
- #getTree ⇒ Object
-
#initialize(config, mappingStore = nil, allowDefault = true) ⇒ Mapping
constructor
A new instance of Mapping.
- #mapPath(pathSegments) ⇒ Object
Constructor Details
#initialize(config, mappingStore = nil, allowDefault = true) ⇒ Mapping
Returns a new instance of Mapping.
9 10 11 12 13 14 15 16 17 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 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/disloku/config/Mapping.rb', line 9 def initialize(config, mappingStore = nil, allowDefault = true) @mapping = {} symbolize = Proc.new() do |s| match = s.match(/^:(.*)/) match.nil? ? s : match[1].to_sym() end mappingConfig = config["mapping"] if (!mappingConfig.nil?) mappingConfig.value().each() do |m| node = @mapping src = m["src"].value() if (src.kind_of?(Symbol)) segments = [src] else segments = Util::File.getSegments(src).map(&symbolize) end segments[0..-2].each() do |segment| if (!node.has_key?(segment)) node[segment] = {} end node = node[segment] end dst = m["dst"].value() if (dst.kind_of?(Symbol)) node[segments[-1]] = dst else node[segments[-1]] = Util::File.getSegments(dst) end end elsif (allowDefault) @mapping[:any] = :keep end baseMapping = config["baseMapping"].nil? ? nil : config["baseMapping"].value() if (!baseMapping.nil?) if (mappingStore.nil?) raise ArgumentError.new("mapping has a base but no mapping manager was passed") else @mapping = mappingStore.get(baseMapping).getTree().recursive_merge(@mapping) end end end |
Instance Method Details
#getTree ⇒ Object
58 59 60 |
# File 'lib/disloku/config/Mapping.rb', line 58 def getTree() return @mapping end |
#mapPath(pathSegments) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/disloku/config/Mapping.rb', line 62 def mapPath(pathSegments) node = @mapping for i in 0..pathSegments.count if (node.has_key?(pathSegments[i])) node = node[pathSegments[i]] elsif (node.has_key?(:any)) node = node[:any] else return nil end if (node == :block) return nil elsif (node == :keep) return pathSegments elsif (node.kind_of?(Array)) return Array.new(node).concat(pathSegments[(i + 1)..-1]) end end end |