Class: Temp::Tempfile
- Inherits:
-
Object
- Object
- Temp::Tempfile
- Defined in:
- lib/temp/tempfile.rb
Overview
A Tempfile object acts as a sandbox for the Tempfile DSL.
Instance Attribute Summary collapse
-
#erb_files ⇒ Object
readonly
Returns the value of attribute erb_files.
-
#ignore_files ⇒ Object
readonly
Returns the value of attribute ignore_files.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#desc(str) ⇒ Object
Sets the template description.
-
#get_binding ⇒ Object
Gets the object’s binding.
-
#ignore(*files) ⇒ Object
Adds files to the ignore list by expanding the given glob(s).
-
#initialize(dir, options = {}) ⇒ Tempfile
constructor
Loads a Tempfile in the specified directory.
-
#name(str) ⇒ Object
Sets the template name.
-
#use_erb(*files) ⇒ Object
Adds files to the ERB list by expanding the given glob(s).
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, = {}) @dir = File.(dir) @file = File.join(@dir, 'Tempfile') @options = @info = {} @ignore_files = [] @erb_files = [] instance_eval File.read(@file) if File.file? @file end |
Instance Attribute Details
#erb_files ⇒ Object (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_files ⇒ Object (readonly)
Returns the value of attribute ignore_files.
6 7 8 |
# File 'lib/temp/tempfile.rb', line 6 def ignore_files @ignore_files end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
6 7 8 |
# File 'lib/temp/tempfile.rb', line 6 def info @info end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/temp/tempfile.rb', line 6 def @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_binding ⇒ Object
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 |