Class: LightService::Testing::ContextFactory
- Inherits:
-
Object
- Object
- LightService::Testing::ContextFactory
- Defined in:
- lib/light-service/testing/context_factory.rb
Instance Attribute Summary collapse
-
#organizer ⇒ Object
readonly
Returns the value of attribute organizer.
Class Method Summary collapse
Instance Method Summary collapse
- #for(action) ⇒ Object
-
#initialize(organizer) ⇒ ContextFactory
constructor
A new instance of ContextFactory.
-
#with(*args, &block) ⇒ Object
More than one arguments can be passed to the Organizer’s #call method rubocop:disable Style/ArgumentsForwarding.
Constructor Details
#initialize(organizer) ⇒ ContextFactory
Returns a new instance of ContextFactory.
39 40 41 |
# File 'lib/light-service/testing/context_factory.rb', line 39 def initialize(organizer) @organizer = organizer end |
Instance Attribute Details
#organizer ⇒ Object (readonly)
Returns the value of attribute organizer.
4 5 6 |
# File 'lib/light-service/testing/context_factory.rb', line 4 def organizer @organizer end |
Class Method Details
.make_from(organizer) ⇒ Object
6 7 8 |
# File 'lib/light-service/testing/context_factory.rb', line 6 def self.make_from(organizer) new(organizer) end |
Instance Method Details
#for(action) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/light-service/testing/context_factory.rb', line 10 def for(action) @organizer.append_before_actions( lambda do |ctx| if ctx.current_action == action # The last `:_before_actions` hook is for # ContextFactory, remove it, so it won't # be invoked again ctx[:_before_actions].pop throw(:return_ctx_from_execution, ctx) end end ) self end |
#with(*args, &block) ⇒ Object
More than one arguments can be passed to the Organizer’s #call method rubocop:disable Style/ArgumentsForwarding
30 31 32 33 34 |
# File 'lib/light-service/testing/context_factory.rb', line 30 def with(*args, &block) catch(:return_ctx_from_execution) do @organizer.call(*args, &block) end end |