Module: Files
- Defined in:
- lib/files.rb,
lib/files/version.rb
Defined Under Namespace
Classes: Files
Constant Summary collapse
- VERSION =
"0.4.0"
Class Method Summary collapse
- .called_from(level = 1) ⇒ Object
- .create(options = default_options, &block) ⇒ Object
-
.default_options(level = 2) ⇒ Object
class methods.
Instance Method Summary collapse
- #dir(*args, &block) ⇒ Object
- #file(*args, &block) ⇒ Object
-
#files(options = ::Files.default_options) ⇒ Object
mixin methods.
Class Method Details
.called_from(level = 1) ⇒ Object
11 12 13 14 15 |
# File 'lib/files.rb', line 11 def self.called_from level = 1 line = caller[level] line.gsub!(/^.:/, '') # correct for leading Windows C: File.basename line.split(':').first, ".rb" end |
.create(options = default_options, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/files.rb', line 17 def self.create = , &block require 'tmpdir' require 'fileutils' name = [:name] root = Dir::tmpdir # if the user specified a root directory (instead of default Dir.tmpdir) if [:path] # then we will create their directory for them (test context-be friendly) root = [:path] FileUtils::mkdir_p(root) # if they gave relative path, this forces absolute root = File.(root) end path = File.join(root, "#{name}_#{Time.now.to_i}_#{rand(1000)}") Files.new path, block, end |
.default_options(level = 2) ⇒ Object
class methods
7 8 9 |
# File 'lib/files.rb', line 7 def self. level = 2 {:remove => true, :name => called_from(level)} end |
Instance Method Details
#dir(*args, &block) ⇒ Object
46 47 48 |
# File 'lib/files.rb', line 46 def dir *args, &block files.dir *args, &block end |
#file(*args, &block) ⇒ Object
42 43 44 |
# File 'lib/files.rb', line 42 def file *args, &block files.file *args, &block end |