class FoundersTemplate::TemplateFile

Public Class Methods

new(output_directory) click to toggle source
# 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
output_file(file_name = nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Public Instance Methods

binding_for_render() click to toggle source
# File lib/founders_template/template_file.rb, line 39
def binding_for_render
  binding
end
output_file() click to toggle source
# File lib/founders_template/template_file.rb, line 47
def output_file
  File.join(@output_directory, self.class.output_file)
end
template_file() click to toggle source
# File lib/founders_template/template_file.rb, line 43
def template_file
  self.class.template_file
end
valid?() click to toggle source
# File lib/founders_template/template_file.rb, line 35
def valid?
  self.class.required_keys.none? { |key| public_send(key).nil? }
end

Private Instance Methods

load_data() click to toggle source
# File lib/founders_template/template_file.rb, line 53
def load_data
  @data.each do |key, value|
    public_send("#{key}=", value)
  end
end