effective_resources 2.32.0 → 2.34.0

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: a6ac2e641e8596cdcce840faf6fb901d7ca6394757e6f98eb7d8bbe30a30e23d
4
- data.tar.gz: beb65fb3bd8397e0a347b944fddcd271cf032553a07a1f5230fac5023f92cf36
3
+ metadata.gz: a673f073e82b66e022333d5aa269a5575dac0781dda438062842cfa2947e5e04
4
+ data.tar.gz: 8c69a47dcfb84b34046c56d925a5e0c325e5354f7106d9a835b2ed483556a07d
5
5
  SHA512:
6
- metadata.gz: 52920001d7999fd0fa0d4e7a6dea54193eb47ad4b0f5ea953375547292a2d06d3afc3b56f4e3355e1baf7a87406c4379b3b6b7bdb492f6047c8abe28fa37232d
7
- data.tar.gz: 221e98eb7e99f98a7690c9d0684416e4e8ed63e2a9e05a9c800609c653ec007425b74b1a4e5c7f13bdfc9f7a5aba7677d23ccd4a31a912fad285918a35878c91
6
+ metadata.gz: f57d263e36acb49eae8ff7cb87da207fdb1827075006da249d4bd5d247c5b4f956bf13f0bd0b0fde52200abd927f0b52139d02aad1d00dc0e37965313b935bc2
7
+ data.tar.gz: b10d8fd11ad1973ba4ddd1aac85e2a5de25217cc11f7a5e001eedac1f11a30e19cdc4461eb9cb1d54152b7e82cd2d1de9ac3147b01c41fc13ec13dbb71b7c2f2
@@ -36,7 +36,7 @@ module Effective
36
36
  # submit :save, 'Save', success: -> { "#{resource} was saved okay!" }
37
37
  def submit(action, label, args = {})
38
38
  instance_exec do
39
- before_action { _insert_submit(action, label, args) }
39
+ prepend_before_action { _insert_submit(action, label, args) }
40
40
  end
41
41
  end
42
42
 
@@ -49,7 +49,7 @@ module Effective
49
49
  # button :decline, false
50
50
  def button(action, label = nil, args = {})
51
51
  instance_exec do
52
- before_action { _insert_button(action, label, args) }
52
+ prepend_before_action { _insert_button(action, label, args) }
53
53
  end
54
54
  end
55
55
 
@@ -57,7 +57,7 @@ module Effective
57
57
  # submit and buttons options will be merged ontop of these
58
58
  def on(action, args = {})
59
59
  instance_exec do
60
- before_action { _insert_on(action, args) }
60
+ prepend_before_action { _insert_on(action, args) }
61
61
  end
62
62
  end
63
63
 
@@ -29,7 +29,8 @@ module Effective
29
29
  # before_action :authorize_resource, only: [:show, :update]
30
30
  # Authorize the resource
31
31
  def authorize_resource
32
- EffectiveResources.authorize!(self, action_name.to_sym, resource)
32
+ action = (commit_action[:action] == :save ? action_name : commit_action[:action]).to_sym
33
+ EffectiveResources.authorize!(self, action, resource)
33
34
  end
34
35
 
35
36
  # before_action :assign_required_steps, only: [:show, :update]
@@ -22,9 +22,21 @@ module Effective
22
22
  # name: sort by this column, or this relation
23
23
  # sort: when a symbol or boolean, this is the relation's column to sort by
24
24
 
25
- def order(name, direction = :asc, as: nil, sort: nil, sql_column: nil, limit: nil, reorder: false)
25
+ # There is a sort by array (ids) syntax:
26
+ # This will sort the base collection.id array by the given direction
27
+ #
28
+ # Effective::Resource.new(collection).order(direction) do
29
+ # collection.sort { |a, b| a.membership&.category.to_s <=> b.membership&.category.to_s }
30
+ # end
31
+
32
+ def order(name = nil, direction = :asc, as: nil, sort: nil, sql_column: nil, limit: nil, reorder: false, &block)
26
33
  raise 'expected relation to be present' unless relation
27
34
 
35
+ if block_given? && (name == :asc || name == :desc)
36
+ direction = name
37
+ name = :id
38
+ end
39
+
28
40
  sql_column ||= sql_column(name)
29
41
  sql_type = (as || sql_type(name))
30
42
 
@@ -32,6 +44,11 @@ module Effective
32
44
  sql_direction = sql_direction(direction)
33
45
  @relation = relation.reorder(nil) if reorder
34
46
 
47
+ if block_given?
48
+ ids = block.call().map { |resource| resource.try(:id) || resource }
49
+ return relation.order(order_by_array_position((direction == :asc) ? ids : ids.reverse, sql_column))
50
+ end
51
+
35
52
  case sql_type
36
53
  when :belongs_to
37
54
  relation
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.32.0'.freeze
2
+ VERSION = '2.34.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.32.0
4
+ version: 2.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-06 00:00:00.000000000 Z
11
+ date: 2025-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails