Skip to content

Commit

Permalink
depend on ActiveSupport 3.2, remove the depreactions
Browse files Browse the repository at this point in the history
  • Loading branch information
dnagir committed Jan 25, 2012
1 parent 85298c7 commit 713d4d3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion allowy.gemspec
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|


s.add_runtime_dependency "i18n"
s.add_runtime_dependency "activesupport"
s.add_runtime_dependency "activesupport", "~> 3.2"

s.add_development_dependency "rspec"
s.add_development_dependency "pry"
Expand Down
30 changes: 14 additions & 16 deletions lib/allowy/access_control.rb
Expand Up @@ -5,25 +5,23 @@ module AccessControl
attr_reader :context
end

module InstanceMethods
def initialize(ctx)
@context = ctx
end

def can?(action, *args)
m = "#{action}?"
raise UndefinedAction.new("The #{self.class.name} needs to have #{m} method. Please define it.") unless self.respond_to? m
send(m, *args)
end
def initialize(ctx)
@context = ctx
end

def cannot?(*args)
not can?(*args)
end
def can?(action, *args)
m = "#{action}?"
raise UndefinedAction.new("The #{self.class.name} needs to have #{m} method. Please define it.") unless self.respond_to? m
send(m, *args)
end

def authorize!(*args)
raise AccessDenied.new("Not authorized", args.first, args[1]) unless can?(*args)
end
def cannot?(*args)
not can?(*args)
end

def authorize!(*args)
raise AccessDenied.new("Not authorized", args.first, args[1]) unless can?(*args)
end
end

end
30 changes: 14 additions & 16 deletions lib/allowy/context.rb
Expand Up @@ -21,27 +21,25 @@ module Allowy
module Context
extend ActiveSupport::Concern

module InstanceMethods

def allowy_context
self
end
def allowy_context
self
end

def current_allowy
@current_allowy ||= ::Allowy::Registry.new(allowy_context)
end
def current_allowy
@current_allowy ||= ::Allowy::Registry.new(allowy_context)
end

def can?(action, subject, *args)
current_allowy.access_control_for!(subject).can?(action, subject, *args)
end
def can?(action, subject, *args)
current_allowy.access_control_for!(subject).can?(action, subject, *args)
end

def cannot?(*args)
current_allowy.access_control_for!(subject).cannot?(action, subject, *args)
end
def cannot?(*args)
current_allowy.access_control_for!(subject).cannot?(action, subject, *args)
end

def authorize!(action, subject, *args)
current_allowy.access_control_for!(subject).authorize!(action, subject, *args)
end
def authorize!(action, subject, *args)
current_allowy.access_control_for!(subject).authorize!(action, subject, *args)
end
end

Expand Down

0 comments on commit 713d4d3

Please sign in to comment.