Class: Dicer::Context

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dicer/context.rb,
lib/dicer/railtie/context.rb,
lib/dicer/context/description.rb

Defined Under Namespace

Classes: Description

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentObject



12
13
14
# File 'lib/dicer/railtie/context.rb', line 12

def self.current
  Middleware.store[:context]
end

.current=(context) ⇒ Object



8
9
10
# File 'lib/dicer/railtie/context.rb', line 8

def self.current=(context)
  Middleware.store[:context] = context
end

.current_controllerObject



20
21
22
# File 'lib/dicer/railtie/context.rb', line 20

def self.current_controller
  Middleware.store[:current_controller]
end

.current_controller=(controller) ⇒ Object



16
17
18
# File 'lib/dicer/railtie/context.rb', line 16

def self.current_controller=(controller)
  Middleware.store[:current_controller] = controller
end

.describe(klass, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/dicer/context.rb', line 12

def self.describe(klass, &block)
  description = Description.new(klass, &block)
  klass = description.described_class

  if descriptions.has_key?(klass)
    descriptions[klass].merge!(description)
  else
    descriptions[klass] = description
  end
end

.descriptionsObject



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

def self.descriptions
  @descriptions ||=
    self < Dicer::Context ?
      self.superclass.descriptions.dup :
      {}
end

Instance Method Details

#controllerObject



24
25
26
# File 'lib/dicer/railtie/context.rb', line 24

def controller
  self.class.current_controller
end

#supply(object, role = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/dicer/context.rb', line 23

def supply(object, role = nil)
  description = self.class.descriptions[object.class]
  delegator = description ?
    (role.nil? ?
      description.delegator :
      description.delegator_for(role)) :
    nil

  delegator ? delegator.new(object) : object
end