Class: Unobtainium::Driver
- Inherits:
-
Object
- Object
- Unobtainium::Driver
- Defined in:
- lib/unobtainium/driver.rb
Overview
Creating a Driver instance creates either an Appium or Selenium driver depending on the arguments, and delegates all else to the underlying implementation.
It’s possible to add more drivers, but Appium and Selenium are the main targets.
Instance Attribute Summary collapse
-
#impl ⇒ Object
readonly
Public methods.
-
#label ⇒ Object
readonly
Public methods.
-
#options ⇒ Object
readonly
Public methods.
Class Method Summary collapse
-
.create(*args) ⇒ Object
Create a driver instance with the given arguments.
-
.register_implementation(klass, path) ⇒ Object
Add a new driver implementation.
Instance Method Summary collapse
- #method_missing(meth, *args, &block) ⇒ Object
-
#respond_to?(meth) ⇒ Boolean
Map any missing method to the driver implementation.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/unobtainium/driver.rb', line 79 def method_missing(meth, *args, &block) if not @impl.nil? and @impl.respond_to?(meth) return @impl.send(meth.to_s, *args, &block) end return super end |
Instance Attribute Details
#impl ⇒ Object (readonly)
Public methods
68 69 70 |
# File 'lib/unobtainium/driver.rb', line 68 def impl @impl end |
#label ⇒ Object (readonly)
Public methods
68 69 70 |
# File 'lib/unobtainium/driver.rb', line 68 def label @label end |
#options ⇒ Object (readonly)
Public methods
68 69 70 |
# File 'lib/unobtainium/driver.rb', line 68 def @options end |
Class Method Details
.create(*args) ⇒ Object
Create a driver instance with the given arguments
25 26 27 |
# File 'lib/unobtainium/driver.rb', line 25 def create(*args) new(*args) end |
.register_implementation(klass, path) ⇒ Object
Add a new driver implementation. The first parameter is the class itself, the second should be a file path pointing to the file where the class is defined. You would typically pass __FILE__ for the second parameter.
Using file names lets us figure out whether the class is a duplicate, or merely a second registration of the same class.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/unobtainium/driver.rb', line 37 def register_implementation(klass, path) # We need to deal with absolute paths only fpath = File.absolute_path(path) # Figure out if the class implements all the methods we need; we're not # checking for anything else. klass_methods = klass.methods - klass.instance_methods - Object.methods if DRIVER_METHODS - klass_methods != [] raise LoadError, "Driver #{klass.name} is not implementing all of "\ "the class methods #{DRIVER_METHODS}, aborting!" end # The second question is whether the same class is already known, or # whether a class with the same name but under a different location is # known. if @@drivers.include?(klass) and @@drivers[klass] != fpath raise LoadError, "Driver #{klass.name} is duplicated in file "\ "'#{fpath}'; previous definition is here: "\ "'#{@@drivers[klass]}'" end # If all of that was ok, we can register the implementation. @@drivers[klass] = fpath end |
Instance Method Details
#respond_to?(meth) ⇒ Boolean
Map any missing method to the driver implementation
72 73 74 75 76 77 |
# File 'lib/unobtainium/driver.rb', line 72 def respond_to?(meth) if not @impl.nil? and @impl.respond_to?(meth) return true end return super end |