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 +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.5-2.lock +1 -1
- data/Gemfile.6-1.lock +1 -1
- data/Gemfile.7-0.lock +1 -1
- data/README.md +17 -1
- data/lib/consul/controller.rb +39 -3
- data/lib/consul/errors.rb +1 -0
- data/lib/consul/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d56978b19324d537eb1380dd0435e7a9dca4b4c8e7195f0e4e649ad6baa3065
|
4
|
+
data.tar.gz: ebe94441887929eae46422dbc6974e5b71da7e41fba2d0005f9ed650f471b14e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/Gemfile.6-1.lock
CHANGED
data/Gemfile.7-0.lock
CHANGED
data/README.md
CHANGED
@@ -476,7 +476,23 @@ class NotesController < ApplicationController
|
|
476
476
|
end
|
477
477
|
```
|
478
478
|
|
479
|
-
|
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
|
data/lib/consul/controller.rb
CHANGED
@@ -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
|
-
|
64
|
-
|
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
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: 1.
|
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-
|
11
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memoized
|