class Qipowl::Mappers::Mapper
Operates mapping
for loaded YAML
rules files.
-
For top level sections, each section name should have the corresponding method within Mapping class; default is ‘[:includes]` which is processed with {#includes} method which is simply loads rules from the respective file
Mapping may be loaded from YAML file, as well as be merged against other YAML file, hash or ‘Ruler` instance.
Public Class Methods
new(input = nil)
click to toggle source
# File lib/qipowl/core/mapper.rb, line 22 def initialize input = nil @hash = {} merge!(input) unless input.nil? end
Public Instance Methods
merge!(input)
click to toggle source
# File lib/qipowl/core/mapper.rb, line 29 def merge! input map = load_yaml(input) if input.is_one_of?(String, IO) raise ArgumentError.new "Invalid map (#{input} @ #{Qipowl.bowlers}) for merge in Mapper.\nCurrent dir: [#{Dir.pwd}].\n" \ unless map.respond_to? :to_hash incs = map.delete(:includes) @entities_dirty = true @hash.rmerge!(map.to_hash) incs.each { |inc| merge! inc } rescue NoMethodError # FIXME WTF rescueing here? end
to_hash()
click to toggle source
# File lib/qipowl/core/mapper.rb, line 26 def to_hash @hash end
Private Instance Methods
load_yaml(input)
click to toggle source
# File lib/qipowl/core/mapper.rb, line 50 def load_yaml input IO === input ? YAML.load_stream(input) : load_yaml_file("#{input.downcase}") end
load_yaml_file(name)
click to toggle source
# File lib/qipowl/core/mapper.rb, line 43 def load_yaml_file name [*Qipowl.bowlers].each { |b| (return YAML.load_file("#{b}/#{name}.yaml")) rescue next } nil end