Sha256: 44a18b64686ff5fa89e99b85131daa7d5f0f68f80840ce5daf9cc562b5ef6d18

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'aranha/selenium/driver_factory'
require 'eac_ruby_utils/core_ext'

module Aranha
  module Selenium
    class Defaults
      class Option
        common_constructor :owner, :key, :sanitizer, default: [nil] do
          self.key = key.to_sym
        end
        attr_accessor :user_value

        # @return [String]
        def constant_name
          "default_#{key}".upcase
        end

        # @return [Object]
        def default_value
          owner.class.const_get(constant_name)
        end

        # @return [String]
        def envvar_name
          "aranha_selenium_#{key}".upcase
        end

        # @return [Object]
        def value
          sanitized_value do
            next ENV.fetch(envvar_name) if ENV.key?(envvar_name)
            next user_value unless user_value.nil?

            default_value
          end
        end

        private

        def sanitized_value(&block)
          r = block.call
          sanitizer.present? ? sanitizer.call(r) : r
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aranha-selenium-0.7.0 lib/aranha/selenium/defaults/option.rb
aranha-selenium-0.6.1 lib/aranha/selenium/defaults/option.rb
aranha-selenium-0.6.0 lib/aranha/selenium/defaults/option.rb