Skip to content

Commit

Permalink
[rb] fix incongruent name spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jul 8, 2019
1 parent 16559dd commit ad9f331
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 63 deletions.
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/chrome/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module Selenium
module WebDriver
module Chrome
class Options < WebDriver::Common::Options
class Options < WebDriver::Options
attr_accessor :profile

KEY = 'goog:chromeOptions'
Expand Down
114 changes: 56 additions & 58 deletions rb/lib/selenium/webdriver/common/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,76 +19,74 @@

module Selenium
module WebDriver
module Common
class Options
attr_accessor :options
class Options
attr_accessor :options

def initialize(options: nil, **opts)
@options = if options
WebDriver.logger.deprecate(":options as keyword for initializing #{self.class}",
"custom values directly in #new constructor")
opts.merge(options)
else
opts
end
end
def initialize(options: nil, **opts)
@options = if options
WebDriver.logger.deprecate(":options as keyword for initializing #{self.class}",
"custom values directly in #new constructor")
opts.merge(options)
else
opts
end
end

#
# Add a new option not yet handled by bindings.
#
# @example Leave Chrome open when chromedriver is killed
# options = Selenium::WebDriver::Chrome::Options.new
# options.add_option(:detach, true)
#
# @param [String, Symbol] name Name of the option
# @param [Boolean, String, Integer] value Value of the option
#
#
# Add a new option not yet handled by bindings.
#
# @example Leave Chrome open when chromedriver is killed
# options = Selenium::WebDriver::Chrome::Options.new
# options.add_option(:detach, true)
#
# @param [String, Symbol] name Name of the option
# @param [Boolean, String, Integer] value Value of the option
#

def add_option(name, value)
@options[name] = value
end
def add_option(name, value)
@options[name] = value
end

#
# @api private
#
#
# @api private
#

def as_json(*)
options = @options.dup
def as_json(*)
options = @options.dup

opts = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash|
capability_value = options.delete(capability_alias)
hash[capability_name] = capability_value unless capability_value.nil?
end
opts.merge(options)
opts = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash|
capability_value = options.delete(capability_alias)
hash[capability_name] = capability_value unless capability_value.nil?
end
opts.merge(options)
end

private
private

def generate_as_json(value)
if value.respond_to?(:as_json)
value.as_json
elsif value.is_a?(Hash)
value.each_with_object({}) { |(key, val), hash| hash[convert_json_key(key)] = generate_as_json(val) }
elsif value.is_a?(Array)
value.map(&method(:generate_as_json))
elsif value.is_a?(Symbol)
value.to_s
else
value
end
def generate_as_json(value)
if value.respond_to?(:as_json)
value.as_json
elsif value.is_a?(Hash)
value.each_with_object({}) { |(key, val), hash| hash[convert_json_key(key)] = generate_as_json(val) }
elsif value.is_a?(Array)
value.map(&method(:generate_as_json))
elsif value.is_a?(Symbol)
value.to_s
else
value
end
end

def convert_json_key(key)
key = camel_case(key) if key.is_a?(Symbol)
return key if key.is_a?(String)
def convert_json_key(key)
key = camel_case(key) if key.is_a?(Symbol)
return key if key.is_a?(String)

raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class}"
end
raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class}"
end

def camel_case(str)
str.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
end
end # Options
end # Common
def camel_case(str)
str.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
end
end # Options
end # WebDriver
end # Selenium
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/edge_html/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module Selenium
module WebDriver
module EdgeHtml
class Options < WebDriver::Common::Options
class Options < WebDriver::Options
# see https://docs.microsoft.com/en-us/microsoft-edge/webdriver#capabilities
CAPABILITIES = {in_private: 'ms:inPrivate',
extension_paths: 'ms:extensionPaths',
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/firefox/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module Selenium
module WebDriver
module Firefox
class Options < WebDriver::Common::Options
class Options < WebDriver::Options
KEY = 'moz:firefoxOptions'

# see: https://firefox-source-docs.mozilla.org/testing/geckodriver/Capabilities.html
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/ie/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module Selenium
module WebDriver
module IE
class Options < WebDriver::Common::Options
class Options < WebDriver::Options
KEY = 'se:ieOptions'
SCROLL_TOP = 0
SCROLL_BOTTOM = 1
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/safari/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module Selenium
module WebDriver
module Safari
class Options < WebDriver::Common::Options
class Options < WebDriver::Options
attr_accessor :options

# @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari
Expand Down

0 comments on commit ad9f331

Please sign in to comment.