36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/casting/context.rb', line 36
def initialize(*setup_args, &block)
attr_reader(*setup_args)
private(*setup_args)
define_method(:__custom_initialize, &(block || proc {}))
mod = Module.new
mod.class_eval <<~INIT, __FILE__, __LINE__ + 1
def initialize(#{setup_args.map { |name| "#{name}:" }.join(",")})
@assignments = []
#{setup_args.map do |name|
["assign(", name, ", '", name, "')"].join
end.join("\n")}
__custom_initialize
Thread.current[:context] = self
end
attr_reader :assignments
INIT
const_set(:Initializer, mod)
include mod
end
|