Module: Dicer::Contextable

Included in:
ActiveRecord
Defined in:
lib/dicer/contextable.rb,
lib/dicer/railtie/contextable.rb

Instance Method Summary collapse

Instance Method Details

#as(*behaviors, &block) ⇒ Object



13
14
15
16
17
# File 'lib/dicer/contextable.rb', line 13

def as(*behaviors, &block)
  delegator = Dicer::Delegator.make(self.class, behaviors)

  block.nil? ? delegator.new(self) : block.call(delegator.new(self))
end

#in_context(context, &block) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/dicer/contextable.rb', line 5

def in_context(context, &block)
  if block.nil?
    context.supply(self)
  else
    block.call(context.supply(self))
  end
end

#in_context_with_dicer(context = Dicer::Context.current, &block) ⇒ Object



5
6
7
# File 'lib/dicer/railtie/contextable.rb', line 5

def in_context_with_dicer(context = Dicer::Context.current, &block)
  in_context_without_dicer(context, &block)
end