Module: PathMapper::Node::Dir

Includes:
Base, File, Grep, Inheritance, Representation
Included in:
DirNode
Defined in:
lib/path_mapper/node/dir.rb,
lib/path_mapper/node/dir/erb.rb,
lib/path_mapper/node/dir/file.rb,
lib/path_mapper/node/dir/grep.rb,
lib/path_mapper/node/dir/inheritance.rb,
lib/path_mapper/node/dir/representation.rb,
lib/path_mapper/node/dir/inheritance/base.rb,
lib/path_mapper/node/dir/inheritance/grep.rb

Defined Under Namespace

Modules: Erb, File, Grep, Inheritance, Representation

Instance Attribute Summary

Attributes included from Base

#name, #path

Attributes included from Base::File

#changes_overlay

Instance Method Summary collapse

Methods included from Grep

#grep, #grep_dirs, #grep_files

Methods included from Base

#initialize, #parent

Methods included from Helpers

#kwargs, #with_line_separator

Methods included from Helper::Storage

#delete_storage_branch, #deleted_files, #storage, #storage_file_delete, #storage_file_tree, #storage_tree

Methods included from Helper::Logger

#logger, #logger=, #with_logger

Methods included from Helper::Debug

#dry_run, #dry_run=, #with_dry_run

Methods included from Base::Representation

#any?, #bool, #dir?, #empty?, #file?, #float, #inspect, #int, #json, #lines, #nil?, #node?, #raw_value, #to_pathname, #to_s, #to_str, #value

Methods included from Base::File

#_append!, #_create!, #_delete!, #_override!, #_put!, #_remove_line!, #_rename!, #_safe_put!, #check, #compare_with, #custom_diff, #diff, #md5

Methods included from Base::Grep

#grep, #grep_dirs, #grep_files

Methods included from Representation

#empty?

Methods included from File

#_create!, #_delete!, #_override!, #_rename!, #md5

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



10
11
12
13
# File 'lib/path_mapper/node/dir.rb', line 10

def method_missing(m, *args, &block)
  resp = self.f(m, self.kwargs(args)) if (resp = super).is_a? NilClass # Base::File
  resp
end

Instance Method Details

#f(m, **kwargs) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/path_mapper/node/dir.rb', line 15

def f(m, **kwargs)
  def with_file_node(fname, **kwargs)
    if (obj = self._create_node(@path.join(fname))).file?
      yield obj
    end
  end

  res = case m.to_s
    when /(.*)(?=\?)/ then with_file_node($1) {|node| node.bool } || false
    when /(.*)(?=_val)/ then with_file_node($1) {|node| node.value }
    when /(.*)(?=_lines)/ then with_file_node($1) {|node| node.lines }
  end
  res.nil? ? super : res
end

#with_file_node(fname, **kwargs) ⇒ Object



16
17
18
19
20
# File 'lib/path_mapper/node/dir.rb', line 16

def with_file_node(fname, **kwargs)
  if (obj = self._create_node(@path.join(fname))).file?
    yield obj
  end
end