Class: Temp::Tempfile

Inherits:
Object
  • Object
show all
Defined in:
lib/temp/tempfile.rb

Overview

A Tempfile object acts as a sandbox for the Tempfile DSL.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, options = {}) ⇒ Tempfile

Loads a Tempfile in the specified directory. Options can be passed so that they can be accessed from the Tempfile.



10
11
12
13
14
15
16
17
18
# File 'lib/temp/tempfile.rb', line 10

def initialize(dir, options = {})
  @dir = File.expand_path(dir)
  @file = File.join(@dir, 'Tempfile')
  @options = options
  @info = {}
  @ignore_files = []
  @erb_files = []
  instance_eval File.read(@file) if File.file? @file
end

Instance Attribute Details

#erb_filesObject (readonly)

Returns the value of attribute erb_files.



6
7
8
# File 'lib/temp/tempfile.rb', line 6

def erb_files
  @erb_files
end

#ignore_filesObject (readonly)

Returns the value of attribute ignore_files.



6
7
8
# File 'lib/temp/tempfile.rb', line 6

def ignore_files
  @ignore_files
end

#infoObject (readonly)

Returns the value of attribute info.



6
7
8
# File 'lib/temp/tempfile.rb', line 6

def info
  @info
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/temp/tempfile.rb', line 6

def options
  @options
end

Instance Method Details

#desc(str) ⇒ Object

Sets the template description



31
32
33
# File 'lib/temp/tempfile.rb', line 31

def desc(str)
  info[:desc] = str
end

#get_bindingObject

Gets the object’s binding



21
22
23
# File 'lib/temp/tempfile.rb', line 21

def get_binding
  binding
end

#ignore(*files) ⇒ Object

Adds files to the ignore list by expanding the given glob(s)



36
37
38
39
40
# File 'lib/temp/tempfile.rb', line 36

def ignore(*files)
  @ignore_files |= files.map do |file|
    Dir.glob(File.join(@dir, file)).map { |f| f.sub(@dir + '/', '') }
  end.flatten
end

#name(str) ⇒ Object

Sets the template name



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

def name(str)
  info[:name] = str
end

#use_erb(*files) ⇒ Object

Adds files to the ERB list by expanding the given glob(s)



43
44
45
46
47
# File 'lib/temp/tempfile.rb', line 43

def use_erb(*files)
  @erb_files |= files.map do |file|
    Dir.glob(File.join(@dir, file)).map { |f| f.sub(@dir + '/', '') }
  end.flatten
end