Class: Hobber::TmplVarExtractor::Yaml
- Inherits:
-
Object
- Object
- Hobber::TmplVarExtractor::Yaml
- Defined in:
- lib/hobber/tmpl_var_extractor/yaml.rb
Instance Attribute Summary collapse
-
#combined_content ⇒ Object
readonly
Returns the value of attribute combined_content.
-
#tmpl_content ⇒ Object
readonly
Returns the value of attribute tmpl_content.
-
#tmpl_vars ⇒ Object
readonly
Returns the value of attribute tmpl_vars.
Instance Method Summary collapse
- #extract ⇒ Object
-
#initialize(combined_content, path = nil) ⇒ Yaml
constructor
A new instance of Yaml.
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_content ⇒ Object (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_content ⇒ Object (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_vars ⇒ Object (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
#extract ⇒ Object
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.} (#{e.class})", "while trying to extract tmpl_vars from [#{@path}]"] * " -- ") error.set_backtrace(e.backtrace) raise error end |