Module: Zen::Service::Plugins::Context

Extended by:
Plugin
Defined in:
lib/zen/service/plugins/context.rb

Defined Under Namespace

Modules: ServiceMethods

Instance Method Summary collapse

Methods included from Plugin

config, default_options, extended, register_as, service_extension

Instance Method Details

#contextObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/zen/service/plugins/context.rb', line 11

def context
  global_context = ::Zen::Service.context
  return global_context if local_context.nil?

  if global_context.respond_to?(:merge)
    global_context.merge(local_context)
  else
    local_context
  end
end

#executeObject



29
30
31
32
33
# File 'lib/zen/service/plugins/context.rb', line 29

def execute(*)
  ::Zen::Service.with_context(context) do
    super
  end
end

#with_context(ctx) ⇒ Object



22
23
24
25
26
27
# File 'lib/zen/service/plugins/context.rb', line 22

def with_context(ctx)
  clone.tap do |copy|
    copy.local_context =
      copy.local_context.respond_to?(:merge) ? copy.local_context.merge(ctx) : ctx
  end
end