civil 2.1.0 → 3.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 +11 -2
- data/README.md +5 -5
- data/lib/civil.rb +1 -1
- data/lib/civil/array.rb +35 -0
- data/lib/civil/service.rb +2 -2
- data/lib/civil/version.rb +1 -1
- metadata +2 -2
- data/lib/civil/set.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7466208c6933e1c80abafd6ca50f919a479b65a8
|
4
|
+
data.tar.gz: 998b31b58587c0b45c59fe069a646ce3b5d53926
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cdfee13f4671d49cf5c5d23336b095915ab90b0b8a29c216cd2e530953a44f5fb774308130400ca187fbea67964b25c0240d006736aed7145d7c8aee3bc04ea
|
7
|
+
data.tar.gz: 7796162ca2fd5625955ae0755565eedb6f308e3f1de31dee46403ab5790b2be4ebcd8fa56aa78b01104e11f0c9bdc212c03ba277932409391214ea7a55d5aa1f
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [3.0.0] - 2016-12-14
|
10
|
+
### Changed
|
11
|
+
- `Civil::Set` now renamed to `Civil::Array` and inherit from the `::Array`
|
12
|
+
class. This change means that conditions and meta contain `Civil::Array`
|
13
|
+
instances as values, which can be operated on like normal arrays (e.g.,
|
14
|
+
`result.conditions[:id].first[:desc]`).
|
15
|
+
|
9
16
|
## [2.1.0] - 2016-12-14
|
10
17
|
### Added
|
11
18
|
- `Civil::Set#pluck` to enable extracting a given field from a set of
|
@@ -56,7 +63,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
|
|
56
63
|
- Documentation and examples in README.md
|
57
64
|
- This changelog :-)
|
58
65
|
|
59
|
-
[Unreleased]: https://github.com/earksiinni/civil/compare/
|
60
|
-
[
|
66
|
+
[Unreleased]: https://github.com/earksiinni/civil/compare/v3.0.0...HEAD
|
67
|
+
[3.0.0]: https://github.com/earksiinni/civil/compare/v2.1.0...v3.0.0
|
68
|
+
[2.1.0]: https://github.com/earksiinni/civil/compare/v2.0.0...v2.1.0
|
69
|
+
[2.0.0]: https://github.com/earksiinni/civil/compare/v1.1.0...v2.0.0
|
61
70
|
[1.1.0]: https://github.com/earksiinni/civil/compare/v1.0.0...v1.1.0
|
62
71
|
[1.0.0]: https://github.com/earksiinni/civil/compare/v0.1.0...v1.0.0
|
data/README.md
CHANGED
@@ -84,7 +84,7 @@ Your condition will be available in your result:
|
|
84
84
|
```ruby
|
85
85
|
result = SaveAvatarImage.call image: image
|
86
86
|
|
87
|
-
result.conditions # { image_too_big: "The uploaded image must be < 1 MB in size" }
|
87
|
+
result.conditions # { image_too_big: [ "The uploaded image must be < 1 MB in size" ] }
|
88
88
|
result.ideal? # false
|
89
89
|
result.deviant? # true
|
90
90
|
```
|
@@ -106,7 +106,7 @@ end
|
|
106
106
|
|
107
107
|
result = MetadataExample.call doodad: doodad
|
108
108
|
|
109
|
-
result.meta # { length:
|
109
|
+
result.meta # { length: [ 12.5 ] }
|
110
110
|
```
|
111
111
|
|
112
112
|
### Overriding the service block
|
@@ -148,9 +148,9 @@ end
|
|
148
148
|
|
149
149
|
result = BuildCars.call(makes: ['Wondercar', 'Lamecar', 'Hamilcar'])
|
150
150
|
|
151
|
-
result.conditions[:cars].where(make: 'Wondercar') # {
|
152
|
-
result.conditions[:cars].where(make: 'Wondercar', msg: 'not a thing') # {
|
153
|
-
result.meta[:cars].where(make: 'Wondercar') # {
|
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
154
|
```
|
155
155
|
|
156
156
|
For filtering to work properly, you must pass a hash or an instance of
|
data/lib/civil.rb
CHANGED
data/lib/civil/array.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Civil
|
2
|
+
class Array < ::Array
|
3
|
+
def initialize(*args, &block)
|
4
|
+
if args[0].is_a? ::Array
|
5
|
+
args[0] = args[0].map { |e| e.is_a?(::Hash) ? Civil::Hash.new.merge(e) : e }
|
6
|
+
end
|
7
|
+
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(o)
|
12
|
+
o and o.is_a?(::Hash) and o = Civil::Hash.new.merge(o)
|
13
|
+
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def where(attrs)
|
18
|
+
self.inject(Civil::Array.new) { |arr, item|
|
19
|
+
item.is_a?(Civil::Hash) and item =~ attrs and arr << item
|
20
|
+
|
21
|
+
arr
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def pluck(key)
|
26
|
+
raise ArgumentError, "key must be a symbol" unless key.is_a? Symbol
|
27
|
+
|
28
|
+
self.inject(Civil::Array.new) { |arr, item|
|
29
|
+
item.is_a?(Civil::Hash) and arr << item[key]
|
30
|
+
|
31
|
+
arr
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/civil/service.rb
CHANGED
@@ -40,13 +40,13 @@ module Civil
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def add_condition(key, condition)
|
43
|
-
conditions = (_conditions[key.to_sym] ||= Civil::
|
43
|
+
conditions = (_conditions[key.to_sym] ||= Civil::Array.new)
|
44
44
|
|
45
45
|
conditions << condition
|
46
46
|
end
|
47
47
|
|
48
48
|
def add_meta(key, metadatum)
|
49
|
-
meta = (_meta[key.to_sym] ||= Civil::
|
49
|
+
meta = (_meta[key.to_sym] ||= Civil::Array.new)
|
50
50
|
|
51
51
|
meta << metadatum
|
52
52
|
end
|
data/lib/civil/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: civil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ersin Akinci
|
@@ -90,10 +90,10 @@ files:
|
|
90
90
|
- bin/setup
|
91
91
|
- civil.gemspec
|
92
92
|
- lib/civil.rb
|
93
|
+
- lib/civil/array.rb
|
93
94
|
- lib/civil/hash.rb
|
94
95
|
- lib/civil/result.rb
|
95
96
|
- lib/civil/service.rb
|
96
|
-
- lib/civil/set.rb
|
97
97
|
- lib/civil/version.rb
|
98
98
|
homepage: https://github.com/earksiinni/civil
|
99
99
|
licenses:
|
data/lib/civil/set.rb
DELETED
@@ -1,37 +0,0 @@
|
|
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
|
-
|
27
|
-
def pluck(key)
|
28
|
-
raise ArgumentError, "key must be a symbol" unless key.is_a? Symbol
|
29
|
-
|
30
|
-
self.inject(Civil::Set.new) { |set, item|
|
31
|
-
item.is_a?(Civil::Hash) and set.add(item[key])
|
32
|
-
|
33
|
-
set
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|