consul 0.12.4 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of consul might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +0 -1
- data/README.md +20 -1
- data/Rakefile +1 -1
- data/lib/consul/controller.rb +4 -0
- data/lib/consul/power.rb +19 -6
- data/lib/consul/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca9294f9af0f9456d5951b5bf1d8657060fbda67
|
4
|
+
data.tar.gz: 57ce0c814786137d801dd5fbc9d1595a05d1e076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69c0404a0afcee733ca00380bdae22620a897083be8c6d1d9ee055fd3d3abeae7f59a6ff834b6d76938f5b776bc27a50e9c784bdf3e5b3f475d2765a8dfdbe8f
|
7
|
+
data.tar.gz: 484ec20a1104eaaded3681807e28694de11f6d5c383f357372f94fefdab2fbc11809b3ecebc3a0381625fff192f34545715b0167b9d953bfea8a863bdf99cf76
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Consul is an authorization solution for Ruby on Rails where you describe *sets o
|
|
8
8
|
We have used Consul in combination with [assignable_values](https://github.com/makandra/assignable_values) to solve a variety of authorization requirements ranging from boring to bizarre.
|
9
9
|
Also see our crash course video: [Solving bizare authorization requirements with Rails](http://bizarre-authorization.talks.makandra.com/).
|
10
10
|
|
11
|
-
Consul is tested with Rails 2.3, 3.2, 4.
|
11
|
+
Consul is tested with Rails 2.3, 3.2, 4.2, and 5.1 on Ruby 1.8.7, 2.1, and 2.4 (only if supported, for each Ruby/Rails combination).
|
12
12
|
|
13
13
|
|
14
14
|
Describing access to your application
|
@@ -628,6 +628,25 @@ The `authorize_values_for` macro comes with many useful options and details best
|
|
628
628
|
assignable_values_for :field, :through => lambda { Power.current }
|
629
629
|
```
|
630
630
|
|
631
|
+
Memoization
|
632
|
+
-----------
|
633
|
+
|
634
|
+
All power methods are [memoized](https://www.justinweiss.com/articles/4-simple-memoization-patterns-in-ruby-and-one-gem/) for performance reasons. Multiple calls to the same method will only call your block the first time, and return a cached result afterwards:
|
635
|
+
|
636
|
+
```
|
637
|
+
power = Power.new
|
638
|
+
power.projects! # calls the `power :projects { ... }` block
|
639
|
+
power.projects! # returns the cached result from earlier
|
640
|
+
power.projects! # returns the cached result from earlier
|
641
|
+
```
|
642
|
+
|
643
|
+
If you want to discard all cached results, call `#unmemoize_all`:
|
644
|
+
|
645
|
+
```
|
646
|
+
power.unmemoize_all
|
647
|
+
```
|
648
|
+
|
649
|
+
|
631
650
|
Dynamic power access
|
632
651
|
--------------------
|
633
652
|
|
data/Rakefile
CHANGED
@@ -52,7 +52,7 @@ def for_each_directory_of(path, &block)
|
|
52
52
|
puts 'Skipping - Rails 3.2.13 does not support Ruby 2.2+'
|
53
53
|
elsif directory.include?('rails-4.2') && (RUBY_VERSION < '1.9.3' || RUBY_VERSION >= '2.4.0')
|
54
54
|
puts 'Skipping - Rails 4.2 requires Ruby 1.9.3+ .. 2.3.x'
|
55
|
-
elsif directory.include?('rails-5.1
|
55
|
+
elsif directory.include?('rails-5.1') && RUBY_VERSION < '2.2.2'
|
56
56
|
puts 'Skipping - Rails 5 requires Ruby 2.2.2+'
|
57
57
|
else
|
58
58
|
block.call(directory)
|
data/lib/consul/controller.rb
CHANGED
@@ -46,6 +46,10 @@ module Consul
|
|
46
46
|
elsif Rails.version.to_i < 5
|
47
47
|
skip_before_action :unchecked_power, options
|
48
48
|
else
|
49
|
+
# Every `power` in a controller will skip the power check filter. After the 1st time, Rails 5+ will raise
|
50
|
+
# an error because there is no `unchecked_power` action to skip any more.
|
51
|
+
# To avoid this, we add the following extra option. Note that it must not be added in Rails 4 to avoid errors.
|
52
|
+
# See http://api.rubyonrails.org/classes/ActiveSupport/Callbacks/ClassMethods.html#method-i-skip_callback
|
49
53
|
skip_before_action :unchecked_power, { :raise => false }.merge!(options)
|
50
54
|
end
|
51
55
|
end
|
data/lib/consul/power.rb
CHANGED
@@ -63,8 +63,6 @@ module Consul
|
|
63
63
|
self.class.singularize_power_name(name)
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
66
|
module ClassMethods
|
69
67
|
include Consul::Power::DynamicAccess::ClassMethods
|
70
68
|
|
@@ -109,16 +107,34 @@ module Consul
|
|
109
107
|
query_method = "#{name}?"
|
110
108
|
bang_method = "#{name}!"
|
111
109
|
define_method(query_method, &query)
|
110
|
+
memoize query_method
|
112
111
|
define_method(bang_method) { |*args| send(query_method, *args) or powerless!(name, *args) }
|
112
|
+
# We don't memoize the bang method since memoizer can't memoize a thrown exception
|
113
|
+
end
|
114
|
+
|
115
|
+
def define_ids_method(name)
|
116
|
+
ids_method = power_ids_name(name)
|
117
|
+
define_method(ids_method) { |*args| default_power_ids(name, *args) }
|
118
|
+
# Memoize `ids_method` in addition to the collection method itself, since
|
119
|
+
# #default_include_object? directly accesses `ids_method`.
|
120
|
+
memoize ids_method
|
121
|
+
end
|
122
|
+
|
123
|
+
def define_main_method(name, &block)
|
124
|
+
define_method(name, &block)
|
125
|
+
memoize name
|
113
126
|
end
|
114
127
|
|
115
128
|
def define_power(name, &block)
|
116
129
|
name = name.to_s
|
117
130
|
if name.ends_with?('?')
|
131
|
+
# The developer is trying to register an optimized query method
|
132
|
+
# for singular object queries.
|
118
133
|
name_without_suffix = name.chop
|
119
134
|
define_query_and_bang_methods(name_without_suffix, &block)
|
120
135
|
else
|
121
|
-
|
136
|
+
define_main_method(name, &block)
|
137
|
+
define_ids_method(name)
|
122
138
|
define_query_and_bang_methods(name) { |*args| default_include_power?(name, *args) }
|
123
139
|
begin
|
124
140
|
singular = singularize_power_name(name)
|
@@ -127,9 +143,6 @@ module Consul
|
|
127
143
|
# We do not define singularized power methods if it would
|
128
144
|
# override the collection method
|
129
145
|
end
|
130
|
-
ids_method = power_ids_name(name)
|
131
|
-
define_method(ids_method) { |*args| default_power_ids(name, *args) }
|
132
|
-
memoize ids_method
|
133
146
|
end
|
134
147
|
name
|
135
148
|
end
|
data/lib/consul/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memoizer
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.6.13
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: A scope-based authorization solution for Ruby on Rails.
|