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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f26edaf1d93b7150757a61ab7ff678026e08bd5
4
- data.tar.gz: 1c42642576f8d7f5fc41a64ee1a4b07a50fd4596
3
+ metadata.gz: ca9294f9af0f9456d5951b5bf1d8657060fbda67
4
+ data.tar.gz: 57ce0c814786137d801dd5fbc9d1595a05d1e076
5
5
  SHA512:
6
- metadata.gz: 839f3d4d75529467aaef3b5fbab879a410c9fd53a63cb35c76c18757073cec47dd1fe83d18af7fe56a60eee641ec7c424be6aba9b7db14db6dd8d36846fe1cf3
7
- data.tar.gz: d6b9d7a73176eaa0f07a2562a601189225a3b6f74ae1f2ce5a00f91b248936f728fa67ea9edc647a8b937a5a1293bfe22558a10bb2ab4cfa6af0b7859468a86d
6
+ metadata.gz: 69c0404a0afcee733ca00380bdae22620a897083be8c6d1d9ee055fd3d3abeae7f59a6ff834b6d76938f5b776bc27a50e9c784bdf3e5b3f475d2765a8dfdbe8f
7
+ data.tar.gz: 484ec20a1104eaaded3681807e28694de11f6d5c383f357372f94fefdab2fbc11809b3ecebc3a0381625fff192f34545715b0167b9d953bfea8a863bdf99cf76
data/.gitignore CHANGED
@@ -3,6 +3,6 @@ pkg
3
3
  *.gem
4
4
  .idea
5
5
  *.db
6
- app_root/log/*
6
+ *.log
7
7
  .bundle
8
8
  spec/shared/app_root/db/*.sqlite3
@@ -3,7 +3,6 @@ sudo: false
3
3
  rvm:
4
4
  - "1.8.7"
5
5
  - "2.1.0"
6
- - "2.2.6"
7
6
  - "2.4.1"
8
7
  before_install: gem install bundler # Fix bundler issues on 1.9.3
9
8
  before_script: rake travis_ci:prepare
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.1, 4.2.7, and 5.1.1 on Ruby 1.8.7, 2.1.0, 2.2.6, and 2.4.1 (only if supported, for each Ruby/Rails combination).
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.1') && RUBY_VERSION < '2.2.2'
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)
@@ -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
@@ -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
- define_method(name, &block)
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
@@ -1,3 +1,3 @@
1
1
  module Consul
2
- VERSION = '0.12.4'
2
+ VERSION = '0.13.0'
3
3
  end
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.12.4
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-06-23 00:00:00.000000000 Z
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.2.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.