allowy 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
 
22
22
  s.add_runtime_dependency "i18n"
23
- s.add_runtime_dependency "activesupport"
23
+ s.add_runtime_dependency "activesupport", "~> 3.2"
24
24
 
25
25
  s.add_development_dependency "rspec"
26
26
  s.add_development_dependency "pry"
@@ -5,25 +5,23 @@ module Allowy
5
5
  attr_reader :context
6
6
  end
7
7
 
8
- module InstanceMethods
9
- def initialize(ctx)
10
- @context = ctx
11
- end
12
-
13
- def can?(action, *args)
14
- m = "#{action}?"
15
- raise UndefinedAction.new("The #{self.class.name} needs to have #{m} method. Please define it.") unless self.respond_to? m
16
- send(m, *args)
17
- end
8
+ def initialize(ctx)
9
+ @context = ctx
10
+ end
18
11
 
19
- def cannot?(*args)
20
- not can?(*args)
21
- end
12
+ def can?(action, *args)
13
+ m = "#{action}?"
14
+ raise UndefinedAction.new("The #{self.class.name} needs to have #{m} method. Please define it.") unless self.respond_to? m
15
+ send(m, *args)
16
+ end
22
17
 
23
- def authorize!(*args)
24
- raise AccessDenied.new("Not authorized", args.first, args[1]) unless can?(*args)
25
- end
18
+ def cannot?(*args)
19
+ not can?(*args)
26
20
  end
27
21
 
22
+ def authorize!(*args)
23
+ raise AccessDenied.new("Not authorized", args.first, args[1]) unless can?(*args)
24
+ end
28
25
  end
26
+
29
27
  end
@@ -21,27 +21,25 @@ module Allowy
21
21
  module Context
22
22
  extend ActiveSupport::Concern
23
23
 
24
- module InstanceMethods
25
24
 
26
- def allowy_context
27
- self
28
- end
25
+ def allowy_context
26
+ self
27
+ end
29
28
 
30
- def current_allowy
31
- @current_allowy ||= ::Allowy::Registry.new(allowy_context)
32
- end
29
+ def current_allowy
30
+ @current_allowy ||= ::Allowy::Registry.new(allowy_context)
31
+ end
33
32
 
34
- def can?(action, subject, *args)
35
- current_allowy.access_control_for!(subject).can?(action, subject, *args)
36
- end
33
+ def can?(action, subject, *args)
34
+ current_allowy.access_control_for!(subject).can?(action, subject, *args)
35
+ end
37
36
 
38
- def cannot?(*args)
39
- current_allowy.access_control_for!(subject).cannot?(action, subject, *args)
40
- end
37
+ def cannot?(*args)
38
+ current_allowy.access_control_for!(subject).cannot?(action, subject, *args)
39
+ end
41
40
 
42
- def authorize!(action, subject, *args)
43
- current_allowy.access_control_for!(subject).authorize!(action, subject, *args)
44
- end
41
+ def authorize!(action, subject, *args)
42
+ current_allowy.access_control_for!(subject).authorize!(action, subject, *args)
45
43
  end
46
44
  end
47
45
 
@@ -7,15 +7,10 @@ module Allowy
7
7
  end
8
8
 
9
9
  def say msg
10
- "#{msg} #{@action} #{@subject.inspect}" + if @context
11
- ' with ' + @context.inspect
12
- else
13
- ''
14
- end
10
+ "#{msg} #{@action} #{@subject.inspect}"
15
11
  end
16
12
 
17
13
  def matches?(access_control)
18
- @context = access_control.context
19
14
  access_control.can?(@action, @subject)
20
15
  end
21
16
 
@@ -1,3 +1,3 @@
1
1
  module Allowy
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,33 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Allowy
4
- module Context
5
- extend ActiveSupport::Concern
6
-
7
- module InstanceMethods
8
-
9
- def allowy_context
10
- self
11
- end
12
-
13
- def current_allowy
14
- @current_allowy ||= ::Allowy::Registry.new(allowy_context)
15
- end
16
-
17
- def can?(action, subject, *args)
18
- current_allowy.access_control_for!(subject).can?(action, subject, *args)
19
- end
20
-
21
- def cannot?(*args)
22
- current_allowy.access_control_for!(subject).cannot?(action, subject, *args)
23
- end
24
-
25
- def authorize!(action, subject, *args)
26
- current_allowy.access_control_for!(subject).authorize!(action, subject, *args)
27
- end
28
- end
29
- end
30
-
31
4
  class SampleContext
32
5
  include Context
33
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allowy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-23 00:00:00.000000000 Z
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &70143292970420 !ruby/object:Gem::Requirement
16
+ requirement: &70283147409820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70143292970420
24
+ version_requirements: *70283147409820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70143292969800 !ruby/object:Gem::Requirement
27
+ requirement: &70283147409320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ! '>='
30
+ - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '3.2'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70143292969800
35
+ version_requirements: *70283147409320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70143292969140 !ruby/object:Gem::Requirement
38
+ requirement: &70283147408900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70143292969140
46
+ version_requirements: *70283147408900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &70143292968580 !ruby/object:Gem::Requirement
49
+ requirement: &70283147408440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70143292968580
57
+ version_requirements: *70283147408440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard
60
- requirement: &70143292967960 !ruby/object:Gem::Requirement
60
+ requirement: &70283147408020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70143292967960
68
+ version_requirements: *70283147408020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &70143292967200 !ruby/object:Gem::Requirement
71
+ requirement: &70283147407600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70143292967200
79
+ version_requirements: *70283147407600
80
80
  description: Allowy provides CanCan-like way of checking permission but doesn't enforce
81
81
  a tight DSL giving you more control
82
82
  email: