civil 1.1.0 → 2.0.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/CHANGELOG.md +16 -1
- data/README.md +28 -2
- data/lib/civil.rb +2 -0
- data/lib/civil/hash.rb +11 -0
- data/lib/civil/result.rb +1 -1
- data/lib/civil/service.rb +5 -7
- data/lib/civil/set.rb +27 -0
- data/lib/civil/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8390c4a979faf2430eade2b066f488d1f4513a20
|
4
|
+
data.tar.gz: ac8dbd887ea9a374235673365b8684a6b9ad087e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9346f18a5657d97e9c5f954548e75875dc7ee1bab62462024aaca32d03c0bd93624d8b7156415f0f26382e5b6a413b0956607866df81ba0531a82cc5170e8bc7
|
7
|
+
data.tar.gz: 3545447288f314cad524427a52d1ab3c0e93bb7aa179c9e68d6968a681c9f3d6c476650db7c2faed530971f056b8e470cadb827d87ec05b838ba2580e2a1b4df
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.0.0] - 2016-12-13
|
10
|
+
### Added
|
11
|
+
- `Civil::Hash` and `Civil::Set` utility classes created to enable filtering.
|
12
|
+
- `Civil::Set#where` allows filtering result conditions and meta based on
|
13
|
+
hashes (e.g., `result.conditions[:foo].where(id: 3)`).
|
14
|
+
### Changed
|
15
|
+
- Result conditions and meta are now instances of `Civil::Hash`, whose values
|
16
|
+
can contain instances of `Civil::Set`. This change allows you to filter results
|
17
|
+
and will allow for other neat tricks in the future.
|
18
|
+
- Any time a hash is passed to `add_condition` or `add_meta`, it is
|
19
|
+
automatically converted to and stored as a `Civil::Hash` instance to enable
|
20
|
+
filtering to work.
|
21
|
+
|
9
22
|
## [1.1.0] - 2016-12-2
|
10
23
|
### Added
|
11
24
|
- You can now run services by passing in blocks to `call`. The service will
|
@@ -38,5 +51,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
|
|
38
51
|
- Documentation and examples in README.md
|
39
52
|
- This changelog :-)
|
40
53
|
|
41
|
-
[Unreleased]: https://github.com/earksiinni/civil/compare/
|
54
|
+
[Unreleased]: https://github.com/earksiinni/civil/compare/v2.0.0...HEAD
|
55
|
+
[1.2.0]: https://github.com/earksiinni/civil/compare/v1.1.0...v2.0.0
|
56
|
+
[1.1.0]: https://github.com/earksiinni/civil/compare/v1.0.0...v1.1.0
|
42
57
|
[1.0.0]: https://github.com/earksiinni/civil/compare/v0.1.0...v1.0.0
|
data/README.md
CHANGED
@@ -106,7 +106,7 @@ end
|
|
106
106
|
|
107
107
|
result = MetadataExample.call doodad: doodad
|
108
108
|
|
109
|
-
result.meta # { length: 12.5 }
|
109
|
+
result.meta # { length: {12.5} }
|
110
110
|
```
|
111
111
|
|
112
112
|
### Overriding the service block
|
@@ -129,6 +129,33 @@ end
|
|
129
129
|
result = MyService.call { step_one; result; }
|
130
130
|
```
|
131
131
|
|
132
|
+
### Filtering
|
133
|
+
|
134
|
+
Filter metadata and results by using `where`:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
class BuildCars
|
138
|
+
...
|
139
|
+
|
140
|
+
def trigger_some_conditions_and_metadata
|
141
|
+
if make == 'Wondercar'
|
142
|
+
add_condition :cars, { make: 'Wondercar', msg: 'no such make' }
|
143
|
+
add_condition :cars, { make: 'Wondercar', msg: 'not a thing' }
|
144
|
+
add_meta :cars, { make: 'Wondercar', msg: 'pretty cool name, though' }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
result = BuildCars.call(makes: ['Wondercar', 'Lamecar', 'Hamilcar'])
|
150
|
+
|
151
|
+
result.conditions[:cars].where(make: 'Wondercar') # {{ make: 'Wondercar', msg: 'no such make'}, { make: 'Wondercar', msg: 'not a thing'}}
|
152
|
+
result.conditions[:cars].where(make: 'Wondercar', msg: 'not a thing') # {{ make: 'Wondercar', msg: 'not a thing'}}
|
153
|
+
result.meta[:cars].where(make: 'Wondercar') # {{ make: 'Wondercar', msg: 'pretty cool name, though' }}
|
154
|
+
```
|
155
|
+
|
156
|
+
For filtering to work properly, you must pass a hash or an instance of
|
157
|
+
`Civil::Hash` to `add_condition`/`add_meta`.
|
158
|
+
|
132
159
|
## Development
|
133
160
|
|
134
161
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -143,4 +170,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/earksi
|
|
143
170
|
## License
|
144
171
|
|
145
172
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
146
|
-
|
data/lib/civil.rb
CHANGED
data/lib/civil/hash.rb
ADDED
data/lib/civil/result.rb
CHANGED
data/lib/civil/service.rb
CHANGED
@@ -18,7 +18,7 @@ module Civil
|
|
18
18
|
# Initiate service execution and return standardized result
|
19
19
|
#
|
20
20
|
# result = MyService.call(foo: 1, bar: 'a')
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# if result.ideal?
|
23
23
|
# ...
|
24
24
|
# else
|
@@ -40,25 +40,23 @@ module Civil
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def add_condition(key, condition)
|
43
|
-
conditions = (_conditions[key.to_sym] ||=
|
43
|
+
conditions = (_conditions[key.to_sym] ||= Civil::Set.new)
|
44
44
|
|
45
45
|
conditions << condition
|
46
|
-
conditions.compact!
|
47
46
|
end
|
48
47
|
|
49
48
|
def add_meta(key, metadatum)
|
50
|
-
meta = (_meta[key.to_sym] ||=
|
49
|
+
meta = (_meta[key.to_sym] ||= Civil::Set.new)
|
51
50
|
|
52
51
|
meta << metadatum
|
53
|
-
meta.compact!
|
54
52
|
end
|
55
53
|
|
56
54
|
def _conditions
|
57
|
-
@_conditions ||=
|
55
|
+
@_conditions ||= Civil::Hash.new
|
58
56
|
end
|
59
57
|
|
60
58
|
def _meta
|
61
|
-
@_meta ||=
|
59
|
+
@_meta ||= Civil::Hash.new
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
data/lib/civil/set.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Civil
|
2
|
+
class Set < ::Set
|
3
|
+
def initialize(enum = nil)
|
4
|
+
enum = enum.map { |e| e.is_a?(::Hash) ? Civil::Hash.new.merge(e) : e } if enum
|
5
|
+
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(o)
|
10
|
+
o and o.is_a?(::Hash) and o = Civil::Hash.new.merge(o)
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def <<(o)
|
16
|
+
add(o)
|
17
|
+
end
|
18
|
+
|
19
|
+
def where(attrs)
|
20
|
+
self.inject(Civil::Set.new) { |set, item|
|
21
|
+
item.is_a?(Civil::Hash) and item =~ attrs and set.add(item)
|
22
|
+
|
23
|
+
set
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/civil/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: civil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ersin Akinci
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,8 +90,10 @@ files:
|
|
90
90
|
- bin/setup
|
91
91
|
- civil.gemspec
|
92
92
|
- lib/civil.rb
|
93
|
+
- lib/civil/hash.rb
|
93
94
|
- lib/civil/result.rb
|
94
95
|
- lib/civil/service.rb
|
96
|
+
- lib/civil/set.rb
|
95
97
|
- lib/civil/version.rb
|
96
98
|
homepage: https://github.com/earksiinni/civil
|
97
99
|
licenses:
|