Module: Applitools::EyesConfigurationDSL
- Included in:
- AbstractConfiguration, AccessibilitySettings
- 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, allow_nil = false) ⇒ Object
- #string_field(field_name) ⇒ Object
Instance Method Details
#accessor_methods ⇒ Object
9 10 11 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 9 def accessor_methods @accessor_methods ||= [] end |
#boolean_field(field_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 19 def boolean_field(field_name) collect_method field_name define_method(field_name) do return send("custom_getter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_getter_for_#{field_name}") return nil if config_hash[field_name.to_sym].nil? return true if config_hash[field_name.to_sym] false end define_method("#{field_name}=") do |*args| value = args.shift config_hash[field_name.to_sym] = value ? true : false config_hash[field_name.to_sym] = send("custom_setter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_setter_for_#{field_name}") end define_method("defined_#{field_name}?") do true end end |
#collect_method(field_name) ⇒ Object
13 14 15 16 17 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 13 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
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 113 def enum_field(field_name, available_values_array) collect_method(field_name) define_method(field_name) do return send("custom_getter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_getter_for_#{field_name}") config_hash[field_name.to_sym] end define_method("#{field_name}=") do |*args| value = args.shift unless available_values_array.include? value raise( Applitools::EyesIllegalArgument, "Unknown #{field_name} #{value}. Allowed #{field_name} values: " \ "#{available_values_array.join(', ')}" ) end config_hash[field_name.to_sym] = value config_hash[field_name.to_sym] = send("custom_setter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_setter_for_#{field_name}") end define_method("defined_#{field_name}?") do available_values_array.include? send(field_name) end end |
#int_field(field_name) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 91 def int_field(field_name) collect_method(field_name) define_method(field_name) do return send("custom_getter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_getter_for_#{field_name}") config_hash[field_name.to_sym] end define_method("#{field_name}=") do |*args| value = args.shift raise Applitools::EyesIllegalArgument, "Expected #{field_name} to be an Integer" unless value.respond_to?(:to_i) config_hash[field_name.to_sym] = value.to_i if value.respond_to? :to_i config_hash[field_name.to_sym] = send("custom_setter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_setter_for_#{field_name}") end define_method("defined_#{field_name}?") do value = send(field_name) value.is_a? Integer end end |
#methods_to_delegate ⇒ Object
5 6 7 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 5 def methods_to_delegate @methods_to_delegate ||= [] end |
#object_field(field_name, klass, allow_nil = false) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 66 def object_field(field_name, klass, allow_nil = false) collect_method field_name define_method(field_name) do return send("custom_getter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_getter_for_#{field_name}") config_hash[field_name.to_sym] end define_method("#{field_name}=") do |*args| value = args.shift unless value.is_a?(klass) raise( Applitools::EyesIllegalArgument, "Expected #{klass} but got #{value.class}" ) unless allow_nil && value.nil? end config_hash[field_name.to_sym] = value config_hash[field_name.to_sym] = send("custom_setter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_setter_for_#{field_name}") end define_method("defined_#{field_name}?") do value = send(field_name) value.is_a? klass end end |
#string_field(field_name) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/applitools/core/eyes_configuration_dsl.rb', line 41 def string_field(field_name) collect_method field_name define_method(field_name) do return send("custom_getter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_getter_for_#{field_name}") config_hash[field_name.to_sym] end define_method("#{field_name}=") do |*args| value = args.shift unless value.is_a? String raise Applitools::EyesIllegalArgument, "Expected #{field_name} to be a String but got #{value.class} instead" end config_hash[field_name.to_sym] = value.freeze config_hash[field_name.to_sym] = send("custom_setter_for_#{field_name}", config_hash[field_name.to_sym]) if respond_to?("custom_setter_for_#{field_name}") end define_method("defined_#{field_name}?") do value = send(field_name) return false if value.nil? !value.empty? end end |