Sha256: 66c71c7f3b608b5ac141f128bab388258e27003dfe451830925129f813632394

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 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
      message = "Unknown data source#{invalid_data_sources.size > 1 ? 's' : ''} \"#{invalid_data_sources.join(', ')}\" found."
      fail Exceptions::DataSourcesAreInvalid, message unless invalid_data_sources.empty?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
filegen-0.4.3 lib/filegen/data_source_builder.rb
filegen-0.4.1 lib/filegen/data_source_builder.rb
filegen-0.4.0 lib/filegen/data_source_builder.rb
filegen-0.3.1 lib/filegen/data_source_builder.rb