halumi 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -11
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c04a4c14a486cfa8ca40c9bd59db8c7884abb3230778c295adbec636f49b5e8f
|
4
|
+
data.tar.gz: '0438cc6e07359e757395fd619abefeb19f5f77b7b9e03b0b21e27b9a32cc2efd'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3a743c8c7f8505be63192f0bdc80106d92fb51cf26c754da6d4fa7da5dfccf264144b48ba461c8b65aa5179228ecec1bc60ba21aa55a4e88ddeb985929d145f
|
7
|
+
data.tar.gz: f46d72e5528ed7a1950803d05d2b18ab2bbaf5bd74715fa51de1efd6d1363fedf7a61eb953635b6fd2b13f1ad7052e90fa95e0cc4d673b6b098b1956c3630963
|
data/README.md
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
# Halumi
|
2
|
-
![Gem](https://img.shields.io/gem/v/halumi.svg) ![GitHub](https://img.shields.io/github/license/PiotrWald/halumi.svg)
|
3
|
-
|
4
|
-
One of the patterns in Rails development I find usefull are query objects.
|
5
|
-
They are essantialy service objects returning a ActiveRecord Relation. Using them
|
6
|
-
results in less code cluttering your controllers and models. Plus you can easily
|
7
|
-
unit test each of your queries.
|
8
|
-
|
9
|
-
This Gem adds simple DSL allowing you to build query objects and than merge
|
10
|
-
them into one query (ActiveRecord::Relation)
|
11
2
|
|
12
3
|
One of the cool patterns in Rails development are query objects.
|
13
4
|
They are essantialy service objects returning a ActiveRecord Relation. Using them
|
@@ -41,6 +32,7 @@ class PaginationQuery < Halumi::Query
|
|
41
32
|
end
|
42
33
|
end
|
43
34
|
```
|
35
|
+
|
44
36
|
```Ruby
|
45
37
|
class PublishedArticlesQuery
|
46
38
|
def execute
|
@@ -63,8 +55,24 @@ end
|
|
63
55
|
This will return published articles, paginated and sorted by creation time
|
64
56
|
|
65
57
|
```Ruby
|
58
|
+
params = { page: 2, per_page: 10 }
|
59
|
+
|
60
|
+
ArticlesQuery.new(params).call
|
61
|
+
```
|
66
62
|
|
67
|
-
|
63
|
+
## Optional integration with Dry::Types
|
68
64
|
|
69
|
-
|
65
|
+
Params with dry type specified behave like they would be sanatized by it. If a a type
|
66
|
+
would rise an error, for example in case of strict types, the error will be rescued and
|
67
|
+
query execution will be terminated
|
68
|
+
|
69
|
+
```Ruby
|
70
|
+
class PaginationQuery < Halumi::Query
|
71
|
+
param :per_page, Types::Strict::Integer
|
72
|
+
param :page, Types::Strict::Integer
|
73
|
+
|
74
|
+
def execute
|
75
|
+
relation.page(page).per(per_page)
|
76
|
+
end
|
77
|
+
end
|
70
78
|
```
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: halumi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Wald
|
@@ -14,16 +14,16 @@ dependencies:
|
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dry-types
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.0.
|
84
|
+
rubygems_version: 3.0.3
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Use query objects as flexible building blocks
|