Sha256: e94a1d727f82e70ff39eb4d259ed411d43da9650b7d44178b0b5d05b6ad7b839

Contents?: true

Size: 1.31 KB

Versions: 48

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require_relative '../../models/color_theme'

module Dsu
  module Services
    module ColorTheme
      class HydratorService
        def initialize(theme_name:, theme_hash:, options: {})
          raise ArgumentError, 'theme_name is nil.' if theme_name.nil?
          raise ArgumentError, "theme_name is the wrong object type: \"#{theme_name}\"." unless theme_hash.is_a?(Hash)
          raise ArgumentError, 'theme_hash is nil' if theme_hash.nil?
          raise ArgumentError, "theme_hash is the wrong object type: \"#{theme_hash}\"" unless theme_hash.is_a?(Hash)
          raise ArgumentError, 'options is nil' if options.nil?
          raise ArgumentError, "options is the wrong object type:\"#{options}\"" unless options.is_a?(Hash)

          @theme_name = theme_name
          @theme_hash = theme_hash
          @options = options || {}
        end

        def call
          Models::ColorTheme.new(theme_name: theme_name, theme_hash: hydrate)
        end

        private

        attr_reader :theme_hash, :theme_name, :options

        def hydrate
          theme_hash.each_pair do |key, value|
            next if %i[version description].include?(key)

            value.each_pair do |k, _v|
              value[k] = value[k].to_sym
            end
          end
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
dsu-3.0.5 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.4 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.3 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.1 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.beta.3 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.beta.2 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.beta.1 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.beta.0 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.12 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.11 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.10 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.9 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.8 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.7 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.6 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.5 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.4 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.3 lib/dsu/services/color_theme/hydrator_service.rb
dsu-3.0.0.alpha.2 lib/dsu/services/color_theme/hydrator_service.rb