devise_roles 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/Gemfile +2 -0
- data/README.md +8 -41
- data/devise_roles-0.2.4.gem +0 -0
- data/devise_roles.gemspec +0 -8
- data/lib/devise_roles.rb +19 -1
- data/lib/devise_roles/engine.rb +6 -0
- data/lib/devise_roles/version.rb +1 -1
- data/lib/generators/devise_roles/devise_roles_initializer.rb +1 -0
- data/lib/generators/devise_roles/install_generator.rb +23 -0
- metadata +6 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47dd71bc8f5189c30e628784e3c27468751635cd
|
4
|
+
data.tar.gz: 4710822eb395dfd1472f8120f7905e3471b31aef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 467b89d426ce402628d46c2bd8a13a05b54b1ab7095694d1abcf7979621ad8d345f3a5a4ffddc004bb8b782fb515c9e43365e2b2b44f9d77d9e738559dd5e567
|
7
|
+
data.tar.gz: d281f2bfe862dd8168f8d471cd019bb22a49a0e2faff5f97c4d84b772167f1f93d4f0646db0944cadeb0b6439a14f8278ddda9520ffcb3c6ffbcda12b32e87b1
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# DeviseRoles::Gem
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/devise_roles.svg)](https://badge.fury.io/rb/devise_roles)
|
3
|
+
[![Build Status](https://travis-ci.org/MarkusBansky/devise_roles.svg?branch=master)](https://travis-ci.org/MarkusBansky/devise_roles)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/MarkusBansky/devise_roles/badges/gpa.svg)](https://codeclimate.com/github/MarkusBansky/devise_roles)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/MarkusBansky/devise_roles/badges/coverage.svg)](https://codeclimate.com/github/MarkusBansky/devise_roles/coverage)
|
2
6
|
|
3
7
|
Gem that helps you to organaize your users with roles and manipulate them.
|
4
8
|
|
@@ -18,14 +22,10 @@ And then execute:
|
|
18
22
|
|
19
23
|
$ bundle
|
20
24
|
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install devise_roles
|
24
|
-
|
25
25
|
Also you need to require it in your Application.
|
26
26
|
You can create and initializer and add next line to it, or just write at top of your controllers
|
27
27
|
```ruby
|
28
|
-
require '
|
28
|
+
require 'devise_roles'
|
29
29
|
```
|
30
30
|
|
31
31
|
## Pre set up
|
@@ -36,44 +36,11 @@ Generate User model if you haven't yet:
|
|
36
36
|
|
37
37
|
$ rails generate devise User
|
38
38
|
|
39
|
-
### Set up Role and User models
|
40
|
-
|
41
|
-
To do so, run:
|
42
|
-
|
43
|
-
$ rails g model Role name:string
|
44
|
-
$ rails g migration addRoleIdToUser role:references
|
45
|
-
$ rake db:migrate
|
46
|
-
|
47
|
-
Then in your app's models:
|
48
|
-
|
49
|
-
```ruby
|
50
|
-
class User < ActiveRecord::Base
|
51
|
-
belongs_to :role
|
52
|
-
end
|
53
|
-
```
|
54
|
-
for **User** model and also
|
55
|
-
```ruby
|
56
|
-
class Role < ActiveRecord::Base
|
57
|
-
has_many :users
|
58
|
-
end
|
59
|
-
```
|
60
|
-
for **Role** model.
|
61
|
-
|
62
|
-
### Set up seeds.rb with roles and add to db
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
['registered', 'banned', 'moderator', 'admin'].each do |role|
|
66
|
-
Role.find_or_create_by({name: role})
|
67
|
-
end
|
68
|
-
```
|
69
|
-
These are required, you can also add your custom roles on your own.
|
70
|
-
Then you must add them to *db*
|
71
|
-
|
72
|
-
$ rake db:seed
|
73
39
|
|
74
|
-
|
40
|
+
To set up **Roles** follow tutorial
|
41
|
+
from official [DeviseRoles page here](https://github.com/plataformatec/devise/wiki/How-To:-Add-a-default-role-to-a-User).
|
75
42
|
|
76
|
-
Now you can go to learn methods for this *gem*.
|
43
|
+
And this is all for setting up. Now you can go to learn methods for this *gem*.
|
77
44
|
|
78
45
|
## DeviseRoles Usage
|
79
46
|
|
Binary file
|
data/devise_roles.gemspec
CHANGED
@@ -16,13 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.homepage = "https://github.com/MarkusBansky/devise_roles"
|
17
17
|
spec.license = "MIT"
|
18
18
|
|
19
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
20
|
-
# delete this section to allow pushing this gem to any host.
|
21
|
-
# if spec.respond_to?(:metadata)
|
22
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
23
|
-
# else
|
24
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
-
# end
|
26
19
|
|
27
20
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
21
|
spec.bindir = "exe"
|
@@ -35,7 +28,6 @@ Gem::Specification.new do |spec|
|
|
35
28
|
spec.add_development_dependency 'test_declarative', '>=0.0.2'
|
36
29
|
spec.add_development_dependency 'mocha', '>=0.14'
|
37
30
|
spec.add_development_dependency 'rake'
|
38
|
-
spec.add_development_dependency 'coveralls'
|
39
31
|
spec.add_development_dependency "bundler", "~> 1.10"
|
40
32
|
|
41
33
|
spec.required_rubygems_version = '>= 1.3.6'
|
data/lib/devise_roles.rb
CHANGED
@@ -2,6 +2,7 @@ require "devise_roles/version"
|
|
2
2
|
require 'rails/all'
|
3
3
|
|
4
4
|
module DeviseRoles
|
5
|
+
require 'devise_roles/engine' if defined?(Rails)
|
5
6
|
|
6
7
|
def self.user_is(user_role_name, current_user)
|
7
8
|
return current_user.role.name == user_role_name
|
@@ -11,8 +12,25 @@ module DeviseRoles
|
|
11
12
|
return current_user.role.name != user_role_name
|
12
13
|
end
|
13
14
|
|
14
|
-
def self.add_role_to_user(
|
15
|
+
def self.add_role_to_user(role_name, user)
|
16
|
+
role = Role.find_or_create({:name => role_name})
|
15
17
|
user.role = role
|
16
18
|
end
|
17
19
|
|
20
|
+
def self.create_role(name)
|
21
|
+
Role.create!({:name => name})
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.remove_user(email)
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.make_admin(user_email)
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.remove_admin(user_email)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
18
36
|
end
|
data/lib/devise_roles/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'devise_roles'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#lib/generators/gemname/install_generator.rb
|
2
|
+
require 'rails/generators'
|
3
|
+
module DeviseRoles
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
desc "DeviseRoles generator performing tasks"
|
6
|
+
|
7
|
+
# Commandline options can be defined here using Thor-like options:
|
8
|
+
# class_option :my_opt, :type => :boolean, :default => false, :desc => "My Option"
|
9
|
+
# I can later access that option using:
|
10
|
+
# options[:my_opt]
|
11
|
+
|
12
|
+
|
13
|
+
def self.source_root
|
14
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
15
|
+
end
|
16
|
+
|
17
|
+
# Generator Code. Remember this is just suped-up Thor so methods are executed in order
|
18
|
+
def copy_initializer_file
|
19
|
+
copy_file "devise_roles_initializer.rb", "config/initializers/#{file_name}.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_roles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MarkusBansky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: coveralls
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: bundler
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,9 +111,13 @@ files:
|
|
125
111
|
- Rakefile
|
126
112
|
- bin/console
|
127
113
|
- bin/setup
|
114
|
+
- devise_roles-0.2.4.gem
|
128
115
|
- devise_roles.gemspec
|
129
116
|
- lib/devise_roles.rb
|
117
|
+
- lib/devise_roles/engine.rb
|
130
118
|
- lib/devise_roles/version.rb
|
119
|
+
- lib/generators/devise_roles/devise_roles_initializer.rb
|
120
|
+
- lib/generators/devise_roles/install_generator.rb
|
131
121
|
homepage: https://github.com/MarkusBansky/devise_roles
|
132
122
|
licenses:
|
133
123
|
- MIT
|