civil 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36e9e60e77f322cb051c7bc260731a64aa7130dd
4
- data.tar.gz: f77a1dd589ac256dc93b54c71819c4848f7a85f9
3
+ metadata.gz: 7466208c6933e1c80abafd6ca50f919a479b65a8
4
+ data.tar.gz: 998b31b58587c0b45c59fe069a646ce3b5d53926
5
5
  SHA512:
6
- metadata.gz: 636c61112090b66682338c75d4ee33f8ed5e6c58b187f44cd501a7468b32dd041d8311c5fe09eda618c0242a9151347ba325e334afed3e8b1092a4ab0f99c5bc
7
- data.tar.gz: f52797cb0bece1e82362963d9586bba35b1d565344acc0776cd4db5623949066d306358d19c130b0a0b693c42345822ab2c35cf75e49b90b8308e0d74882cc3a
6
+ metadata.gz: 9cdfee13f4671d49cf5c5d23336b095915ab90b0b8a29c216cd2e530953a44f5fb774308130400ca187fbea67964b25c0240d006736aed7145d7c8aee3bc04ea
7
+ data.tar.gz: 7796162ca2fd5625955ae0755565eedb6f308e3f1de31dee46403ab5790b2be4ebcd8fa56aa78b01104e11f0c9bdc212c03ba277932409391214ea7a55d5aa1f
@@ -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/v2.0.0...HEAD
60
- [1.2.0]: https://github.com/earksiinni/civil/compare/v1.1.0...v2.0.0
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: {12.5} }
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') # {{ 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' }}
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
@@ -2,4 +2,4 @@ require "civil/version"
2
2
  require "civil/service"
3
3
  require "civil/result"
4
4
  require "civil/hash"
5
- require "civil/set"
5
+ require "civil/array"
@@ -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
@@ -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::Set.new)
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::Set.new)
49
+ meta = (_meta[key.to_sym] ||= Civil::Array.new)
50
50
 
51
51
  meta << metadatum
52
52
  end
@@ -1,3 +1,3 @@
1
1
  module Civil
2
- VERSION = "2.1.0"
2
+ VERSION = "3.0.0"
3
3
  end
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: 2.1.0
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:
@@ -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