devise_roles 0.1.8 → 0.1.9

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: 2aa6aead28cc5b1316e14ab99ace4dfb2df8738b
4
- data.tar.gz: 424f714f95485c9433cfe2c8b4d9271a382c5c04
3
+ metadata.gz: fe3588c277305ce647bfc3717d47961241d75f13
4
+ data.tar.gz: 813dc2de520bb1bbe24282daad801a3c680c34a3
5
5
  SHA512:
6
- metadata.gz: c211175501fe45e578e5b926d4f1d4fe96703d194e589c8ccba8fc25d15e01abfe8ed92c3b1e00d3aa9b1266befd9dd107f1c1e2d961b720a774082dfbb019da
7
- data.tar.gz: 818c2441e4bbba9aad26542863f5171fe29eb7f1e98ea8ca5afc65eb911b611ab126574ab7bf21416f734b6de5e1f23afdc8779237156ed0c52b3c235864b0c5
6
+ metadata.gz: 9b18bc1fffbc9bd0827171d6b4bf9b0e1aca27924219d35ba55bc69e4383c49d33ff3449f9f2942b8f50837adc41276ae9b76f85e49085c872b5d0e69c2585b6
7
+ data.tar.gz: 0d6e5aff5357886197350e5a63441f580e6cd24cbff984c18dc846f7d2b98b94a1cbf5b180789162fb045dc83b2f7cc2832d026a623a9e666d95cda3d0ede4d5
data/README.md CHANGED
@@ -22,12 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install devise_roles
24
24
 
25
- Also you need to include it in your Application
26
-
27
- In your **application.rb** add This
28
- ```ruby
29
- config.autoload_paths += %W(#{config.root}/lib)
30
- ```
25
+ Also you need to require it in your Application.
31
26
  You can create and initializer and add next line to it, or just write at top of your controllers
32
27
  ```ruby
33
28
  require 'encryption/encryption'
@@ -84,21 +79,39 @@ Now you can go to learn methods for this *gem*.
84
79
 
85
80
  Here is a list of available methods.
86
81
 
87
- #### Enable only for Role
82
+ #### user_is
83
+ To check if user role is what you want use
84
+ ```ruby
85
+ DeviseRoles.user_is(user_role_name, current_user)
86
+ ```
87
+ Here is some example how to use it
88
+ ```ruby
89
+ def some_controller_method_name
90
+ # Some other code ...
91
+
92
+ if DeviseRoles.user_is('admin', current_user)
93
+ # Everything is ok!
94
+ end
95
+
96
+ # Some other code ...
97
+ end
98
+ ```
88
99
 
89
- If you want to enable some page for exact Role only, use this method
100
+ #### user_not
101
+ Also there is an opposite method
90
102
  ```ruby
91
- DeviseRoles.available_for_user_role(user_role_name, current_user, user_redirect_path)
103
+ DeviseRoles.user_not(user_role_name, current_user)
92
104
  ```
93
105
  Here is some example how to use it
94
106
  ```ruby
95
107
  def some_controller_method_name
96
- # Implement it at the top
97
- # In this example, current view would be available for admins only
98
- DeviseRoles.available_for_user_role('admin', current_user, root_path)
108
+ # Some other code ...
109
+
110
+ if DeviseRoles.user_not('admin', current_user)
111
+ # User is NOT **admin** !!!
112
+ end
99
113
 
100
114
  # Some other code ...
101
- # That would be run if user is not **admin**
102
115
  end
103
116
  ```
104
117
 
data/devise_roles.gemspec CHANGED
@@ -29,5 +29,6 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_development_dependency "devise", "~> 3.5.2"
31
31
  spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_dependency "rails", "~> 4.0.2"
32
33
  spec.add_development_dependency "rake", "~> 10.0"
33
34
  end
data/lib/devise_roles.rb CHANGED
@@ -2,11 +2,13 @@ require "devise_roles/version"
2
2
  require 'rails/all'
3
3
 
4
4
  module DeviseRoles
5
- def self.available_for_user_role(user_role_name, current_user, user_redirect_path)
6
- if current_user.role.name != user_role_name
7
- redirect_to user_redirect_path, alert: "You should be #{user_role_name} to view that page!"
8
- end
5
+
6
+ def self.user_is(user_role_name, current_user)
7
+ return current_user.role.name == user_role_name
9
8
  end
10
9
 
10
+ def self.user_not(user_role_name, current_user)
11
+ return current_user.role.name != user_role_name
12
+ end
11
13
 
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseRoles
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_roles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - MarkusBansky
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.2
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement