Class: MasterView::MIO::StringHashMIOTree

Inherits:
Object
  • Object
show all
Includes:
MasterViewIOTreeMixin
Defined in:
lib/masterview/io.rb

Overview

MIO implemented as simple hash of path to string content This MIOTree does not keep track of mtimes and thus will always return new mtimes

Direct Known Subclasses

MTimeStringHashMIOTree

Constant Summary

Constants included from MasterViewIOTreeMixin

MasterViewIOTreeMixin::DefaultExtensionInstances

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MasterViewIOTreeMixin

#apply_filters, #cleanup_path_get_relative_pathname, #default_extension, #default_extension=, #default_mio_filter_block

Constructor Details

#initialize(string_hash = {}, default_extension = nil, options = {}, &block) ⇒ StringHashMIOTree

Returns a new instance of StringHashMIOTree.



136
137
138
139
140
141
# File 'lib/masterview/io.rb', line 136

def initialize(string_hash = {}, default_extension=nil, options={}, &block)
  @string_hash = string_hash
  @options = options
  self.default_extension = default_extension
  @new_mio_block = block
end

Instance Attribute Details

#string_hashObject

Returns the value of attribute string_hash.



135
136
137
# File 'lib/masterview/io.rb', line 135

def string_hash
  @string_hash
end

Instance Method Details

#find(options = {}) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/masterview/io.rb', line 154

def find(options = {})
  path = options[:path] || ''
  path = '' if path == '.'
  found = []
  @string_hash.each { |p,v| found << p if p.starts_with?(path) }
  found = found.select { |p| Pathname.for_path(p).basename.fnmatch?(options[:pattern]) } if options[:pattern]
  found.sort!
  found = found.collect{ |p| self.path(p) } # create mio objects
  found.each { |mio| yield mio } if block_given?
  found
end

#path(path) ⇒ Object



147
148
149
150
151
152
# File 'lib/masterview/io.rb', line 147

def path(path)
  clean_path = Pathname.for_path(path).cleanpath
  mio = StringMIO.new(clean_path, @string_hash)
  mio.pathname = clean_path
  apply_filters(mio, @options, @new_mio_block)
end