petergate 1.5.5 → 1.6.2

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: c51edf01b106b36c542d3f3a84be0c446182e438
4
- data.tar.gz: 4a2cee1e5feb96c6e13f999fb342640cd602c96c
3
+ metadata.gz: acdb2ef4dd4f034a5a8ba195ed98db7de09b682b
4
+ data.tar.gz: 87e581e14a57eea73f588ddfd8a60c72c04b3212
5
5
  SHA512:
6
- metadata.gz: 7ebb8fa08e5196fad85f10bfefe66b73c5ebc108ff4fdd90feef10efcc93b52094ad9a0a7243428354c75afddb05184829753366eee7f302505bf05800739bb8
7
- data.tar.gz: d3bde72299efaace7a48e33d128478c98ad601950a1688a9dee760c568c928d5dd415a11d707b154ced26cddf00fa240d693cda462c1d4f27d852bd14a4a94d0
6
+ metadata.gz: 6edb852867594b047ff7a629fc45e27f76e51cb43113260afec72372f7026faffbe62e73b63acdebcd0222f7ef11a5bffb0597445468a156d5466752f8d15cbd
7
+ data.tar.gz: f22f4efcdccea3c1c932262ad2365d84cd6f43774d68dc724400a5b8876249141d232ed5945f510d4c60fc315b12974f3a6bacf6c8f72cdf1578d40ffa9c0383
data/README.md CHANGED
@@ -12,19 +12,19 @@
12
12
 
13
13
  Installation
14
14
  ------
15
-
16
- ######Add this line to your application's Gemfile:
15
+ #####Get the gem
16
+ Add this line to your application's Gemfile:
17
17
 
18
18
  gem 'petergate'
19
19
 
20
- ######And then execute:
20
+ And then execute:
21
21
 
22
22
  bundle
23
23
 
24
- ######Or install it yourself as:
24
+ Or install it yourself as:
25
25
 
26
26
  gem install petergate
27
- ######Setup Authentication
27
+ #####Prerequisites: Setup Authentication (Devise)
28
28
 
29
29
  Make sure your user model is defined in
30
30
  app/models/user.rb
@@ -37,7 +37,7 @@ If you're using [devise](https://github.com/plataformatec/devise) you're in luck
37
37
  after_sign_in_path_for(current_user)
38
38
  authenticate_user!
39
39
 
40
- ######Finally you can run the generators
40
+ #####Run the generators
41
41
 
42
42
  rails g petergate:install
43
43
  rake db:migrate
@@ -93,6 +93,11 @@ def roles=(v)
93
93
  end
94
94
  ```
95
95
 
96
+ If you want to change the `permission denied` message you can add to the access line:
97
+
98
+ ```ruby
99
+ access user: [:show, :index], message: "You shall not pass"
100
+ ```
96
101
 
97
102
  Credits
98
103
  -------
@@ -20,6 +20,16 @@ module Petergate
20
20
 
21
21
  instance_eval do
22
22
  const_set('ROLES', (roles + [:user]).uniq) unless defined?(User::ROLES)
23
+
24
+ if multiple
25
+ roles.each do |role|
26
+ define_singleton_method("role_#{role.to_s.pluralize}".downcase.to_sym){self.where("roles LIKE '%- :#{role}\n%'")}
27
+ end
28
+ else
29
+ roles.each do |role|
30
+ define_singleton_method("role_#{role.to_s.pluralize}".downcase.to_sym){self.where(roles: role)}
31
+ end
32
+ end
23
33
  end
24
34
 
25
35
  class_eval do
@@ -33,19 +43,20 @@ module Petergate
33
43
  end
34
44
  else
35
45
  def roles=(v)
36
- self[:roles] = case v.class.to_s
37
- when "String", "Symbol"
38
- v
39
- when "Array"
40
- v.first
41
- end
46
+ r = case v.class.to_s
47
+ when "String", "Symbol"
48
+ v
49
+ when "Array"
50
+ v.first
51
+ end
52
+ self[:roles] = available_roles.include?(r) ? r : :user
42
53
  end
43
54
  end
44
55
 
45
56
  def roles
46
57
  case self[:roles].class.to_s
47
58
  when "String", "Symbol"
48
- [self[:roles].to_sym, :user]
59
+ [self[:roles].to_sym, :user].uniq
49
60
  when "Array"
50
61
  super
51
62
  else
@@ -1,3 +1,3 @@
1
1
  module Petergate
2
- VERSION = "1.5.5"
2
+ VERSION = "1.6.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petergate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-15 00:00:00.000000000 Z
11
+ date: 2016-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler