Sha256: 80b47346d08adf6a3e89f82ced44906c7aaa8e6b8380efd8b4dc778073eaeb66

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

# encoding: utf-8
module Filegen
  # Build data sources
  class DataSourceBuilder
    private

    attr_reader :params

    public

    # @!attribute [r] sources
    #   Return the sources generated
    attr_reader :sources

    # Create the data source builder
    #
    # @param [OpenStruct] params
    #   the params instance which contains all parameter of the commandline utility
    def initialize(params)
      @params = params

      validate_data_sources

      @sources = []
      chosen_data_sources.each do |o|
        @sources << known_data_source_builders[o]
      end
    end

    private

    def chosen_data_sources
      params.data_sources
    end

    def known_data_source_builders
      params.data_source_builders
    end

    def allowed_data_sources
      known_data_source_builders.keys
    end

    def validate_data_sources
      invalid_data_sources = chosen_data_sources - allowed_data_sources
      fail Exceptions::InvalidDataSources, "Unknown data source#{invalid_data_sources.size > 1 ? 's' : ''} \"#{invalid_data_sources.join(', ')}\" found." unless invalid_data_sources.empty?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
filegen-0.2.1 lib/filegen/data_source_builder.rb
filegen-0.2.0 lib/filegen/data_source_builder.rb
filegen-0.1.2 lib/filegen/data_source_builder.rb
filegen-0.1.1 lib/filegen/data_source_builder.rb