Module: SitePrism::Loadable
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#load_error ⇒ Object
In certain circumstances, we cache that the page has already been confirmed to be loaded so that actions which call ‘loaded?` a second time do not need to perform the load_validation queries against the page a second time.
-
#loaded ⇒ Object
In certain circumstances, we cache that the page has already been confirmed to be loaded so that actions which call ‘loaded?` a second time do not need to perform the load_validation queries against the page a second time.
Class Method Summary collapse
Instance Method Summary collapse
-
#loaded? ⇒ Boolean
Check if the page is loaded.
-
#when_loaded(&_block) ⇒ Object
Executes the given block after the page is loaded.
Instance Attribute Details
#load_error ⇒ Object
In certain circumstances, we cache that the page has already been confirmed to be loaded so that actions which call ‘loaded?` a second time do not need to perform the load_validation queries against the page a second time.
38 39 40 |
# File 'lib/site_prism/loadable.rb', line 38 def load_error @load_error end |
#loaded ⇒ Object
In certain circumstances, we cache that the page has already been confirmed to be loaded so that actions which call ‘loaded?` a second time do not need to perform the load_validation queries against the page a second time.
38 39 40 |
# File 'lib/site_prism/loadable.rb', line 38 def loaded @loaded end |
Class Method Details
.included(base) ⇒ Object
32 33 34 |
# File 'lib/site_prism/loadable.rb', line 32 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#loaded? ⇒ Boolean
Check if the page is loaded.
On failure, if an error was reported by a failing validation, it will be available via the ‘load_error` accessor.
66 67 68 69 70 71 72 |
# File 'lib/site_prism/loadable.rb', line 66 def loaded? self.load_error = nil return true if loaded load_validations_pass? end |
#when_loaded(&_block) ⇒ Object
Executes the given block after the page is loaded.
The loadable object instance is yielded into the block.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/site_prism/loadable.rb', line 45 def when_loaded(&_block) previously_loaded = loaded # Get original loaded value, in case we are nested inside another when_loaded block. raise(ArgumentError, 'A block was expected, but none received.') unless block_given? # Within the block, cache loaded? to optimize performance. self.loaded = loaded? unless loaded = "Failed to load because: #{load_error || 'no reason given'}" raise(::SitePrism::NotLoadedError, ) end yield self ensure self.loaded = previously_loaded end |