the_role 2.4 → 2.5
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/README.md +6 -1
- data/app/models/concerns/base.rb +4 -4
- data/app/models/concerns/role.rb +25 -15
- data/lib/the_role/hash.rb +1 -1
- data/lib/the_role/version.rb +1 -1
- data/lib/the_role.rb +0 -1
- data/spec/dummy_app/Gemfile +2 -0
- data/spec/dummy_app/spec/models/param_process_spec.rb +8 -13
- data/the_role.gemspec +1 -0
- metadata +16 -3
- data/lib/the_role/param_helper.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7700ef13fecc1ba8b6947d6a0ba4456e91cbf91
|
4
|
+
data.tar.gz: edee96d6f042e8f6454d6d899572603ba0057bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a95cff998b90f59352d1b380ae698ca026f0f31b024844219b1a6ed55f761e7a83ac42a6a3d9ff99ccde0be192ac7f2ec7cd2e121ee39dd8eb4cda7c35473a81
|
7
|
+
data.tar.gz: b44c2b1b3fbcaf32e2127e632cf866298307a4f6837930ff3ab752d7b72fd2a2bc268614c2db1b3aa97eb50fa20ab4a4ce003e8076e6bc2f7540adf2bc79eb7b
|
data/README.md
CHANGED
@@ -19,7 +19,9 @@
|
|
19
19
|
|
20
20
|
### GUI
|
21
21
|
|
22
|
-
:
|
22
|
+
:warning: UI moved in **the_role_bootstrap3_ui** gem
|
23
|
+
|
24
|
+
https://github.com/the-teacher/the_role_bootstrap3_ui
|
23
25
|
|
24
26
|
We are waiting for **foundation** version of UI
|
25
27
|
|
@@ -49,6 +51,9 @@ gem 'the_role_bootstrap3_ui'
|
|
49
51
|
|
50
52
|
Please read *the_role_bootstrap3_ui* docs to know more about assets
|
51
53
|
|
54
|
+
https://github.com/the-teacher/the_role_bootstrap3_ui
|
55
|
+
|
56
|
+
|
52
57
|
## If you have any questions
|
53
58
|
|
54
59
|
Please, before asking anything try to launch and play with the **[Dummy App](spec/dummy_app)** in the spec folder. Maybe an example integration will be better than any documentation. Thank you!
|
data/app/models/concerns/base.rb
CHANGED
@@ -2,15 +2,15 @@ module TheRole
|
|
2
2
|
module Base
|
3
3
|
def has_section? section_name
|
4
4
|
hash = role_hash
|
5
|
-
section_name =
|
5
|
+
section_name = section_name.to_s.to_slug_param(delimiter: '_')
|
6
6
|
return true if hash[section_name]
|
7
7
|
false
|
8
8
|
end
|
9
9
|
|
10
10
|
def has_role? section_name, rule_name
|
11
11
|
hash = role_hash
|
12
|
-
section_name =
|
13
|
-
rule_name =
|
12
|
+
section_name = section_name.to_s.to_slug_param(delimiter: '_')
|
13
|
+
rule_name = rule_name.to_s.to_slug_param(delimiter: '_')
|
14
14
|
|
15
15
|
return true if hash.try(:[], 'system').try(:[], 'administrator')
|
16
16
|
return true if hash.try(:[], 'moderator').try(:[], section_name)
|
@@ -26,7 +26,7 @@ module TheRole
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def moderator? section_name
|
29
|
-
section_name =
|
29
|
+
section_name = section_name.to_slug_param(delimiter: '_')
|
30
30
|
has_role? section_name, 'any_crazy_name'
|
31
31
|
end
|
32
32
|
|
data/app/models/concerns/role.rb
CHANGED
@@ -12,7 +12,7 @@ module TheRole
|
|
12
12
|
alias_method :any?, :any_role?
|
13
13
|
|
14
14
|
def has_section? section_name
|
15
|
-
to_hash.key?
|
15
|
+
to_hash.key? section_name.to_s.to_slug_param(delimiter: '_')
|
16
16
|
end
|
17
17
|
|
18
18
|
included do
|
@@ -22,7 +22,7 @@ module TheRole
|
|
22
22
|
validates :description, presence: true
|
23
23
|
|
24
24
|
before_save do
|
25
|
-
self.name =
|
25
|
+
self.name = name.to_s.to_slug_param(delimiter: '_')
|
26
26
|
|
27
27
|
rules_set = self.the_role
|
28
28
|
self.the_role = {}.to_json if rules_set.blank? # blank
|
@@ -41,9 +41,9 @@ module TheRole
|
|
41
41
|
def create_section section_name = nil
|
42
42
|
return false unless section_name
|
43
43
|
role = to_hash
|
44
|
-
section_name =
|
44
|
+
section_name = section_name.to_s.to_slug_param(delimiter: '_')
|
45
45
|
return false if section_name.blank?
|
46
|
-
return true
|
46
|
+
return true if role[section_name]
|
47
47
|
role[section_name] = {}
|
48
48
|
update(the_role: role)
|
49
49
|
end
|
@@ -51,9 +51,11 @@ module TheRole
|
|
51
51
|
def create_rule section_name, rule_name
|
52
52
|
return false if rule_name.blank?
|
53
53
|
return false unless create_section(section_name)
|
54
|
+
|
54
55
|
role = to_hash
|
55
|
-
rule_name
|
56
|
-
section_name =
|
56
|
+
rule_name = rule_name.to_s.to_slug_param(delimiter: '_')
|
57
|
+
section_name = section_name.to_s.to_slug_param(delimiter: '_')
|
58
|
+
|
57
59
|
return true if role[section_name][rule_name]
|
58
60
|
role[section_name][rule_name] = false
|
59
61
|
update(the_role: role)
|
@@ -89,22 +91,26 @@ module TheRole
|
|
89
91
|
|
90
92
|
def rule_on section_name, rule_name
|
91
93
|
role = to_hash
|
92
|
-
rule_name
|
93
|
-
section_name =
|
94
|
+
rule_name = rule_name.to_s.to_slug_param(delimiter: '_')
|
95
|
+
section_name = section_name.to_s.to_slug_param(delimiter: '_')
|
96
|
+
|
94
97
|
return false unless role[section_name]
|
95
98
|
return false unless role[section_name].key? rule_name
|
96
|
-
return true
|
99
|
+
return true if role[section_name][rule_name]
|
100
|
+
|
97
101
|
role[section_name][rule_name] = true
|
98
102
|
update(the_role: role)
|
99
103
|
end
|
100
104
|
|
101
105
|
def rule_off section_name, rule_name
|
102
106
|
role = to_hash
|
103
|
-
rule_name
|
104
|
-
section_name =
|
107
|
+
rule_name = rule_name.to_s.to_slug_param(delimiter: '_')
|
108
|
+
section_name = section_name.to_s.to_slug_param(delimiter: '_')
|
109
|
+
|
105
110
|
return false unless role[section_name]
|
106
111
|
return false unless role[section_name].key? rule_name
|
107
|
-
return true
|
112
|
+
return true unless role[section_name][rule_name]
|
113
|
+
|
108
114
|
role[section_name][rule_name] = false
|
109
115
|
update(the_role: role)
|
110
116
|
end
|
@@ -114,19 +120,23 @@ module TheRole
|
|
114
120
|
def delete_section section_name = nil
|
115
121
|
return false unless section_name
|
116
122
|
role = to_hash
|
117
|
-
section_name =
|
123
|
+
section_name = section_name.to_s.to_slug_param(delimiter: '_')
|
124
|
+
|
118
125
|
return false if section_name.blank?
|
119
126
|
return false unless role[section_name]
|
127
|
+
|
120
128
|
role.delete section_name
|
121
129
|
update(the_role: role)
|
122
130
|
end
|
123
131
|
|
124
132
|
def delete_rule section_name, rule_name
|
125
133
|
role = to_hash
|
126
|
-
rule_name
|
127
|
-
section_name =
|
134
|
+
rule_name = rule_name.to_s.to_slug_param(delimiter: '_')
|
135
|
+
section_name = section_name.to_s.to_slug_param(delimiter: '_')
|
136
|
+
|
128
137
|
return false unless role[section_name]
|
129
138
|
return false unless role[section_name].key? rule_name
|
139
|
+
|
130
140
|
role[section_name].delete rule_name
|
131
141
|
update(the_role: role)
|
132
142
|
end
|
data/lib/the_role/hash.rb
CHANGED
data/lib/the_role/version.rb
CHANGED
data/lib/the_role.rb
CHANGED
data/spec/dummy_app/Gemfile
CHANGED
@@ -6,6 +6,8 @@ gem 'devise'
|
|
6
6
|
gem 'sqlite3'
|
7
7
|
gem 'state_machine', '~> 1.2.0'
|
8
8
|
|
9
|
+
gem "the_string_to_slug", path: "../../../the_string_to_slug"
|
10
|
+
|
9
11
|
gem 'sprockets-rails', github: 'rails/sprockets-rails'
|
10
12
|
gem 'coffee-rails', github: 'rails/coffee-rails'
|
11
13
|
gem 'sass-rails', github: 'rails/sass-rails'
|
@@ -2,36 +2,31 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe
|
6
|
-
it 'module TheRoleParam should be defined' do
|
7
|
-
TheRoleParam.class.should be Module
|
8
|
-
end
|
9
|
-
|
5
|
+
describe "String to slug" do
|
10
6
|
it 'string process 1' do
|
11
|
-
|
7
|
+
'hello world!'.to_slug_param(delimiter: '_').should eq 'hello_world'
|
12
8
|
end
|
13
9
|
|
14
10
|
it 'string process 2' do
|
15
|
-
|
11
|
+
:hello_world!.to_s.to_slug_param(delimiter: '_').should eq 'hello_world'
|
16
12
|
end
|
17
13
|
|
18
14
|
it 'string process 3' do
|
19
|
-
|
15
|
+
"hello ! world".to_slug_param(delimiter: '_').should eq 'hello_world'
|
20
16
|
end
|
21
17
|
|
22
18
|
it 'string process 4' do
|
23
|
-
|
19
|
+
"HELLO $!= WorlD".to_slug_param(delimiter: '_').should eq 'hello_world'
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'string process 5' do
|
27
|
-
|
23
|
+
"HELLO---WorlD".to_slug_param(delimiter: '_').should eq 'hello_world'
|
28
24
|
end
|
29
25
|
|
30
26
|
it "should work with Controller Name" do
|
31
27
|
ctrl = PagesController.new
|
32
28
|
ctrl.controller_path
|
33
|
-
|
34
|
-
TheRoleParam.process(ctrl.controller_path).should eq 'pages'
|
29
|
+
ctrl.controller_path.to_slug_param(delimiter: '_').should eq 'pages'
|
35
30
|
end
|
36
31
|
|
37
32
|
it "should work with Nested Controller Name" do
|
@@ -39,6 +34,6 @@ describe TheRoleParam do
|
|
39
34
|
ctrl = Admin::PagesController.new
|
40
35
|
ctrl.controller_path
|
41
36
|
|
42
|
-
|
37
|
+
ctrl.controller_path.to_slug_param(delimiter: '_').should eq 'admin_pages'
|
43
38
|
end
|
44
39
|
end
|
data/the_role.gemspec
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_role
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya N. Zykin [the-teacher]
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: the_string_to_slug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rails
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,7 +84,6 @@ files:
|
|
70
84
|
- lib/the_role/activerecord.rb
|
71
85
|
- lib/the_role/config.rb
|
72
86
|
- lib/the_role/hash.rb
|
73
|
-
- lib/the_role/param_helper.rb
|
74
87
|
- lib/the_role/the_class_exists.rb
|
75
88
|
- lib/the_role/version.rb
|
76
89
|
- pic.png
|