devise_roles 0.1.0 → 0.1.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: 37bf4908a7d5be4f9c695a836196de32617e6c68
4
- data.tar.gz: 98c1bfa18b44b9261319398263ec441fb998fb7e
3
+ metadata.gz: 1ee934be745830ccdb2797e52e08f214bfd5329b
4
+ data.tar.gz: 0606df0512ef6877454127c77fd938652bb8700b
5
5
  SHA512:
6
- metadata.gz: 3878ad96f29d50953048bc77df2def2cf7237d57e659d689569697dc7d9328a50ee09f6f05cb114aec41fb30ee03acdc7a5631a21590fdb7ce188faffc1c02b4
7
- data.tar.gz: 9ecb83aa6be49613fb26e9489d8f3b6d94146dc80c571585de65ea1ce1de842f95f94b97ee1b9ec955253487bb80b3ef6a6ff7d03a1446bf966d0bca570c843b
6
+ metadata.gz: eb2b5999126147a1450fe31f09b623f3d9c8fa129d39f9783cef771e24029efdee34c2787868f4aa8e29a5bb947ba30c3daa5c088f21f0dd4e732802a9bd6fa0
7
+ data.tar.gz: 62fc6f4944e5fa37d972573b4db0cb0c1c9fcd83ce5d75da325e58c28b2d353c637d9fc4d70bc208674db6f5032bc96b113ee5056f6883f12f90e0da9b2de3b8
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /gem_test/
data/.travis.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
+ cache: bundler
3
+
2
4
  rvm:
3
5
  - 2.1.6
4
- before_install: gem install bundler -v 1.10.6
6
+
7
+ # script: 'bundle exec rake'
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # DeviseRoles::Gem
2
2
 
3
+ Gem that helps you to organaize your users with roles and manipulate them.
4
+
5
+ And you are on its HOMEPAGE.
6
+
7
+ This gem is currently in development, so if you find any issues please report.
8
+
3
9
  ## Installation
4
10
 
5
11
  Add this line to your application's Gemfile:
@@ -18,18 +24,70 @@ Or install it yourself as:
18
24
 
19
25
  ## Usage
20
26
 
21
- TODO: Write usage instructions here
27
+ To use this gem features, you should create table **Roles** and add roles to it.
28
+
29
+ Generate User model if you haven't yet:
30
+
31
+ $ rails generate devise User
32
+
33
+ ### Set up Role and User models
34
+
35
+ To do so, run:
36
+
37
+ $ rails g model Role name:string
38
+ $ rails g migration addRoleIdToUser role:references
39
+ $ rake db:migrate
40
+
41
+ Then in your app's models:
42
+
43
+ ```ruby
44
+ class User < ActiveRecord::Base
45
+ belongs_to :role
46
+ end
47
+ ```
48
+ for **User** model and also
49
+ ```ruby
50
+ class Role < ActiveRecord::Base
51
+ has_many :users
52
+ end
53
+ ```
54
+ for **Role** model.
55
+
56
+ ### Set up seeds.rb with roles and add to db
22
57
 
23
- ## Development
58
+ ```ruby
59
+ ['registered', 'banned', 'moderator', 'admin'].each do |role|
60
+ Role.find_or_create_by({name: role})
61
+ end
62
+ ```
63
+ These are required, you can also add your custom roles on your own.
64
+ Then you must add them to *db*
24
65
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+ $ rake db:seed
26
67
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
+ And this is all for setting up.
28
69
 
29
- ## Contributing
70
+ Now you can go to learn methods for this *gem*.
30
71
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/devise_roles.
72
+ ## Devise Roles methods
32
73
 
74
+ #### Enable only for Role
75
+
76
+ If you want to enable some page for exact Role only, use this method
77
+ ```ruby
78
+ available_for_user_role(user_role_name, user_redirect_path)
79
+ ```
80
+ Here is some example how to use it
81
+ ```ruby
82
+ def some_controller_method_name
83
+ # Implement it at the top
84
+ # In this example, current view would be available for admins only
85
+ available_for_user_role('admin', root_path)
86
+
87
+ # Some other code ...
88
+ # That would be run if user is not **admin**
89
+ end
90
+ ```
33
91
 
34
92
  ## License
35
93
 
Binary file
data/devise_roles.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["benovskym@gmail.com"]
11
11
 
12
12
  spec.summary = %q{A simple gem for devise roles.}
13
- spec.description = %q{Gem that helps you to organaize your users with roles and manipulate them.}
13
+ spec.description = %q{Gem that helps you to organaize your users with roles and manipulate them. Visit HOMEPAGE for more information how to use this gem.}
14
14
  spec.homepage = "https://github.com/MarkusBansky/devise_roles"
15
15
  spec.license = "MIT"
16
16
 
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_development_dependency "devise", "~> 3.5.2"
30
31
  spec.add_development_dependency "bundler", "~> 1.10"
31
32
  spec.add_development_dependency "rake", "~> 10.0"
32
33
  end
data/lib/devise_roles.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  require "devise_roles/version"
2
2
 
3
3
  module DeviseRoles
4
- # Your code goes here...
4
+ def available_for_user_role(user_role_name, user_redirect_path)
5
+ if current_user.role.name != user_role_name
6
+ redirect_to admin_path, alert: "You should be #{user_role_name} to view that page!"
7
+ end
8
+ end
9
+
10
+
5
11
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseRoles
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MarkusBansky
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: devise
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.5.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '10.0'
41
55
  description: Gem that helps you to organaize your users with roles and manipulate
42
- them.
56
+ them. Visit HOMEPAGE for more information how to use this gem.
43
57
  email:
44
58
  - benovskym@gmail.com
45
59
  executables: []
@@ -55,6 +69,7 @@ files:
55
69
  - Rakefile
56
70
  - bin/console
57
71
  - bin/setup
72
+ - devise_roles-0.1.0.gem
58
73
  - devise_roles.gemspec
59
74
  - lib/devise_roles.rb
60
75
  - lib/devise_roles/version.rb