voltex 0.0.7 → 0.0.8

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: 2cfe384897e6390f5c2b104fa7ec302487933991
4
- data.tar.gz: 8c310d1c3f02e8b78273d4dbe4a9c43ab41a8c61
3
+ metadata.gz: b282a966aaaf962ee73b61a7058797997d190260
4
+ data.tar.gz: 3512c2339b07c25d1327fb9c98222f5a363401b8
5
5
  SHA512:
6
- metadata.gz: 242b09d85afce9a55a2724dab725b8203ff24a97528dec84ac152ad3d52feb0d9bb5d238b678db609bf8b4b24c4171eaacfa3e62036bc9ef044552fd6dcf4e10
7
- data.tar.gz: 2e4d16190fb46a29a3ac96f46bf202ec0cefc2130025435b0f5b578e42ed459a2c7a19d6fdd953398db3779b74f29a15cdce9a5589fffa68411d18f74d643d24
6
+ metadata.gz: c6f0ce0d777f8e1fe2e16a76c7adb43befaa0d37ad32185f8cf0d35cab8a6e6683ef7cc3fd9a8f270a268915f4bdc1fff63904d5fbc37b94c14b39b7e34ada88
7
+ data.tar.gz: 0d6ba883b3fa46241662b83169b4b4da6fe3fc20fad48362cbeee4465457b808deb9ccefe9a067b4f30c18a19432ac5604332efb498c466f6c071c69595275c1
data/README.md CHANGED
@@ -2,69 +2,64 @@
2
2
  This engine aims to provide an easy way to work with dynamic permissions.
3
3
 
4
4
 
5
- ## Compatibility
6
- * Rails 4+
7
- * ActiveRecord 4+
8
- * Ruby 2+
9
-
10
-
11
5
  ## Installation
12
6
  1. Add Voltex to your Gemfile.
13
7
 
14
- ```ruby
15
- gem 'voltex'
16
- ```
8
+ ```ruby
9
+ gem 'voltex'
10
+ ```
17
11
 
18
12
  2. Generate voltex initializer.
19
13
 
20
- ```
21
- bundle exec rails g voltex:install
22
- ```
14
+ ```
15
+ rails g voltex:install
16
+ ```
23
17
 
24
18
  3. Update initializer according your needs.
25
19
 
26
- ```ruby
27
- Voltex.setup do |config|
28
- # Voltex classes configuration.
29
- # config.user_class = 'User'
30
- # config.role_class = 'Role'
31
- # config.permission_class = 'Permission'
32
- ...
33
- end
34
- ```
20
+ ```ruby
21
+ Voltex.setup do |config|
22
+ # Voltex classes configuration.
23
+ # config.user_class = 'User'
24
+ # config.role_class = 'Role'
25
+ # config.permission_class = 'Permission'
26
+ ...
27
+ end
28
+ ```
35
29
 
36
30
  4. Generate voltex resources.
37
31
 
38
- ```
39
- bundle exec rails g voltex:resources
40
- ```
32
+ ```
33
+ rails g voltex:resources
34
+ ```
41
35
 
42
36
  5. Migrate your database.
43
37
 
44
- ```
45
- bundle exec rake db:migrate
46
- ```
38
+ ```
39
+ rails db:migrate
40
+ ```
47
41
 
48
42
  6. Create default permissions.
49
43
 
50
- ```
51
- bundle exec rake voltex
52
- ```
44
+ ```
45
+ rake voltex
46
+ ```
53
47
 
54
48
  7. Load current user permissions in your application controller.
55
49
 
56
- ```ruby
57
- class ApplicationController < ActionController::Base
58
- ...
59
- before_action :set_current_permissions
60
- end
61
- ```
50
+ ```ruby
51
+ class ApplicationController < ActionController::Base
52
+ ...
53
+ before_action :set_current_permissions
54
+ end
55
+ ```
62
56
 
63
57
  By default this callback preloads permissions for `current_user` if this
64
58
  is defined. If you need that this callback preloads permission for
65
59
  another user just overwrite `voltex_user` method.
66
60
 
67
61
  Example:
62
+
68
63
  ```ruby
69
64
  class ApplicationController < ActionController::Base
70
65
  ...
@@ -78,6 +73,7 @@ end
78
73
 
79
74
  ## Using Voltex with Pundit
80
75
  Include voltex in your application policy.
76
+
81
77
  ```ruby
82
78
  require 'voltex/pundit'
83
79
 
@@ -85,7 +81,9 @@ class ApplicationPolicy
85
81
  include Voltex::Pundit
86
82
  end
87
83
  ```
84
+
88
85
  Now a new helper is available in your policies.
86
+
89
87
  ```ruby
90
88
  class PostPolicy
91
89
  def index?
@@ -97,12 +95,13 @@ end
97
95
 
98
96
  ## Using Voltex with CanCan
99
97
  Include voltex in your ability class.
98
+
100
99
  ```ruby
101
- require 'voltex/cancan/ability'
100
+ require 'voltex/cancan'
102
101
 
103
102
  class Ability
104
103
  include CanCan::Ability
105
- include Voltex::CanCan::Ability
104
+ include Voltex::CanCan
106
105
 
107
106
  def initialize(user)
108
107
  define_voltex_abilities(user)
@@ -113,6 +112,7 @@ end
113
112
 
114
113
  ## Including and Excluding permissions
115
114
  Update your voltex initializer:
115
+
116
116
  ```ruby
117
117
  Voltex.setup do |config|
118
118
  # Voltex classes configuration.
@@ -133,22 +133,28 @@ Voltex.setup do |config|
133
133
  ]
134
134
  end
135
135
  ```
136
+
136
137
  And run voltex rake task again:
138
+
137
139
  ```
