Class: Hobber::TmplVarExtractor::Yaml

Inherits:
Object
  • Object
show all
Defined in:
lib/hobber/tmpl_var_extractor/yaml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(combined_content, path = nil) ⇒ Yaml

Returns a new instance of Yaml.



10
11
12
13
14
15
16
17
# File 'lib/hobber/tmpl_var_extractor/yaml.rb', line 10

def initialize(combined_content, path=nil)
  @combined_content = combined_content
  @path = path

  @tmpl_content = combined_content
  @tmpl_vars = {}
  extract
end

Instance Attribute Details

#combined_contentObject (readonly)

Returns the value of attribute combined_content.



8
9
10
# File 'lib/hobber/tmpl_var_extractor/yaml.rb', line 8

def combined_content
  @combined_content
end

#tmpl_contentObject (readonly)

Returns the value of attribute tmpl_content.



8
9
10
# File 'lib/hobber/tmpl_var_extractor/yaml.rb', line 8

def tmpl_content
  @tmpl_content
end

#tmpl_varsObject (readonly)

Returns the value of attribute tmpl_vars.



8
9
10
# File 'lib/hobber/tmpl_var_extractor/yaml.rb', line 8

def tmpl_vars
  @tmpl_vars
end

Instance Method Details

#extractObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hobber/tmpl_var_extractor/yaml.rb', line 19

def extract
  @tmpl_vars = {}
  if @combined_content.match(/\s*---.*---/m)
    ignore, yaml_buffer, tmpl_content = @combined_content.split(/---/,3)
    @tmpl_content = tmpl_content
    @tmpl_vars = YAML.parse(yaml_buffer).to_ruby
    @tmpl_vars = HashWithIndifferentAccess.new(@tmpl_vars)
  end
# rescue Psych::SyntaxError => e
rescue => e
  debugger
  error = ProblemParsingYaml.new(["#{e.message} (#{e.class})", "while trying to extract tmpl_vars from [#{@path}]"] * " -- ")
  error.set_backtrace(e.backtrace)
  raise error
end