Sha256: bb703cd8b1c9942f537faef4160cac27459f7d0f1d23b5f337dec5fcf9318076

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

# Parse and validate options
#   * _options_ - user's set options
# Return array of options hash (from .pumper.yml) if set --config
# Return options hash unless set --config
require 'yaml'

module Pumper
  class Configuration
    class ProjectNotSet < StandardError; end
    class InvalidOptions < StandardError; end

    class << self
      def configure!(options)
        validate(options)

        options[:config] ? parse_from_config : options
      end

      private

      def validate(options)
        if options[:config] && (options[:project] || options[:gemset] || options[:vendor])
          raise InvalidOptions.new('Error: config option use without [project|gemset|vendor] options')
        end

        if options[:project].nil? && options[:config].nil?
          raise ProjectNotSet.new('You need set project (--project <PATH_TO_PROJECT>) or use config')
        end
      end

      def parse_from_config
        file = File.read(File.join(Dir.pwd, '.pumper.yml'))
        YAML.load(file)['projects'].each_with_object([]) do |(_, option), arr|
          arr.push(
            project: option['path'],
            is_absolute_path: option['absolute_path'],
            gemset: option['gemset'],
            is_vendor: option['vendor']
          )
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pumper-1.2.0 lib/pumper/configuration.rb