Module: Symbiont::Ready
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#ready ⇒ Object
Returns the value of attribute ready.
-
#ready_error ⇒ Object
Returns the value of attribute ready_error.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#ready ⇒ Object
Returns the value of attribute ready.
23 24 25 |
# File 'lib/symbiont/ready.rb', line 23 def ready @ready end |
#ready_error ⇒ Object
Returns the value of attribute ready_error.
23 24 25 |
# File 'lib/symbiont/ready.rb', line 23 def ready_error @ready_error end |
Class Method Details
.included(caller) ⇒ Object
25 26 27 |
# File 'lib/symbiont/ready.rb', line 25 def self.included(caller) caller.extend(ClassMethods) end |
Instance Method Details
#ready? ⇒ Boolean
43 44 45 46 47 |
# File 'lib/symbiont/ready.rb', line 43 def ready? self.ready_error = nil return true if ready ready_validations_pass? end |
#ready_validations_pass? ⇒ Boolean
49 50 51 52 53 54 55 |
# File 'lib/symbiont/ready.rb', line 49 def ready_validations_pass? self.class.ready_validations.all? do |validation| passed, = instance_eval(&validation) self.ready_error = if && !passed passed end end |
#when_ready(&block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/symbiont/ready.rb', line 29 def when_ready(&block) already_marked_ready = ready fail(ArgumentError, 'A block is required for a when_ready action.') unless block_given? unless self.ready = ready? = "Failed to validate because: #{ready_error || 'no reason provided'}" fail(::Symbiont::Errors::PageNotValidatedError, ) end block.call self ensure self.ready = already_marked_ready end |