Module: Files

Defined in:
lib/files.rb,
lib/files/version.rb

Defined Under Namespace

Classes: Files

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.called_from(level = 1) ⇒ Object



11
12
13
# File 'lib/files.rb', line 11

def self.called_from level = 1
  File.basename caller[level].split(':').first, ".rb"
end

.create(options = default_options, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/files.rb', line 15

def self.create options = default_options, &block
  require 'tmpdir'
  require 'fileutils'

  name = options[:name]
  path = File.join(Dir::tmpdir, "#{name}_#{Time.now.to_i}_#{rand(1000)}")

  Files.new path, block, options
end

.default_options(level = 2) ⇒ Object

class methods



7
8
9
# File 'lib/files.rb', line 7

def self.default_options level = 2
  {:remove => true, :name => called_from(level)}
end

Instance Method Details

#dir(*args, &block) ⇒ Object



34
35
36
# File 'lib/files.rb', line 34

def dir *args, &block
  files.dir *args, &block
end

#file(*args, &block) ⇒ Object



30
31
32
# File 'lib/files.rb', line 30

def file *args, &block
  files.file *args, &block
end

#files(options = ::Files.default_options) ⇒ Object

mixin methods



26
27
28
# File 'lib/files.rb', line 26

def files options = ::Files.default_options   # todo: block
  @files ||= ::Files.create(options)
end