Module: Applitools::EyesConfigurationDSL

Included in:
AbstractConfiguration
Defined in:
lib/applitools/core/eyes_configuration_dsl.rb

Instance Method Summary collapse

Instance Method Details

#accessor_methodsObject



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

def accessor_methods
  @accessor_methods ||= []
end

#boolean_field(field_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 17

def boolean_field(field_name)
  collect_method field_name
  define_method(field_name) do
    return true if config_hash[field_name]
    false
  end

  define_method("#{field_name}=") do |*args|
    value = args.shift
    if value
      config_hash[field_name] = true
    else
      config_hash[field_name] = false
    end
  end

  define_method("defined_#{field_name}?") do
    true
  end
end

#collect_method(field_name) ⇒ Object



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

def collect_method(field_name)
  accessor_methods.push field_name.to_sym
  methods_to_delegate.push field_name.to_sym
  methods_to_delegate.push "#{field_name}=".to_sym
end

#enum_field(field_name, available_values_array) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 137

def enum_field(field_name, available_values_array)
  collect_method(field_name)

  define_method(field_name) do
    config_hash[field_name.to_sym]
  end

  define_method("#{field_name}=") do |*args|
    value = args.shift
    raise(
        Applitools::EyesIllegalArgument,
        "Unknown #{field_name} #{value}. Allowed session types: " \
        "#{available_values_array.join(', ')}"
    ) unless available_values_array.include? value
    config_hash[field_name.to_sym] = value
  end

  define_method("defined_#{field_name}?") do
    available_values_array.include? send(field_name)
  end
end

#int_field(field_name) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 115

def int_field(field_name)
  collect_method(field_name)
  define_method(field_name) do
    config_hash[field_name.to_sym]
    # value =
    # return value if value.is_a? Integer
    # 0
  end

  define_method("#{field_name}=") do |*args|
    value = args.shift
    return config_hash[field_name.to_sym] = value if value.is_a? Integer
    return config_hash[field_name.to_sym] = value.to_i if value.respond_to? :to_i
    raise Applitools::EyesIllegalArgument, "Expected #{field_name} to be an Integer"
  end

  define_method("defined_#{field_name}?") do
    value = send(field_name)
    value.is_a? Integer
  end
end

#methods_to_delegateObject



3
4
5
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 3

def methods_to_delegate
  @methods_to_delegate ||= []
end

#object_field(field_name, klass) ⇒ Object

def batch_info_field(field_name)

collect_method field_name
define_method(field_name) do
  config_hash[field_name.to_sym]
end

define_method("#{field_name}=") do |*args|
  value = args.shift
  raise(
    Applitools::EyesIllegalArgument,
    "Expected Applitools::BatchInfo but got #{value.class}"
  ) unless value.is_a? Applitools::BatchInfo
  config_hash[field_name.to_sym] = value
end

define_method("defined_#{field_name}?") do
  value = send(field_name)
  value.is_a? Applitools::BatchInfo
end

end



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 96

def object_field(field_name, klass)
  collect_method field_name
  define_method(field_name) do
    config_hash[field_name.to_sym]
  end
  define_method("#{field_name}=") do |*args|
    value = args.shift
    raise(
        Applitools::EyesIllegalArgument,
        "Expected #{klass} but got #{value.class}"
    ) unless value.is_a? klass
    config_hash[field_name.to_sym] = value
  end
  define_method("defined_#{field_name}?") do
    value = send(field_name)
    value.is_a? klass
  end
end

#string_field(field_name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 38

def string_field(field_name)
  collect_method field_name
  define_method(field_name) do
    config_hash[field_name.to_sym]
  end

  define_method("#{field_name}=") do |*args|
    value = args.shift
    raise Applitools::EyesIllegalArgument, "Expected #{field_name} to be a String but got #{value.class} instead" unless value.is_a? String
    config_hash[field_name.to_sym] = value.freeze
  end

  define_method("defined_#{field_name}?") do
    value = send(field_name)
    return false if value.nil?
    !value.empty?
  end
end