typical_situation 1.1.0 → 1.2.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: 48bf00bdaee8edb5e3fbf54b68ca577960068cae3dac7804ca56169d738c834c
4
- data.tar.gz: e11a3d08dd5991937bb08b2b3a731d8bd67f91b19658c25239bef18e60e4f921
3
+ metadata.gz: 1806328a0281819fd09cedb96002dd5e038f56a2b292c608b8e1920bd3e7cf25
4
+ data.tar.gz: fb92828cdf08f013652d379c96e52177b1f6005184b24ac6ea9e9273b4d94383
5
5
  SHA512:
6
- metadata.gz: 584cecff5e2be5ac3201983c4a2e0fbe1ec69cf5cd7cc18c91aa2d267bb73a8680194137774889fe9cd546c3f3dc55ee35bcef53ff643e8b5ff54eb741a7e6fe
7
- data.tar.gz: e31342f32bc78ce7aecf165ce64c51fb38f1fd3d8031ffeec891f38b972945fc0da002227a919afc7942ca61179fe3de4e4dbf4fe3f82af77cc9a014b7ed1b14
6
+ metadata.gz: 4d997a83448cd809e5c884c67fb55cd5be7fe1cf2869b6b177e884300c06cd63b65fce54c85f594b68f239bee417b629e9e9335480ed049c6f05d02d0ad2592f
7
+ data.tar.gz: c4b44e7839dfdcdc8d896354748e154e12c270bfc1c93be8f9167b65f774d24f970ebdc69dc493890bd0f47c582d8075a14d8622963647d69b0c0e55c7bf8c54
data/README.md CHANGED
@@ -117,9 +117,10 @@ For index actions, resources move through this pipeline:
117
117
 
118
118
  1. `collection` - base relation from the host controller
119
119
  2. `scoped_resource` - visibility/tenant/security scoping
120
- 3. `prepare_resources` - search or filter transforms
120
+ 3. `apply_filtering` - request-driven search and filter transforms
121
121
  4. `apply_sorting` - default sorting from `default_sorting_attribute`
122
122
  5. `paginate_resources` - pagination adapter hook
123
+ 6. `prepare_resources` - post-process the loaded records
123
124
 
124
125
  **Scoped Collections** - Restrict the base collection based on user permissions, tenancy, or other security boundaries:
125
126
 
@@ -136,13 +137,21 @@ end
136
137
  **Search and Filtering** - Apply request-driven filters after scoping and before sorting/pagination:
137
138
 
138
139
  ```ruby
139
- def prepare_resources(resources)
140
+ def apply_filtering(resources)
140
141
  resources = resources.where(status: params[:status]) if params[:status].present?
141
142
  resources = resources.where("title ILIKE ?", "%#{params[:q]}%") if params[:q].present?
142
143
  resources
143
144
  end
144
145
  ```
145
146
 
147
+ **Post-processing** - Mutate or decorate the final paginated record set (e.g. compute a derived attribute on every record):
148
+
149
+ ```ruby
150
+ def prepare_resources(resources)
151
+ resources.each { |post| post.current_user_liked = liked_post_ids.include?(post.id) }
152
+ end
153
+ ```
154
+
146
155
  **Custom Lookup** - Use different attributes for finding resources:
147
156
 
148
157
  ```ruby
@@ -46,22 +46,28 @@ module TypicalSituation
46
46
  # Collection pipeline lifecycle:
47
47
  # collection - base relation (user-defined, required)
48
48
  # scoped_resource - wraps/scopes the collection (visibility, tenancy, PHI)
49
- # prepare_resources - standardized additional transforms (search, filter)
49
+ # apply_filtering - applies search/filter params
50
50
  # apply_sorting - applies ORDER BY
51
51
  # paginate_resources - applies pagination
52
+ # prepare_resources - post-processes the loaded records (e.g. set a computed attribute)
52
53
  #
53
- # Override +prepare_resources+ in host controllers to add search/filter
54
- # behavior without touching sorting or pagination hooks.
54
+ # Override +apply_filtering+ to add search/filter behavior.
55
+ # Override +prepare_resources+ to mutate or decorate the final record set.
55
56
  def get_resources
56
57
  resources = scoped_resource
57
- resources = prepare_resources(resources)
58
+ resources = apply_filtering(resources)
58
59
  resources = apply_sorting(resources)
59
60
  resources = paginate_resources(resources)
61
+ resources = prepare_resources(resources)
60
62
  @resources = resources
61
63
  set_collection_instance
62
64
  @resources
63
65
  end
64
66
 
67
+ def apply_filtering(resources)
68
+ resources
69
+ end
70
+
65
71
  def prepare_resources(resources)
66
72
  resources
67
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypicalSituation
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typical_situation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mars Hall