Class: Shoes::Configuration
- Inherits:
-
Object
- Object
- Shoes::Configuration
- Defined in:
- shoes-core/lib/shoes/configuration.rb
Class Attribute Summary collapse
-
.app_dir ⇒ Object
Returns the value of attribute app_dir.
- .fail_fast ⇒ Object
Class Method Summary collapse
- .backend ⇒ Object
-
.backend=(name) ⇒ Object
Set the Shoes backend to use.
-
.backend_class(object) ⇒ Object
Finds the appropriate backend class for the given Shoes object or class.
- .backend_factory(shoes_object) ⇒ Object
-
.backend_for(shoes_object, *args, &blk) ⇒ Object
Creates an appropriate backend object, passing along additional arguments.
- .backend_name ⇒ Object
- .default_backend ⇒ Object
- .find_shoes_base_class(object) ⇒ Object
Class Attribute Details
.app_dir ⇒ Object
Returns the value of attribute app_dir.
6 7 8 |
# File 'shoes-core/lib/shoes/configuration.rb', line 6 def app_dir @app_dir end |
.fail_fast ⇒ Object
9 10 11 |
# File 'shoes-core/lib/shoes/configuration.rb', line 9 def fail_fast @fail_fast ||= ENV["SHOES_FAIL_FAST"] end |
Class Method Details
.backend ⇒ Object
13 14 15 |
# File 'shoes-core/lib/shoes/configuration.rb', line 13 def backend @backend ||= Shoes.load_backend(backend_name) end |
.backend=(name) ⇒ Object
Set the Shoes backend to use. Can only be set once. Note the backend is not required during this method, but rather when ‘Shoes::Configuration#backend` is called.
38 39 40 41 42 43 44 45 |
# File 'shoes-core/lib/shoes/configuration.rb', line 38 def backend=(name) return if defined?(@backend_name) && @backend_name == name if defined?(@backend) && !@backend.nil? raise "Can't switch backend to Shoes::#{name.capitalize}, Shoes::#{backend_name.capitalize} backend already loaded." end @backend_name ||= name end |
.backend_class(object) ⇒ Object
Finds the appropriate backend class for the given Shoes object or class
53 54 55 56 57 58 59 60 |
# File 'shoes-core/lib/shoes/configuration.rb', line 53 def backend_class(object) klazz = object.is_a?(Class) ? object : find_shoes_base_class(object) class_name = klazz.name.split("::").last # Lookup with false to not consult modules higher in the chain Object # because Shoes::Swt.const_defined? 'Range' => true raise ArgumentError, "#{object} does not have a backend class defined for #{backend}" unless backend.const_defined?(class_name, false) backend.const_get(class_name, false) end |
.backend_factory(shoes_object) ⇒ Object
82 83 84 85 |
# File 'shoes-core/lib/shoes/configuration.rb', line 82 def backend_factory(shoes_object) klass = backend_class(shoes_object) klass.respond_to?(:create) ? klass.method(:create) : klass.method(:new) end |
.backend_for(shoes_object, *args, &blk) ⇒ Object
Creates an appropriate backend object, passing along additional arguments
75 76 77 78 79 80 |
# File 'shoes-core/lib/shoes/configuration.rb', line 75 def backend_for(shoes_object, *args, &blk) # Some element types (packager for instance) legitimately don't have # an app. In those cases, don't try to get it to pass along. args.unshift(shoes_object.app.gui) if shoes_object.respond_to?(:app) backend_factory(shoes_object).call(shoes_object, *args, &blk) end |
.backend_name ⇒ Object
17 18 19 |
# File 'shoes-core/lib/shoes/configuration.rb', line 17 def backend_name @backend_name ||= ENV.fetch('SHOES_BACKEND', default_backend).to_sym end |
.default_backend ⇒ Object
21 22 23 24 25 26 27 |
# File 'shoes-core/lib/shoes/configuration.rb', line 21 def default_backend if caller.any? { |path| path =~ /rspec/ } :mock else :swt end end |
.find_shoes_base_class(object) ⇒ Object
62 63 64 65 |
# File 'shoes-core/lib/shoes/configuration.rb', line 62 def find_shoes_base_class(object) return object.shoes_base_class if object.respond_to?(:shoes_base_class) object.class end |