Sha256: f26ef7b7e5c3dde1d0fda68817ef27c98d81f96c9369a63003dc96ba68ec9054

Contents?: true

Size: 1.04 KB

Versions: 7

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 DriverOptions
      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

7 entries across 7 versions & 1 rubygems

Version Path
aranha-selenium-0.11.1 lib/aranha/selenium/driver_options/option.rb
aranha-selenium-0.11.0 lib/aranha/selenium/driver_options/option.rb
aranha-selenium-0.10.1 lib/aranha/selenium/driver_options/option.rb
aranha-selenium-0.10.0 lib/aranha/selenium/driver_options/option.rb
aranha-selenium-0.9.0 lib/aranha/selenium/driver_options/option.rb
aranha-selenium-0.8.0 lib/aranha/selenium/driver_options/option.rb
aranha-selenium-0.7.1 lib/aranha/selenium/driver_options/option.rb