lib/surrounded/context.rb in surrounded-0.2.0 vs lib/surrounded/context.rb in surrounded-0.2.1

- old
+ new

@@ -15,30 +15,30 @@ @policy ||= :trigger end private + def wrap(name, &block) + require 'delegate' + wrapper_name = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase } + klass = const_set(wrapper_name, Class.new(SimpleDelegator, &block)) + klass.send(:include, Surrounded) + end + def apply_roles_on(which) @policy = which end def initialize(*setup_args) private_attr_reader(*setup_args) - # I want this to work so I can set the arity on initialize: - # class_eval %Q< - # def initialize(#{*setup_args}) - # arguments = parameters.map{|arg| eval(arg[1].to_s) } - # map_roles(setup_args.zip(arguments)) - # apply_roles if policy == :initialize - # end - # > - - define_method(:initialize){ |*args| - map_roles(setup_args.zip(args)) - - apply_roles if policy == :initialize - } + class_eval " + def initialize(#{setup_args.join(',')}) + arguments = method(__method__).parameters.map{|arg| eval(arg[1].to_s) } + map_roles(#{setup_args}.zip(arguments)) + apply_roles if policy == :initialize + end + " end def private_attr_reader(*method_names) attr_reader(*method_names) private(*method_names) \ No newline at end of file