Module: Applitools::Helpers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.environment_variablesObject



7
8
9
# File 'lib/applitools/core/helpers.rb', line 7

def self.environment_variables
  @environment_variables
end

Instance Method Details

#abstract_attr_accessor(*names) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/applitools/core/helpers.rb', line 11

def abstract_attr_accessor(*names)
  names.each do |method_name|
    instance_variable_set "@#{method_name}", nil
    abstract_method method_name, true
    abstract_method "#{method_name}=", true
  end
end

#abstract_method(method_name, is_private = true) ⇒ Object



19
20
21
22
23
24
# File 'lib/applitools/core/helpers.rb', line 19

def abstract_method(method_name, is_private = true)
  define_method method_name do |*_args|
    raise Applitools::AbstractMethodCalled.new method_name, self
  end
  private method_name if is_private
end

#env_variable(environment_variable) ⇒ Object



42
43
44
# File 'lib/applitools/core/helpers.rb', line 42

def env_variable(environment_variable)
  ENV[environment_variable.to_s] || ENV["bamboo_#{environment_variable}"]
end

#environment_attribute(attribute_name, environment_variable) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/applitools/core/helpers.rb', line 26

def environment_attribute(attribute_name, environment_variable)
  class_eval do
    Applitools::Helpers.environment_variables[environment_variable.to_sym] = env_variable(environment_variable) if
        env_variable(environment_variable)
    attr_accessor attribute_name
    define_method(attribute_name) do
      current_value = instance_variable_get "@#{attribute_name}".to_sym
      return current_value if current_value
      instance_variable_set(
        "@#{attribute_name}".to_sym,
        Applitools::Helpers.environment_variables[environment_variable.to_sym]
      )
    end
  end
end