Class: FoundersTemplate::TemplateFile
- Inherits:
-
Object
- Object
- FoundersTemplate::TemplateFile
- Defined in:
- lib/founders_template/template_file.rb
Direct Known Subclasses
Class Method Summary collapse
- .output_file(file_name = nil) ⇒ Object
- .required_keys(keys = nil) ⇒ Object
- .root_key(key = nil) ⇒ Object
- .template_file(file_name = nil) ⇒ Object
Instance Method Summary collapse
- #binding_for_render ⇒ Object
-
#initialize(output_directory) ⇒ TemplateFile
constructor
A new instance of TemplateFile.
- #output_file ⇒ Object
- #template_file ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(output_directory) ⇒ TemplateFile
Returns a new instance of TemplateFile.
25 26 27 28 29 30 31 32 33 |
# File 'lib/founders_template/template_file.rb', line 25 def initialize(output_directory) @output_directory = output_directory @data = File.exist?(output_file) && YAML.load_file(output_file) return unless @data @data = @data[self.class.root_key] if self.class.root_key @data.symbolize_keys! load_data end |
Class Method Details
.output_file(file_name = nil) ⇒ Object
10 11 12 13 |
# File 'lib/founders_template/template_file.rb', line 10 def self.output_file(file_name = nil) @output_file = file_name if file_name @output_file ||= nil end |
.required_keys(keys = nil) ⇒ Object
20 21 22 23 |
# File 'lib/founders_template/template_file.rb', line 20 def self.required_keys(keys = nil) @required_keys = keys if keys @required_keys ||= [] end |
.root_key(key = nil) ⇒ Object
5 6 7 8 |
# File 'lib/founders_template/template_file.rb', line 5 def self.root_key(key = nil) @root_key = key if key @root_key ||= nil end |
.template_file(file_name = nil) ⇒ Object
15 16 17 18 |
# File 'lib/founders_template/template_file.rb', line 15 def self.template_file(file_name = nil) @template_file = file_name if file_name @template_file ||= nil end |
Instance Method Details
#binding_for_render ⇒ Object
39 40 41 |
# File 'lib/founders_template/template_file.rb', line 39 def binding_for_render binding end |
#output_file ⇒ Object
47 48 49 |
# File 'lib/founders_template/template_file.rb', line 47 def output_file File.join(@output_directory, self.class.output_file) end |
#template_file ⇒ Object
43 44 45 |
# File 'lib/founders_template/template_file.rb', line 43 def template_file self.class.template_file end |
#valid? ⇒ Boolean
35 36 37 |
# File 'lib/founders_template/template_file.rb', line 35 def valid? self.class.required_keys.none? { |key| public_send(key).nil? } end |