Class: WrapperBased::Context::Builder

Inherits:
Module
  • Object
show all
Defined in:
lib/wrapper_based/context/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(wrapper_for) ⇒ Builder

Returns a new instance of Builder.



3
4
5
6
# File 'lib/wrapper_based/context/builder.rb', line 3

def initialize(wrapper_for)
  class_variable_set :@@wrapper_for,
    Hash.new { |cache, type_casting| cache[type_casting] = wrapper_for[*type_casting] }
end

Instance Method Details

#Context(*roles, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/wrapper_based/context/builder.rb', line 12

def Context(*roles, &block)
  dci = self
  Class.new(WrapperBased::Context) do
    roles.each { |role| add_role role, dci }
    class_eval(&block) unless block.nil?
  end
end

#wrapper_for(*type_casting) ⇒ Object



8
9
10
# File 'lib/wrapper_based/context/builder.rb', line 8

def wrapper_for(*type_casting)
  class_variable_get(:@@wrapper_for)[type_casting]
end