the_role 2.4 → 2.5

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: 390002fab78f75cdae9b6aa2f354133640b21646
4
- data.tar.gz: f7ef67983c17684310ec02f606454b58b921a58f
3
+ metadata.gz: d7700ef13fecc1ba8b6947d6a0ba4456e91cbf91
4
+ data.tar.gz: edee96d6f042e8f6454d6d899572603ba0057bd8
5
5
  SHA512:
6
- metadata.gz: e0512d3c687adf75d494cfee54b1fde431295bc0b59ccd677f3666b9949ea166f7b2a05c19f22192ff54f636de59835e58e3177db11403feee0f4a148339601c
7
- data.tar.gz: 172dc91e2f26a1a1dd1f979302c59a7fe7186caff13c404472ed80ac387fa701160cd467a647133c2ba8474f37de8fdb01ab031a0f94935591bd5fc2d6cd1cd7
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
- :warn: UI moved in **the_role_bootstrap3_ui** gem
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!
@@ -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 = TheRoleParam.process 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 = TheRoleParam.process(section_name)
13
- rule_name = TheRoleParam.process(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 = TheRoleParam.process(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
 
@@ -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? TheRoleParam.process(section_name)
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 = TheRoleParam.process(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 = TheRoleParam.process(section_name)
44
+ section_name = section_name.to_s.to_slug_param(delimiter: '_')
45
45
  return false if section_name.blank?
46
- return true if role[section_name]
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 = TheRoleParam.process(rule_name)
56
- section_name = TheRoleParam.process(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 = TheRoleParam.process(rule_name)
93
- section_name = TheRoleParam.process(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 if role[section_name][rule_name]
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 = TheRoleParam.process(rule_name)
104
- section_name = TheRoleParam.process(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 unless role[section_name][rule_name]
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 = TheRoleParam.process(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 = TheRoleParam.process(rule_name)
127
- section_name = TheRoleParam.process(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
@@ -34,7 +34,7 @@ class Hash
34
34
 
35
35
  unless {}.respond_to?(:underscorify_keys)
36
36
  def underscorify_keys
37
- deep_transform_keys{ |key| TheRoleParam.process(key) }
37
+ deep_transform_keys{ |key| key.to_s.to_slug_param(delimiter: '_') }
38
38
  end
39
39
 
40
40
  def underscorify_keys!
@@ -1,3 +1,3 @@
1
1
  module TheRole
2
- VERSION = "2.4"
2
+ VERSION = "2.5"
3
3
  end
data/lib/the_role.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'the_role/hash'
2
2
  require 'the_role/config'
3
3
  require 'the_role/version'
4
- require 'the_role/param_helper'
5
4
  require 'the_role/activerecord'
6
5
 
7
6
  module TheRole
@@ -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 TheRoleParam do
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
- TheRoleParam.process('hello world!').should eq 'hello_world'
7
+ 'hello world!'.to_slug_param(delimiter: '_').should eq 'hello_world'
12
8
  end
13
9
 
14
10
  it 'string process 2' do
15
- TheRoleParam.process(:hello_world!).should eq 'hello_world'
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
- TheRoleParam.process("hello ! world").should eq 'hello_world'
15
+ "hello ! world".to_slug_param(delimiter: '_').should eq 'hello_world'
20
16
  end
21
17
 
22
18
  it 'string process 4' do
23
- TheRoleParam.process("HELLO $!= WorlD").should eq 'hello_world'
19
+ "HELLO $!= WorlD".to_slug_param(delimiter: '_').should eq 'hello_world'
24
20
  end
25
21
 
26
22
  it 'string process 5' do
27
- TheRoleParam.process("HELLO---WorlD").should eq 'hello_world'
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
- TheRoleParam.process(ctrl.controller_path).should eq 'admin_pages'
37
+ ctrl.controller_path.to_slug_param(delimiter: '_').should eq 'admin_pages'
43
38
  end
44
39
  end
data/the_role.gemspec CHANGED
@@ -18,5 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
+ s.add_dependency 'the_string_to_slug', '~> 1.1'
21
22
  s.add_runtime_dependency 'rails', ['>= 3', '< 5']
22
23
  end
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'
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-18 00:00:00.000000000 Z
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
@@ -1,9 +0,0 @@
1
- require "active_support/inflector"
2
-
3
- # TheRoleParam.process 'hello world'
4
-
5
- module TheRoleParam
6
- def self.process param
7
- param.to_s.parameterize.underscore
8
- end
9
- end