abilities 5.1.1 → 5.1.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
- SHA1:
3
- metadata.gz: 2a328742f75a37f627ee51e9f1a382c57083e793
4
- data.tar.gz: 0004afe3010be40c94f79851653cbb92be3fdf31
2
+ SHA256:
3
+ metadata.gz: 390e74ed5a671ce769044658101f799b29bf3b78303550d4428017121828a02b
4
+ data.tar.gz: 1d899b3cefd76bbeec8ff76e40d0abe4107234832550bf5076809a75c42ee984
5
5
  SHA512:
6
- metadata.gz: e45bd475820f02b3ac78ddd832df89db173aee1449aa9f6c719b0057de859c00954841ced8c0b3789eaf00043af50d24ad326c69bf74f8f635d9f53f069ab67a
7
- data.tar.gz: 9d8dea1930b6c2da6c259be0a5a088f5b0067427cbdfa505a2f0ff8ec3d7854ad3d72e2034792698a6288e41db0b68b3b2b1c660118108e6816d137047c24685
6
+ metadata.gz: 921462f430e857cdf4d9b52756c888e0f81be1c110f4cd8b20a81dc8e31ae5654bb68928e1579b5ab8673a33ef6b4a8af268d1bab1053ca85057d651cb22c520
7
+ data.tar.gz: d971dfcc046789de59ee154722e1031d10847a0ed7445293eb358771fe4519d6adcd8631218491d64172f4022a76ee5cad01188f7190889c94cb3ed31a850952
data/README.md CHANGED
@@ -9,7 +9,7 @@ Authorization dsl to manage permissions in rails.
9
9
 
10
10
  ## Why
11
11
 
12
- I did this gem to:
12
+ We did this gem to:
13
13
 
14
14
  - Use a dsl instead of a plain class to simplify the syntax.
15
15
  - Limit authorizations to only controllers and their views.
@@ -33,12 +33,10 @@ Generate the definitions file:
33
33
  bundle exec rails g abilities:install
34
34
  ```
35
35
 
36
- Ensure there is a current_user method in your controllers:
36
+ Set the user helper name to use in the controllers in the abilities.rb initializer:
37
37
  ```ruby
38
- class ApplicationController < ActionController::Base
39
- def current_user
40
- @current_user ||= User.find(session[:user_id])
41
- end
38
+ Abilities.configure do |config|
39
+ config.helper = :user
42
40
  end
43
41
  ```
44
42
 
@@ -98,7 +96,7 @@ The helpers can? and cannot? are available in the controller views too:
98
96
 
99
97
  Any issue, pull request, comment of any kind is more than welcome!
100
98
 
101
- I will mainly ensure compatibility to Rails, AWS, PostgreSQL, Redis, Elasticsearch and FreeBSD.
99
+ We will mainly ensure compatibility to Rails, AWS, PostgreSQL, Redis, Elasticsearch and FreeBSD.
102
100
 
103
101
  ## Credits
104
102
 
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ Rake::TestTask.new(:test) do |t|
12
12
  t.libs << 'test'
13
13
  t.pattern = 'test/**/*_test.rb'
14
14
  t.verbose = false
15
+ t.warning = false
15
16
  end
16
17
 
17
18
  task default: :test
@@ -1,4 +1,5 @@
1
1
  require 'abilities/extensions/action_controller/base'
2
+ require 'abilities/configuration'
2
3
  require 'abilities/definitions'
3
4
  require 'abilities/exceptions'
4
5
  require 'abilities/proxy'
@@ -10,10 +11,18 @@ module Abilities
10
11
 
11
12
  attr_reader :block
12
13
 
14
+ def configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
13
18
  def define(&block)
14
19
  @block = block
15
20
  end
16
21
 
22
+ def configure
23
+ yield configuration
24
+ end
25
+
17
26
  %i(can? cannot?).each do |name|
18
27
  define_method name do |user, action, resource|
19
28
  definitions = Definitions.new(user, &block)
@@ -0,0 +1,7 @@
1
+ module Abilities
2
+ class Configuration
3
+
4
+ attr_accessor :helper
5
+
6
+ end
7
+ end
@@ -10,7 +10,8 @@ module Abilities
10
10
 
11
11
  %w(can? cannot?).each do |name|
12
12
  define_method name do |action, resource|
13
- Abilities.send name, current_user, action, resource
13
+ user = send(Abilities.configuration.helper)
14
+ Abilities.send name, user, action, resource
14
15
  end
15
16
  end
16
17
 
@@ -1,5 +1,5 @@
1
1
  module Abilities
2
2
 
3
- VERSION = '5.1.1'
3
+ VERSION = '5.1.2'
4
4
 
5
5
  end
@@ -6,6 +6,10 @@ module Abilities
6
6
 
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
 
9
+ def create_initializer_file
10
+ copy_file 'initializer.rb', 'config/initializers/abilities.rb'
11
+ end
12
+
9
13
  def create_configuration_file
10
14
  copy_file 'configuration.rb', 'config/abilities.rb'
11
15
  end
@@ -0,0 +1,3 @@
1
+ Abilities.configure do |config|
2
+ config.helper = :user
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.1
4
+ version: 5.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmontossi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-09 00:00:00.000000000 Z
11
+ date: 2018-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -49,6 +49,7 @@ files:
49
49
  - README.md
50
50
  - Rakefile
51
51
  - lib/abilities.rb
52
+ - lib/abilities/configuration.rb
52
53
  - lib/abilities/definitions.rb
53
54
  - lib/abilities/exceptions.rb
54
55
  - lib/abilities/extensions/action_controller/base.rb
@@ -57,6 +58,7 @@ files:
57
58
  - lib/abilities/version.rb
58
59
  - lib/generators/abilities/install/install_generator.rb
59
60
  - lib/generators/abilities/install/templates/configuration.rb
61
+ - lib/generators/abilities/install/templates/initializer.rb
60
62
  homepage: https://github.com/museways/abilities
61
63
  licenses:
62
64
  - MIT
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
79
  version: '0'
78
80
  requirements: []
79
81
  rubyforge_project:
80
- rubygems_version: 2.6.13
82
+ rubygems_version: 2.7.3
81
83
  signing_key:
82
84
  specification_version: 4
83
85
  summary: Abilities for rails.