Class: Templar::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/templar/processor.rb

Overview

This is the implementation of template processing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = { }) ⇒ Processor

Get a new processor

Parameters:

  • config_overrides (Hash)

    these values will be merged on top of the defaults.



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

#configTemplar::Config (readonly)

Returns contains the templar configuration data, usually config/templar.yml.

Returns:

  • (Templar::Config)

    contains the templar configuration data, usually config/templar.yml



12
13
14
# File 'lib/templar/processor.rb', line 12

def config
  @config
end

#dataTemplar::Config (readonly)

Returns contains the data loaded from the YAML data file, usually config/templar/data.yml.

Returns:

  • (Templar::Config)

    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

#environmentString

Returns the environment Templar is using.

Returns:

  • (String)

    the environment Templar is using



16
17
18
# File 'lib/templar/processor.rb', line 16

def environment
  @environment
end

Instance Method Details

#processObject

Process configuration templates

Raises:



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