Class: Gem2Rpm::Template
- Inherits:
-
Object
- Object
- Gem2Rpm::Template
- Defined in:
- lib/gem2rpm/template.rb
Defined Under Namespace
Classes: TemplateError
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
Class Method Summary collapse
- .default_location ⇒ Object
- .default_location=(location) ⇒ Object
-
.find(name = nil, options = {}) ⇒ Object
Returns instance of Template class.
- .list ⇒ Object
Instance Method Summary collapse
-
#initialize(filename) ⇒ Template
constructor
Create instance of Template class of specified template filename.
-
#read ⇒ Object
Read the content of the template file.
Constructor Details
#initialize(filename) ⇒ Template
Create instance of Template class of specified template filename. TemplateError is raised when the template file does not exists.
50 51 52 53 54 55 56 |
# File 'lib/gem2rpm/template.rb', line 50 def initialize(filename) if File.exist? filename @filename = filename else fail TemplateError, "Could not locate template #{filename}" end end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
5 6 7 |
# File 'lib/gem2rpm/template.rb', line 5 def filename @filename end |
Class Method Details
.default_location ⇒ Object
7 8 9 |
# File 'lib/gem2rpm/template.rb', line 7 def self.default_location @@location ||= File.join(File.dirname(__FILE__), '..', '..', 'templates') end |
.default_location=(location) ⇒ Object
11 12 13 14 |
# File 'lib/gem2rpm/template.rb', line 11 def self.default_location=(location) @@location = location @@list = nil end |
.find(name = nil, options = {}) ⇒ Object
Returns instance of Template class. If the ‘name’ parameter is specified it tries to instantiate the template of specific name first. When options is specified, it can be taken into consideration when looking for vagrant templates for example.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gem2rpm/template.rb', line 26 def self.find(name = nil, = {}) if name.nil? gem_file = File.basename([:gem_file]) if [:gem_file] case gem_file when /^vagrant(-|_).*/ Gem2Rpm.vagrant_plugin_template else Gem2Rpm.rubygem_template end else begin if File.exist?(name) Gem2Rpm::Template.new(name) else Gem2Rpm::Template.new(File.join(Gem2Rpm::Template.default_location, name + '.spec.erb')) end rescue TemplateError raise TemplateError, "Could not locate template #{name}" end end end |
.list ⇒ Object
16 17 18 19 20 |
# File 'lib/gem2rpm/template.rb', line 16 def self.list @@list ||= Dir.chdir(default_location) do Dir.glob('*').sort end end |
Instance Method Details
#read ⇒ Object
Read the content of the template file.
59 60 61 62 63 |
# File 'lib/gem2rpm/template.rb', line 59 def read @content ||= begin File.open(@filename, OPEN_MODE, &:read) end end |