Module: Unobtainium::World
Overview
The World module combines other modules, defining simpler entry points into the gem’s functionality.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#driver(label = nil, options = nil) ⇒ Object
Returns a driver instance with the given options.
Methods included from ClassMethods
config_file, config_file=, extended, included, set_config_path_default
Methods included from Support::Identifiers
Instance Method Details
#driver(label = nil, options = nil) ⇒ Object
Returns a driver instance with the given options. If no options are provided, options from the global configuration are used.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/unobtainium/world.rb', line 74 def driver(label = nil, = nil) # Resolve unique options label, = (label, ) # Create a key for the label and options. This should always # return the same key for the same label and options. key = ['unobtainium_instance_id'] if key.nil? key = identifier('driver', label, ) end # Only create a driver with this exact configuration once. Unfortunately # We'll have to bind the destructor to whatever configuration exists at # this point in time, so we have to create a proc here - whether the Driver # gets created or not. at_end = config.fetch("at_end", "quit") dtor = proc do |the_driver| # :nocov: if the_driver.nil? return end # We'll rescue Exception here because we really want all destructors # to run. # rubocop:disable Lint/RescueException begin meth = at_end.to_sym the_driver.send(meth) rescue Exception => err puts "Exception in destructor: [#{err.class}] #{err}" end # rubocop:enable Lint/RescueException # :nocov: end return ::Unobtainium::Runtime.instance.store_with_if(key, dtor) do ::Unobtainium::Driver.create(label, ) end end |