Class: MasterView::MIO::FileMIOTree
- Includes:
- MasterViewIOTreeMixin
- Defined in:
- lib/masterview/io.rb
Constant Summary
Constants included from MasterViewIOTreeMixin
MasterViewIOTreeMixin::DefaultExtensionInstances
Instance Method Summary collapse
-
#cleanup_path_get_relative_pathname(path) ⇒ Object
clean up ../..
-
#find(options = {}, &block) ⇒ Object
returns mio objects, if block_given then it yields passing the mio object to the block.
-
#initialize(root_path = Pathname.getwd, default_extension = nil, options = {}, &block) ⇒ FileMIOTree
constructor
A new instance of FileMIOTree.
- #path(path) ⇒ Object
Methods included from MasterViewIOTreeMixin
#apply_filters, #default_extension, #default_extension=, #default_mio_filter_block
Methods inherited from Pathname
for_path, join, #path_no_ext, safe_concat
Constructor Details
#initialize(root_path = Pathname.getwd, default_extension = nil, options = {}, &block) ⇒ FileMIOTree
Returns a new instance of FileMIOTree.
96 97 98 99 100 101 |
# File 'lib/masterview/io.rb', line 96 def initialize(root_path=Pathname.getwd, default_extension=nil, = {}, &block) @options = self.default_extension = default_extension super(Pathname.for_path(root_path).cleanpath) @new_mio_block = block end |
Instance Method Details
#cleanup_path_get_relative_pathname(path) ⇒ Object
clean up ../.. check if path starts with root path and if so get relative, otherwise return path
123 124 125 126 127 128 |
# File 'lib/masterview/io.rb', line 123 def cleanup_path_get_relative_pathname(path) pathname = Pathname.for_path(path) pathname = pathname.relative_path_from(self) if pathname.to_s.starts_with?(self.to_s) pathname = Pathname.for_path(pathname.to_s+self.default_extension) if pathname.extname.empty? && self.default_extension && !self.default_extension.empty? pathname end |
#find(options = {}, &block) ⇒ Object
returns mio objects, if block_given then it yields passing the mio object to the block
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/masterview/io.rb', line 110 def find( = {}, &block) path = [:path] || '.' found = [] working_path = Pathname.safe_concat(self, path) working_path.find { |p| found << p unless p.directory? } found = found.select { |f| f.basename.fnmatch?([:pattern]) } if [:pattern] found = found.collect{ |f| self.path(f.relative_path_from(self)) } # create mio objects found = found.sort { |a,b| a.pathname.to_s <=> b.pathname.to_s } found.each { |mio| yield mio } if block_given? found end |
#path(path) ⇒ Object
103 104 105 106 107 |
# File 'lib/masterview/io.rb', line 103 def path(path) raise InvalidIOPathError.new(path, 'Invalid path specified ('+path.to_s+'). Path is limited to directories under root_path ('+self.to_s+')') unless (self+path)..to_s.starts_with?(self..to_s) #ensure sandbox mio = FileMIO.new(path, self + path) apply_filters(mio, @options, @new_mio_block) end |