Sha256: 755112fb03200d473a5d4c633015cca66f94b7af00866f673fcd315e985851d6

Contents?: true

Size: 811 Bytes

Versions: 1

Compression:

Stored size: 811 Bytes

Contents

# frozen_string_literal: true

require 'yaml'
require 'uri'

module Quicken
  class Parser
    def initialize recipe_path
      @recipe_path = recipe_path
      @plugins = []
    end

    def parse
      file = load_file(@recipe_path)
      recipe = YAML.safe_load(file)
      LOGGER.debug(:parser) { "Parsed recipe #{recipe.inspect}" }
      @plugins.tap do |plugins|
        recipe.each do |step|
          plugin_name = step.keys.first
          plugin_args = step[plugin_name]
          plugins << PluginConfiguration.new(plugin_name, plugin_args)
        end
      end
    end

    private

    def load_file path
      uri = URI(path)
      case uri.scheme
      when 'http', 'https'
        require 'net/http'
        Net::HTTP.get(uri)
      else
        File.read(uri.path)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quicken-ruby-0.1.1 lib/quicken/parser.rb