lib/permissive/permission_definition.rb in permissive-0.2.4.alpha vs lib/permissive/permission_definition.rb in permissive-0.2.5.alpha

- old
+ new

@@ -79,31 +79,28 @@ end end eoc end - if model.instance_methods.include?('role=') && !model.respond_to?(:permissive_role_defined?) - puts "role= defined but role_defined? is false" + if model.column_names.include?('role') model.class_eval do - def role_with_permissive=(role_name) - self.permissions = self.class.permissions[:global].roles[role_name.to_s.downcase.to_sym] - self.role_without_permissive = role_name.to_s.downcase + def role=(role_name) + if role_name + self.permissions = self.class.permissions[:global].roles[role_name.to_s.downcase.to_sym] + if respond_to?(:write_attribute) + write_attribute(:role, role_name.to_s.downcase.strip) + end + else + self.permissions = [] + end end end - model.alias_method_chain :role=, :permissive else model.class_eval do def role=(role_name) self.permissions = self.class.permissions[:global].roles[role_name.to_s.downcase.to_sym] end - - class << self - def permissive_role_defined? - true - end - protected :permissive_role_defined? - end end end end def initialize(model, options = {}) @@ -136,10 +133,10 @@ def role(*names, &block) names.each do |name| @role = name.to_s.to_sym roles[@role] ||= [] instance_eval(&block) if block_given? - if model.instance_methods.include?('role') && !model.instance_methods.include?("is_#{name}?") + if model.column_names.include?('role') && !model.instance_methods.include?("is_#{name}?") model.class_eval <<-eoc def is_#{name}? role == #{name.to_s.downcase.inspect} end eoc \ No newline at end of file