consul 0.13.1 → 0.13.2

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
- SHA1:
3
- metadata.gz: a1b81fc040672be5ea52bad364ca2b1232f66350
4
- data.tar.gz: 396dadb1a2f3d60920c35caedda794a32518508c
2
+ SHA256:
3
+ metadata.gz: 06155bb23047c53d7674934ff0274db41f0241ed9fc45d13959bbe87b7a68a66
4
+ data.tar.gz: f28959645bdbbecd5596d764c4993f36d1e7c42c5e12f0b0014f2a57624c0a92
5
5
  SHA512:
6
- metadata.gz: 2d93efa23a105f53b00fc613e5c44cececa812d6a8f765a609f012ac63222693c0ac13f9eb2b8477cfd9f5048eb54cac0f8a1d9327208649727c2ec74824bd1b
7
- data.tar.gz: 4f6724cb723c9aea92b7f10d8604966dabb779923b1ec64351eb3b0dd6fb0e9ba488a3b2dda13daae8f29b93f1cf1af6bbabdbd518f5cbf1aeea073a31d4d92f
6
+ metadata.gz: 83138414bd69ce544205a1ffe280a1255f0e56217a94c0208bae1d66fb4cccba76e155206a9f032f7cceaae6737d74b1c559fa80fb89904ad57ad4419043aba6
7
+ data.tar.gz: d861f0003017f975a55688b3971a72ba8d1f9da3ac3023f146d9b392eff824f8fa0123eb27629597d3b2e00d8959f3ef920e9bd51704fcb2ccbbddb34893232b
@@ -0,0 +1,42 @@
1
+ All notable changes to this project will be documented in this file.
2
+
3
+ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4
+
5
+
6
+ ## Unreleased
7
+
8
+ ### Breaking changes
9
+
10
+ -
11
+
12
+ ### Compatible changes
13
+
14
+ -
15
+
16
+ ## 0.13.2 - 2017-10-02
17
+
18
+ ### Compatible changes
19
+
20
+ - Bang methods should return the scope when successful (e.g. `power.notes!` returns the scope you defined in the power)
21
+ - improve the error message for scoped powers
22
+
23
+ ## 0.13.1 - 2017-09-28
24
+
25
+ ### Compatible changes
26
+
27
+ - Fix controller integration when using `ActionController::API`.
28
+
29
+ Thanks to derekprior.
30
+
31
+
32
+ ## 0.13.0 - 2017-09-05
33
+
34
+ ### Breaking change
35
+
36
+ - All powers memoize.
37
+
38
+
39
+ ## Older releases
40
+
41
+ Please check commits.
42
+
@@ -22,6 +22,7 @@ module Consul
22
22
  end
23
23
 
24
24
  def default_include_object?(power_name, *args)
25
+ check_number_of_arguments_in_include_object(power_name, args.length)
25
26
  object = args.pop
26
27
  context = args
27
28
  power_value = send(power_name, *context)
@@ -63,6 +64,16 @@ module Consul
63
64
  self.class.singularize_power_name(name)
64
65
  end
65
66
 
67
+ def check_number_of_arguments_in_include_object(power_name, given_arguments)
68
+ # check unmemoized methods as Memoizer wraps methods and masks the arity.
69
+ unmemoized_power_name = respond_to?("_unmemoized_#{power_name}") ? "_unmemoized_#{power_name}" : power_name
70
+ power_arity = method(unmemoized_power_name).arity
71
+ expected_arity = power_arity + 1 # one additional argument for the context
72
+ if power_arity >= 0 && expected_arity != given_arguments
73
+ raise ArgumentError.new("wrong number of arguments (given #{given_arguments}, expected #{expected_arity})")
74
+ end
75
+ end
76
+
66
77
  module ClassMethods
67
78
  include Consul::Power::DynamicAccess::ClassMethods
68
79
 
@@ -103,12 +114,23 @@ module Consul
103
114
  with_power(nil, &block)
104
115
  end
105
116
 
106
- def define_query_and_bang_methods(name, &query)
117
+ def define_query_and_bang_methods(name, options, &query)
118
+ is_plural = options.fetch(:is_plural)
107
119
  query_method = "#{name}?"
108
120
  bang_method = "#{name}!"
109
121
  define_method(query_method, &query)
110
122
  memoize query_method
111
- define_method(bang_method) { |*args| send(query_method, *args) or powerless!(name, *args) }
123
+ define_method(bang_method) do |*args|
124
+ if is_plural
125
+ if send(query_method, *args)
126
+ send(name, *args)
127
+ else
128
+ powerless!(name, *args)
129
+ end
130
+ else
131
+ send(query_method, *args) or powerless!(name, *args)
132
+ end
133
+ end
112
134
  # We don't memoize the bang method since memoizer can't memoize a thrown exception
113
135
  end
114
136
 
@@ -131,14 +153,14 @@ module Consul
131
153
  # The developer is trying to register an optimized query method
132
154
  # for singular object queries.
133
155
  name_without_suffix = name.chop
134
- define_query_and_bang_methods(name_without_suffix, &block)
156
+ define_query_and_bang_methods(name_without_suffix, :is_plural => false, &block)
135
157
  else
136
158
  define_main_method(name, &block)
137
159
  define_ids_method(name)
138
- define_query_and_bang_methods(name) { |*args| default_include_power?(name, *args) }
160
+ define_query_and_bang_methods(name, :is_plural => true) { |*args| default_include_power?(name, *args) }
139
161
  begin
140
162
  singular = singularize_power_name(name)
141
- define_query_and_bang_methods(singular) { |*args| default_include_object?(name, *args) }
163
+ define_query_and_bang_methods(singular, :is_plural => false) { |*args| default_include_object?(name, *args) }
142
164
  rescue Consul::PowerNotSingularizable
143
165
  # We do not define singularized power methods if it would
144
166
  # override the collection method
@@ -1,3 +1,3 @@
1
1
  module Consul
2
- VERSION = '0.13.1'
2
+ VERSION = '0.13.2'
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.13.1
4
+ version: 0.13.2
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-09-28 00:00:00.000000000 Z
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: memoizer
@@ -60,6 +60,7 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - ".gitignore"
62
62
  - ".travis.yml"
63
+ - CHANGELOG.md
63
64
  - LICENSE
64
65
  - README.md
65
66
  - Rakefile
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  version: '0'
95
96
  requirements: []
96
97
  rubyforge_project:
97
- rubygems_version: 2.6.13
98
+ rubygems_version: 2.7.6
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: A scope-based authorization solution for Ruby on Rails.