Class: WrapperBased::Context::Producer

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

Instance Method Summary collapse

Constructor Details

#initialize(wrapper_for) ⇒ Producer

Returns a new instance of Producer.



4
5
6
7
8
# File 'lib/wrapper_based/context/producer.rb', line 4

def initialize(wrapper_for)
  @wrapper_cache = Hash.new do |cache, type_casting|
    cache[type_casting] = wrapper_for[*type_casting]
  end
end

Instance Method Details

#produce(*supporting, **leading, &script) ⇒ Object



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

def produce(*supporting, **leading, &script)
  wrappers = @wrapper_cache
  roles = supporting.map(&:to_sym) | leading.keys
  Class.new(Context) do
    roles.each { |role| add_role role, Casting.new(role, wrappers) }
    leading.each_pair { |role, trait| send(role).as trait }
    class_eval(&script) unless script.nil?
  end
end