Module: Applitools::EyesConfigurationDSL
- Included in:
- AbstractConfiguration
- Defined in:
- lib/applitools/core/eyes_configuration_dsl.rb
Instance Method Summary collapse
- #accessor_methods ⇒ Object
- #boolean_field(field_name) ⇒ Object
- #collect_method(field_name) ⇒ Object
- #enum_field(field_name, available_values_array) ⇒ Object
- #int_field(field_name) ⇒ Object
- #methods_to_delegate ⇒ Object
- #object_field(field_name, klass) ⇒ Object
- #string_field(field_name) ⇒ Object
Instance Method Details
#accessor_methods ⇒ Object
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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 98 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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 76 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_delegate ⇒ Object
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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 57 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 |