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 +4 -4
- data/README.md +11 -2
- data/lib/typical_situation/operations.rb +10 -4
- data/lib/typical_situation/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1806328a0281819fd09cedb96002dd5e038f56a2b292c608b8e1920bd3e7cf25
|
|
4
|
+
data.tar.gz: fb92828cdf08f013652d379c96e52177b1f6005184b24ac6ea9e9273b4d94383
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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. `
|
|
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
|
|
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
|
-
#
|
|
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 +
|
|
54
|
-
#
|
|
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 =
|
|
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
|