consul 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb2a0c2c9a78ba8ad526c9ed666997e3ce7592b1dbbb29e8623d8c21f92265b9
4
- data.tar.gz: 8f1f1dc0d6a22f69aba214cbae6f66d564ab338c06ee63dd20ca158a0d1c1f40
3
+ metadata.gz: 7d56978b19324d537eb1380dd0435e7a9dca4b4c8e7195f0e4e649ad6baa3065
4
+ data.tar.gz: ebe94441887929eae46422dbc6974e5b71da7e41fba2d0005f9ed650f471b14e
5
5
  SHA512:
6
- metadata.gz: 90e19bae5eddeadf3d99a8f31922cb928d911c4957b8558cb28624589b7e6697050d68801af5d2790bb1eae8734aec960ff51976fe8a87abf367788404dcc53e
7
- data.tar.gz: e3e3f137d384cd4b4248baaedc5a7faa020d889d68bcec5a5aa027cdcf4b6ac3bca4e2acece65a6078adbdc518755c887730f12d65c16f67ed86e47724963ffb
6
+ metadata.gz: a85d9db39a349fc55768bc54d87c198f41fd9bdbd6f254ed9e9c75c5783c3809e4f08f797407894c5f6cd39bfbb8fb0bd9d2428756dcb0997ab158d3f1fc1af9
7
+ data.tar.gz: e74d092a626238d63b605db9da653ef63dbf08fabca8d18dfff25602fc25771a32733bb4c22adc749703d8b53c50d6aeff46e88ed9279f5afb4cae23148b728b
data/CHANGELOG.md CHANGED
@@ -9,6 +9,18 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
9
9
 
10
10
  ### Compatible changes
11
11
 
12
+ ## 1.3.1 - 2023-02-28
13
+
14
+ ### Compatible changes
15
+
16
+ - clean release to fix file permissions of files that were broken in 1.3.0
17
+
18
+ ## 1.3.0 - 2023-01-27
19
+
20
+ ### Compatible changes
21
+
22
+ - When you [map a power to a controller method](https://github.com/makandra/consul#auto-mapping-a-power-scope-to-a-controller-method) you can now override the generated method. The original implementation can be accessed with `super`.
23
+ - When trying to map multiple controller method with the name, an error is now raised. Previously only the last mapping was used.
12
24
 
13
25
 
14
26
  ## 1.2.0 - 2023-01-24
data/Gemfile.5-2.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consul (1.2.0)
4
+ consul (1.3.1)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  edge_rider (>= 0.3.0)
data/Gemfile.6-1.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consul (1.2.0)
4
+ consul (1.3.1)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  edge_rider (>= 0.3.0)
data/Gemfile.7-0.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consul (1.2.0)
4
+ consul (1.3.1)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  edge_rider (>= 0.3.0)
data/README.md CHANGED
@@ -476,7 +476,23 @@ class NotesController < ApplicationController
476
476
  end
477
477
  ```
478
478
 
479
- This is especially useful when you are using a RESTful controller library like [resource_controller](https://github.com/jamesgolick/resource_controller). The mapped method is aware of the `:map` option.
479
+ The mapped method is aware of the `:map` option.
480
+
481
+ The mapped method can be overridden and access the original implementation using `super`:
482
+
483
+ ```ruby
484
+ class NotesController < ApplicationController
485
+
486
+ power :notes, :as => :note_scope
487
+
488
+ # ...
489
+
490
+ def note_scope
491
+ super.where(trashed: false)
492
+ end
493
+
494
+ end
495
+ ```
480
496
 
481
497
 
482
498
  ### Multiple power-mappings for nested resources
@@ -47,6 +47,7 @@ module Consul
47
47
 
48
48
  def power(*args)
49
49
  guard = Consul::Guard.new(*args)
50
+ controller = self
50
51
 
51
52
  # One .power directive will skip the check for all actions, even
52
53
  # if that .power directive has :only or :except options.
@@ -60,14 +61,49 @@ module Consul
60
61
  end
61
62
 
62
63
  if guard.direct_access_method
63
- define_method guard.direct_access_method do
64
- guard.power_value(self, action_name)
64
+ consul_features_module.module_eval do
65
+ # It's dangerous to re-define direct access methods like this:
66
+ #
67
+ # power :one, as: :my_power
68
+ # power :two, as: :my_power
69
+ #
70
+ # The method would always check the last power only.
71
+ # To prevent this we're raising an error.
72
+ if method_defined?(guard.direct_access_method)
73
+ raise DuplicateMethod, "Method #{direct_access_method} is already defined on #{controller.name}"
74
+ end
75
+
76
+ define_method guard.direct_access_method do
77
+ guard.power_value(self, action_name)
78
+ end
79
+
80
+ private guard.direct_access_method
65
81
  end
66
- private guard.direct_access_method
67
82
  end
68
83
 
69
84
  end
70
85
 
86
+ # Instead of using define_method on the controller we're enhancing,
87
+ # we define dynamic method in a module and have the controller include that.
88
+ # This way the controller can override our generated method and access
89
+ # the original implenentation with super().
90
+ #
91
+ # See https://thepugautomatic.com/2013/07/dsom/ for more examples on this
92
+ # technique.
93
+ def consul_features_module
94
+ name = :ConsulFeatures
95
+ # Each controller class should get its own FeatureModule, even when
96
+ # we already inherit one from our parent.
97
+ if const_defined?(name, (_search_ancestors = false))
98
+ const_get(name, _search_ancestors = false)
99
+ else
100
+ mod = Module.new
101
+ const_set(name, mod)
102
+ include(mod)
103
+ mod
104
+ end
105
+ end
106
+
71
107
  # On first access we inherit .consul_power_args from our ancestor classes.
72
108
  # We also copy inherited args so we don't change our parent's .consul_power_args
73
109
  def consul_power_args
data/lib/consul/errors.rb CHANGED
@@ -7,4 +7,5 @@ module Consul
7
7
  class NoCollection < Error; end
8
8
  class MissingContext < Error; end
9
9
  class PowerNotSingularizable < Error; end
10
+ class DuplicateMethod < Error; end
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module Consul
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.1'
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: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-24 00:00:00.000000000 Z
11
+ date: 2023-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: memoized