Module: IMW::Resources::LocalDirectory

Defined in:
lib/imw/resources/local.rb

Instance Method Summary collapse

Instance Method Details

#[](selector = '*') ⇒ Array

Return a list of paths relative to this directory which match the selector. Works just like Dir[].

Parameters:

  • selector (String) (defaults to: '*')

Returns:

  • (Array)

    the matched paths



153
154
155
# File 'lib/imw/resources/local.rb', line 153

def [] selector='*'
  Dir[File.join(path, selector)]
end

#all_contentsArray<String>

Return all paths within this directory, recursively.

Returns:



180
181
182
# File 'lib/imw/resources/local.rb', line 180

def all_contents
  self['**/*']
end

#contains?(obj) ⇒ true, false

Does this directory contain obj?

Parameters:

Returns:

  • (true, false)


168
169
170
171
172
173
174
175
# File 'lib/imw/resources/local.rb', line 168

def contains? obj
  require 'find'
  obj_path = obj.is_a?(String) ? obj : obj.path
  Find.find(path) do |sub_path|
    return true if sub_path.ends_with?(obj_path)
  end
  false
end

#contentsArray

Return a list of all paths directly within this directory.

Returns:



160
161
162
# File 'lib/imw/resources/local.rb', line 160

def contents
  self['*']
end

#resourcesArray<IMW::Resource>

Return all resources within this directory, i.e. - all paths converted to IMW::Resource objects.

Returns:



188
189
190
191
192
# File 'lib/imw/resources/local.rb', line 188

def resources
  all_contents.map do |path|
    IMW.open(path) unless File.directory?(path)
  end.compact
end

#rm_rfIMW::Resource

Delete this directory recursively.

Returns:



143
144
145
146
# File 'lib/imw/resources/local.rb', line 143

def rm_rf
  FileUtils.rm_rf path
  self
end

#rmdirIMW::Resource

Delete this directory.

Returns:



135
136
137
138
# File 'lib/imw/resources/local.rb', line 135

def rmdir
  FileUtils.rmdir path
  self
end