can_camel 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/lib/can_camel.rb +1 -1
- data/lib/can_camel/action_node.rb +0 -1
- data/lib/can_camel/base.rb +2 -2
- data/lib/can_camel/cache.rb +12 -3
- data/lib/can_camel/concern_node.rb +3 -3
- data/lib/can_camel/group_node.rb +0 -2
- data/lib/can_camel/node.rb +27 -11
- data/lib/can_camel/root.rb +17 -0
- data/lib/can_camel/subject_node.rb +0 -2
- data/lib/can_camel/version.rb +1 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 597db731eda1993d1204d7735b945635f5200f7d
|
4
|
+
data.tar.gz: b9dd5fb704e2a6ccecd98c4bb2d36c09d458ac22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36d14e9c45ad4a068544834930f1431cf0a9b349ca0de18fdaa4e7ec4c013cbeabb32b076df349c84a3d5750971617cdcc49c2434afb1b16fe2e37b774aa776e
|
7
|
+
data.tar.gz: 29e688f12ddf23d6a5a41e415420d1fb78252050241b899917c31ae5c9d89031a1ca5f09721e4d203867efa6e7839b6ac4d5cdfe3b0eb406b8c27411fb9b4ffd
|
data/lib/can_camel.rb
CHANGED
data/lib/can_camel/base.rb
CHANGED
@@ -8,8 +8,8 @@ module CanCamel
|
|
8
8
|
# @param action [Symbol] symbol relied to action node name
|
9
9
|
# @param subject [Symbol] symbol relied to subject node name
|
10
10
|
# @return [Hash, nil] hash with specific params or nil
|
11
|
-
def can?(user,
|
12
|
-
Cache[[user.send(GROUP_METHOD).to_sym,
|
11
|
+
def can?(user, *path, **args)
|
12
|
+
Cache[[user.send(GROUP_METHOD).to_sym, *path]]
|
13
13
|
.try(:can?, user: user, **args)
|
14
14
|
end
|
15
15
|
|
data/lib/can_camel/cache.rb
CHANGED
@@ -9,6 +9,7 @@ module CanCamel
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def children_of(node)
|
12
|
+
return [] unless node
|
12
13
|
cache.select do |path, _value|
|
13
14
|
_, *subpath = path
|
14
15
|
node.path == subpath
|
@@ -17,8 +18,16 @@ module CanCamel
|
|
17
18
|
|
18
19
|
def append(node, path)
|
19
20
|
path = [node.name, *path]
|
20
|
-
@cache[path]
|
21
|
-
|
21
|
+
old = @cache[path]
|
22
|
+
|
23
|
+
if old
|
24
|
+
old.inherit! node
|
25
|
+
else
|
26
|
+
new = node.dup
|
27
|
+
new.path = path
|
28
|
+
@cache[path] = new
|
29
|
+
children_of(node).each { |child| append child, path }
|
30
|
+
end
|
22
31
|
end
|
23
32
|
|
24
33
|
private
|
@@ -37,7 +46,7 @@ module CanCamel
|
|
37
46
|
def build_cache
|
38
47
|
Node.all.each_with_object({}) do |node, object|
|
39
48
|
object[node.path] = node
|
40
|
-
end
|
49
|
+
end.merge([] => Root.new)
|
41
50
|
end
|
42
51
|
|
43
52
|
def inherit_all!
|
data/lib/can_camel/group_node.rb
CHANGED
data/lib/can_camel/node.rb
CHANGED
@@ -30,15 +30,16 @@ module CanCamel
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def inherit!(source = nil)
|
33
|
-
return if inherited
|
34
|
-
|
35
33
|
raise 'inherit nodes only after cache built' unless Cache[path]
|
34
|
+
inherit_source! source
|
35
|
+
|
36
|
+
return if inherited
|
36
37
|
|
37
38
|
@inherited = true
|
38
|
-
return inherit_source! source if source
|
39
39
|
|
40
40
|
inherit_source! cached_parent
|
41
41
|
inherit_source! cached_inherited_node
|
42
|
+
# inherit_source! cached_uncle
|
42
43
|
end
|
43
44
|
|
44
45
|
validates! :inherited, absence: { message: "You should not save inherited nodes!" }
|
@@ -51,6 +52,10 @@ module CanCamel
|
|
51
52
|
super.symbolize_keys
|
52
53
|
end
|
53
54
|
|
55
|
+
def cached_uncle
|
56
|
+
Cache.children_of(cached_parent.cached_parent).select { |x| x.name == name }.first
|
57
|
+
end
|
58
|
+
|
54
59
|
attr_writer :path
|
55
60
|
|
56
61
|
def path
|
@@ -61,22 +66,33 @@ module CanCamel
|
|
61
66
|
|
62
67
|
attr_reader :inherited
|
63
68
|
|
64
|
-
def
|
65
|
-
return unless source
|
66
|
-
|
67
|
-
source.inherit!
|
68
|
-
|
69
|
+
def inherit_neighbours!(source)
|
69
70
|
Cache.children_of(source).each do |child|
|
70
|
-
|
71
|
-
next if child == self
|
72
|
-
Cache.append child, path
|
71
|
+
Cache.append child, path if child.rank > rank
|
73
72
|
end
|
73
|
+
end
|
74
74
|
|
75
|
+
def inherit_fields!(source)
|
75
76
|
inherit_field(source, :description) { |x| self.description ||= x }
|
76
77
|
inherit_field(source, :result) { |x| result.merge!(x) { |_k, l, _r| l } }
|
77
78
|
inherit_field(source, :condition) { |x| self.condition = x.merge(condition) }
|
78
79
|
end
|
79
80
|
|
81
|
+
def inherit_source!(source)
|
82
|
+
return unless source
|
83
|
+
|
84
|
+
source.inherit!
|
85
|
+
|
86
|
+
# WTF: if we inherit neighbours only once, it fails. Two times should be fine enought,
|
87
|
+
# but we have to do find a way to understand when it enought in code
|
88
|
+
# TODO: Refactor
|
89
|
+
# FIXME: Refactor
|
90
|
+
inherit_neighbours!(source)
|
91
|
+
inherit_neighbours!(source)
|
92
|
+
|
93
|
+
inherit_fields!(source) unless source.is_a? Root
|
94
|
+
end
|
95
|
+
|
80
96
|
def inherit_field(source, field)
|
81
97
|
return if override_fields.include?(field.to_s)
|
82
98
|
yield source.send(field)
|
data/lib/can_camel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_camel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Smirnov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pg
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
description: |2
|
42
28
|
CanCamel allows to manage access levels with all the power of cancan style (saving semantics). It means, that you can use `can?` method anywhere you want to check privileges of a selected user to access something in some way. See readme file at https://github.com/JelF/can_camel/blob/master/README.md to learn more
|
43
29
|
email:
|
@@ -63,6 +49,7 @@ files:
|
|
63
49
|
- lib/can_camel/group_node.rb
|
64
50
|
- lib/can_camel/linter.rb
|
65
51
|
- lib/can_camel/node.rb
|
52
|
+
- lib/can_camel/root.rb
|
66
53
|
- lib/can_camel/subject_node.rb
|
67
54
|
- lib/can_camel/validators.rb
|
68
55
|
- lib/can_camel/validators/general_validators.rb
|