Module: IMW::Resources::LocalDirectory
- Defined in:
- lib/imw/resources/local.rb
Instance Method Summary collapse
-
#[](selector = '*') ⇒ Array
Return a list of paths relative to this directory which match the
selector
. -
#all_contents ⇒ Array<String>
Return all paths within this directory, recursively.
-
#contains?(obj) ⇒ true, false
Does this directory contain
obj
?. -
#contents ⇒ Array
Return a list of all paths directly within this directory.
-
#resources ⇒ Array<IMW::Resource>
Return all resources within this directory, i.e.
-
#rm_rf ⇒ IMW::Resource
Delete this directory recursively.
-
#rmdir ⇒ IMW::Resource
Delete this directory.
Instance Method Details
#[](selector = '*') ⇒ Array
Return a list of paths relative to this directory which match the selector
. Works just like Dir[].
153 154 155 |
# File 'lib/imw/resources/local.rb', line 153 def [] selector='*' Dir[File.join(path, selector)] end |
#all_contents ⇒ Array<String>
Return all paths within this directory, recursively.
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
?
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 |
#contents ⇒ Array
Return a list of all paths directly within this directory.
160 161 162 |
# File 'lib/imw/resources/local.rb', line 160 def contents self['*'] end |
#resources ⇒ Array<IMW::Resource>
Return all resources within this directory, i.e. - all paths converted to IMW::Resource objects.
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_rf ⇒ IMW::Resource
Delete this directory recursively.
143 144 145 146 |
# File 'lib/imw/resources/local.rb', line 143 def rm_rf FileUtils.rm_rf path self end |
#rmdir ⇒ IMW::Resource
Delete this directory.
135 136 137 138 |
# File 'lib/imw/resources/local.rb', line 135 def rmdir FileUtils.rmdir path self end |