138
- bundle exec rake voltex
140
+ rake voltex
139
141
  ```
140
142
 
141
143
 
142
144
  ## Defining role permissions
143
145
  Mount voltex engine in your application:
146
+
144
147
  ```ruby
145
148
  Rails.application.routes.draw do
146
149
  mount Voltex::Engine => '/voltex'
147
150
  end
148
151
  ```
152
+
149
153
  Run voltex views generator:
154
+
150
155
  ```
151
- bundle exec rails g voltex:views
156
+ rails g voltex:views
152
157
  ```
158
+
153
159
  This will define a route `/voltex/roles/:id/edit` where
154
160
  permissions can be defined for each role.
@@ -1,4 +1,4 @@
1
- class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class VoltexCreate<%= table_name.camelize %> < <%= migration_class_name %>
2
2
  def change
3
3
  create_table(:<%= table_name %>) do |t|
4
4
  t.string :resource
@@ -1,4 +1,4 @@
1
- class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class AddVoltexTo<%= table_name.camelize %> < <%= migration_class_name %>
2
2
  def change
3
3
  change_table(:<%= table_name %>) do |t|
4
4
  t.string :resource
@@ -1,4 +1,4 @@
1
- class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class VoltexCreate<%= table_name.camelize %> < <%= migration_class_name %>
2
2
  def change
3
3
  create_table(:<%= table_name %>) do |t|
4
4
  t.references :<%= Voltex.permission_name %>
@@ -1,4 +1,4 @@
1
- class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class AddVoltexTo<%= table_name.camelize %> < <%= migration_class_name %>
2
2
  def change
3
3
  change_table(:<%= table_name %>) do |t|
4
4
  t.references :<%= Voltex.permission_name %>
@@ -1,4 +1,4 @@
1
- class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class VoltexCreate<%= table_name.camelize %> < <%= migration_class_name %>
2
2
  def change
3
3
  create_table(:<%= table_name %>) do |t|
4
4
  t.string :name
@@ -1,4 +1,4 @@
1
- class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class VoltexCreate<%= table_name.camelize %> < <%= migration_class_name %>
2
2
  def change
3
3
  create_table(:<%= table_name %>) do |t|
4
4
  t.string :name
@@ -1,4 +1,4 @@
1
- class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class AddVoltexTo<%= table_name.camelize %> < <%= migration_class_name %>
2
2
  def change
3
3
  change_table(:<%= table_name %>) do |t|
4
4
  t.references :<%= Voltex.role_name %>
@@ -49,6 +49,12 @@ module ActiveRecord
49
49
  def table_exists?
50
50
  ActiveRecord::Base.connection.table_exists? table_name
51
51
  end
52
+
53
+ def migration_class_name
54
+ Rails.version.to_i == 5 ?
55
+ "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]":
56
+ 'ActiveRecord::Migration'
57
+ end
52
58
  end
53
59
  end
54
60
  end
@@ -5,6 +5,7 @@ module ActiveRecord
5
5
  module Generators
6
6
  class VoltexPermissionGenerator < ActiveRecord::Generators::Base
7
7
  include VoltexGenerator
8
+
8
9
  source_root File.expand_path('../templates/permission', __FILE__)
9
10
 
10
11
  private
@@ -5,6 +5,7 @@ module ActiveRecord
5
5
  module Generators
6
6
  class VoltexPermissionsRoleGenerator < ActiveRecord::Generators::Base
7
7
  include VoltexGenerator
8
+
8
9
  source_root File.expand_path('../templates/permissions_role', __FILE__)
9
10
 
10
11
  def generate_model
@@ -5,6 +5,7 @@ module ActiveRecord
5
5
  module Generators
6
6
  class VoltexRoleGenerator < ActiveRecord::Generators::Base
7
7
  include VoltexGenerator
8
+
8
9
  source_root File.expand_path('../templates/role', __FILE__)
9
10
 
10
11
  private
@@ -5,6 +5,7 @@ module ActiveRecord
5
5
  module Generators
6
6
  class VoltexUserGenerator < ActiveRecord::Generators::Base
7
7
  include VoltexGenerator
8
+
8
9
  source_root File.expand_path('../templates/user', __FILE__)
9
10
 
10
11
  private
@@ -0,0 +1,9 @@
1
+ module Voltex
2
+ module CanCan
3
+ def define_voltex_abilities(user)
4
+ Voltex.current_permissions.each do |permission|
5
+ can permission.action.to_sym, permission.resource.constantize
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Voltex
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voltex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erick Fabian
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-15 00:00:00.000000000 Z
12
+ date: 2018-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -59,28 +59,28 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '3.4'
62
+ version: '3.7'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '3.4'
69
+ version: '3.7'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: cucumber
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '2.3'
76
+ version: '3.1'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '2.3'
83
+ version: '3.1'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: aruba
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -143,7 +143,7 @@ files:
143
143
  - lib/generators/voltex/views_generator.rb
144
144
  - lib/tasks/voltex_tasks.rake
145
145
  - lib/voltex.rb
146
- - lib/voltex/cancan/ability.rb
146
+ - lib/voltex/cancan.rb
147
147
  - lib/voltex/engine.rb
148
148
  - lib/voltex/pundit.rb
149
149
  - lib/voltex/scope.rb
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  requirements: []
171
171
  rubyforge_project:
172
- rubygems_version: 2.6.8
172
+ rubygems_version: 2.6.14
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: Dynamic permissions authorization.
@@ -1,11 +0,0 @@
1
- module Voltex
2
- module CanCan
3
- module Ability
4
- def define_voltex_abilities(user)
5
- Voltex.current_permissions.each do |permission|
6
- can permission.action.to_sym, permission.resource.constantize
7
- end
8
- end
9
- end
10
- end
11
- end