Class: Templar::Processor
- Inherits:
-
Object
- Object
- Templar::Processor
- Defined in:
- lib/templar/processor.rb
Overview
This is the implementation of template processing.
Instance Attribute Summary collapse
-
#config ⇒ Templar::Config
readonly
Contains the templar configuration data, usually config/templar.yml.
-
#data ⇒ Templar::Config
readonly
Contains the data loaded from the YAML data file, usually config/templar/data.yml.
-
#environment ⇒ String
The environment Templar is using.
Instance Method Summary collapse
-
#initialize(settings = { }) ⇒ Processor
constructor
Get a new processor.
-
#process ⇒ Object
Process configuration templates.
Constructor Details
#initialize(settings = { }) ⇒ Processor
Get a new processor
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/templar/processor.rb', line 21 def initialize(settings = { }) defaults = { :print_format => " templar: (update: %s) %s => %s" } @config = load_yaml_file("config/templar.yml", :defaults => defaults, :overrides => settings[:overrides]) @use_environments = @config.use_environments @directory = @config.directory @templates = @config.templates || [] @data = load_yaml_file(data_file) raise "Data is empty. Missing environment in data settings?" unless @data end |
Instance Attribute Details
#config ⇒ Templar::Config (readonly)
Returns contains the templar configuration data, usually config/templar.yml.
12 13 14 |
# File 'lib/templar/processor.rb', line 12 def config @config end |
#data ⇒ Templar::Config (readonly)
Returns contains the data loaded from the YAML data file, usually config/templar/data.yml.
14 15 16 |
# File 'lib/templar/processor.rb', line 14 def data @data end |
#environment ⇒ String
Returns the environment Templar is using.
16 17 18 |
# File 'lib/templar/processor.rb', line 16 def environment @environment end |
Instance Method Details
#process ⇒ Object
Process configuration templates
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/templar/processor.rb', line 39 def process if @use_environments @environment ||= begin if defined?(Rails) Rails.env elsif ENV['ENVIRONMENT'] ENV['ENVIRONMENT'] else nil end end raise "Use Environments option is true, but environment is not set (#{@config.inspect})" if @use_environments && !@environment raise "Data is empty, missing environment?" unless @data[@environment.to_sym] @data = @data[@environment.to_sym] end raise "Data is empty, please check configuration" unless @data process_templates end |