Class: Shipitron::MustacheYamlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/shipitron/mustache_yaml_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, options = {}) ⇒ MustacheYamlParser

Returns a new instance of MustacheYamlParser.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/shipitron/mustache_yaml_parser.rb', line 6

def initialize(file_path, options = {})
  @context = options[:context]
  @view = options[:view]

  if (@context.nil? && @view.nil?) || (!@context.nil? && !@view.nil?)
    raise ArgumentError, 'Either context or view required'
  end

  @file_path = file_path.is_a?(Pathname) ? file_path.to_s : file_path
  @view ||= Mustache
end

Class Method Details

.perform(file_path, options = {}) ⇒ Object



22
23
24
# File 'lib/shipitron/mustache_yaml_parser.rb', line 22

def self.perform(file_path, options = {})
  new(file_path, options).perform
end

Instance Method Details

#performObject



18
19
20
# File 'lib/shipitron/mustache_yaml_parser.rb', line 18

def perform
  YAML.load(@view.render(File.read(@file_path), @context))
end