lib/surrounded/context.rb in surrounded-0.5.0 vs lib/surrounded/context.rb in surrounded-0.5.1

- old
+ new

@@ -25,22 +25,22 @@ end def self.default_role_type @default_role_type ||= :module end - + class << self attr_writer :default_role_type, :methods_as_triggers end - + attr_reader :methods_as_triggers - + def self.methods_as_triggers return @methods_as_triggers if defined?(@methods_as_triggers) @methods_as_triggers = false end - + def set_methods_as_triggers @methods_as_triggers = true end def new(*args, &block) @@ -57,11 +57,11 @@ private def private_const_set(name, const) const = const_set(name, const) - private_constant name + private_constant name.to_sym const end def default_role_type @default_role_type ||= Surrounded::Context.default_role_type @@ -90,11 +90,11 @@ define_method(name) do instance_variable_set("@#{name}", Negotiator.new(role_map.assigned_player(name), behavior)) end end end - + def role(name, type=nil, &block) role_type = type || default_role_type if role_type == :module mod_name = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase } private_const_set(mod_name, Module.new(&block)) @@ -103,11 +103,11 @@ meth.call(name, &block) end rescue NameError => e raise e.extend(InvalidRoleType) end - + def apply_roles_on(which) @__apply_role_policy = which end def __apply_role_policy @@ -149,11 +149,11 @@ def role_const(name) if const_defined?(name) const_get(name) end end - + def redo_method(name, args) class_eval %{ def #{name}(#{args.join(', ')}) begin apply_roles if __apply_role_policy == :trigger @@ -164,10 +164,10 @@ remove_roles if __apply_role_policy == :trigger end end } end - + def method_added(name) if methods_as_triggers unless name.to_s.match(/^__trigger|initialize/) || (@triggers && triggers.include?(name)) store_trigger(name) args = self.instance_method(name).parameters.map{|p| p.last } \ No newline at end of file