Sha256: e88219be0cf7bd5919131d257f1b5f38cdf03ad5d90bbe7c1374bdb678f75cef

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

module Evva
  class Config
    def initialize(hash:)
      @hash = hash.deep_symbolize
      @hash.validate_structure!(CONFIG_STRUCT)

      unless dict_struct = DICTIONARY_STRUCT[@hash[:data_source][:type]]
        raise ArgumentError, "unknown data source type '#{@hash[:data_source][:type]}'"
      end

      @hash[:data_source].validate_structure!(dict_struct)
    end

    def to_h
      @hash
    end

    def data_source
      @hash[:data_source]
    end

    def type
      @hash[:type]
    end

    def out_path
      @hash[:out_path]
    end

    def event_file_name
      @hash[:event_file_name]
    end

    def event_enum_file_name
      @hash[:event_enum_file_name]
    end

    def people_file_name
      @hash[:people_file_name]
    end

    def people_enum_file_name
      @hash[:people_enum_file_name]
    end

    def special_enum_file_name
      @hash[:special_enum_file_name]
    end

    def destinations_file_name
      @hash[:destinations_file_name]
    end

    def package_name
      @hash[:package_name]
    end

    CONFIG_STRUCT = {
      type: Hash,
      elements: {
        type: { type: String },
        data_source: { type: Hash, elements: {
          type: { type: String }
        } },
        out_path: { type: String },
        event_file_name: { type: String },
        event_enum_file_name: { type: String },
        people_file_name: { type: String },
        people_enum_file_name: { type: String },
        destinations_file_name: { type: String },
        package_name: { type: String }
      }
    }.freeze

    GOOGLE_SHEET_STRUCT = {
      type: Hash,
      elements: {
        type: { type: String },
        events_url: { type: String },
        people_properties_url: { type: String },
        enum_classes_url: { type: String },
      }
    }.freeze

    DICTIONARY_STRUCT = {
      'google_sheet' => GOOGLE_SHEET_STRUCT
    }.freeze
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
evva-0.4.4 lib/evva/config.rb
evva-0.4.3 lib/evva/config.rb
evva-0.4.2 lib/evva/config.rb
evva-0.4.1 lib/evva/config.rb
evva-0.4.0 lib/evva/config.rb