cannie 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd4ec59a6c5ecf6c0e7307ea41c381cdca880956
4
- data.tar.gz: 666cb9f5b763b66abd5ba9e8e8c5404933e4a940
3
+ metadata.gz: 5c13f08328b1aaa79398982b6005e90cf997d4c0
4
+ data.tar.gz: 8f3faaa516d773988f4d7a4f381f418f903da6c3
5
5
  SHA512:
6
- metadata.gz: bb8863ea60b52ac207da478b9f890001f3d3525620a0f46971f21135d66fbef5182a315b73ea5ec66554f06a6ebb1aac8aeeebf4c9878e806f62aa9f62533e3f
7
- data.tar.gz: 4832f762eaa2a38592721dce60f27390464055ac5b5e8a5a8123fc4f9cd3407249aa526e90d03c6f9380aeeb2f521b4ba9aa0c72b21e0f2c5519242f7e1810b8
6
+ metadata.gz: 75f7491acb62968bdcd8bd82d1ab88d5a7a0a544376ab87b6d4d7875c86f944c3588cf04fcde21a7a2956a9a9dc4e6ec270fc3fb7ee5777f30076c2917db08db
7
+ data.tar.gz: fff01d347bc693e53c2b2ccba2df544f7b3257512cc8e64b67a6f5d0db7417ebf76ae8d3e925d17300d83b4bd842f3a29b4a2b46ade17eaf68b54d6c95be51e5
data/README.md CHANGED
@@ -63,6 +63,14 @@ or
63
63
 
64
64
  allow :index, on: :posts, unless: ->{ user.guest? }
65
65
 
66
+ or
67
+
68
+ allow :index, on: :posts, if: &:admin?
69
+
70
+ or
71
+
72
+ allow :index, on: :posts, unless: &:admin?
73
+
66
74
  These conditions are executed in context of `Permissions` object and its possible to use `user` method to access user that was passed to `Permissions::initialize`.
67
75
 
68
76
  ### Checking permissions
data/lib/cannie/rule.rb CHANGED
@@ -14,11 +14,19 @@ module Cannie
14
14
  attr_reader :_if, :_unless
15
15
 
16
16
  def if?(permissions)
17
- _if ? permissions.instance_exec(&_if) : true
17
+ _if ? exec_condition(_if, permissions) : true
18
18
  end
19
19
 
20
20
  def unless?(permissions)
21
- _unless ? !permissions.instance_exec(&_unless) : true
21
+ _unless ? !exec_condition(_unless, permissions) : true
22
+ end
23
+
24
+ def exec_condition(condition, context)
25
+ if condition.is_a?(Symbol)
26
+ context.instance_eval(&condition)
27
+ else
28
+ context.instance_exec(&condition)
29
+ end
22
30
  end
23
31
  end
24
- end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Cannie
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -42,7 +42,17 @@ describe Cannie::Rule do
42
42
 
43
43
  it 'returns false if passed if-condition evaluated in scope of passed argument return false' do
44
44
  rule = described_class.new(:index, 'entries', if: -> { admin? })
45
- expect(rule.applies_to?(permissions.new())).to be_false
45
+ expect(rule.applies_to?(permissions.new)).to be_false
46
+ end
47
+
48
+ it 'evaluates if-condition specified as symbol' do
49
+ rule = described_class.new(:index, 'entries', if: :admin?)
50
+ expect(rule.applies_to?(permissions.new(true))).to be_true
51
+ end
52
+
53
+ it 'evaluates if-condition specified as proc' do
54
+ rule = described_class.new(:index, 'entries', if: proc { admin? })
55
+ expect(rule.applies_to?(permissions.new(true))).to be_true
46
56
  end
47
57
 
48
58
  it 'returns true if passed unless-condition evaluated in scope of passed argument return false' do
@@ -55,9 +65,19 @@ describe Cannie::Rule do
55
65
  expect(rule.applies_to?(permissions.new(true))).to be_false
56
66
  end
57
67
 
68
+ it 'evaluates unless-condition specified as symbol' do
69
+ rule = described_class.new(:index, 'entries', unless: :admin?)
70
+ expect(rule.applies_to?(permissions.new(false))).to be_true
71
+ end
72
+
73
+ it 'evaluates unless-condition specified as proc' do
74
+ rule = described_class.new(:index, 'entries', unless: proc { admin? })
75
+ expect(rule.applies_to?(permissions.new(false))).to be_true
76
+ end
77
+
58
78
  it 'returns true if all conditions returned true' do
59
79
  rule = described_class.new(:index, 'entries', if: -> { admin? }, unless: -> { guest? })
60
80
  expect(rule.applies_to?(permissions.new(true))).to be_true
61
81
  end
62
82
  end
63
- end
83
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cannie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-23 00:00:00.000000000 Z
11
+ date: 2013-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler