Module: PathMapper::Node::Dir::Inheritance::Base
- Defined in:
- lib/path_mapper/node/dir/inheritance/base.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #<<(mapper) ⇒ Object
- #f(m, overlay: true, **kwargs) ⇒ Object
- #with_inheritance(obj, **kwargs) ⇒ Object
Instance Attribute Details
#inheritance ⇒ Object
8 9 10 |
# File 'lib/path_mapper/node/dir/inheritance/base.rb', line 8 def inheritance @inheritance ||= [] end |
Instance Method Details
#<<(mapper) ⇒ Object
12 13 14 |
# File 'lib/path_mapper/node/dir/inheritance/base.rb', line 12 def <<(mapper) self.inheritance << mapper end |
#f(m, overlay: true, **kwargs) ⇒ Object
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 |
# File 'lib/path_mapper/node/dir/inheritance/base.rb', line 16 def f(m, overlay: true, **kwargs) def with_inheritance(obj, **kwargs) if obj.respond_to? :dir? and obj.dir? obj.inheritance = self.inheritance.map do |inheritor| next if inheritor.path == obj.path.dirname unless (resp = inheritor.f(obj.name, kwargs)).empty? resp end end.compact end obj. = self._create_node(self..path.join(obj.name)) obj end resp = [] base_resp = nil ["#{m.to_s}.erb", m.to_s].each {|fname| base_resp = with_inheritance(self._create_node(@path.join(fname)), kwargs) if base_resp.nil? } resp << base_resp self.inheritance.each do |inherit| unless (resp_ = with_inheritance(inherit.f(m, kwargs), kwargs)).nil? if return resp_ else resp << resp_ end end end if ! || ( and base_resp.empty?) if base_resp.empty? and kwargs.key? :default kwargs[:default] else ? resp.first : resp.select {|node| !node.is_a? Null } end end |
#with_inheritance(obj, **kwargs) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/path_mapper/node/dir/inheritance/base.rb', line 17 def with_inheritance(obj, **kwargs) if obj.respond_to? :dir? and obj.dir? obj.inheritance = self.inheritance.map do |inheritor| next if inheritor.path == obj.path.dirname unless (resp = inheritor.f(obj.name, kwargs)).empty? resp end end.compact end obj. = self._create_node(self..path.join(obj.name)) obj end |