realize 1.0.0.pre.alpha.2 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +9 -6
- data/lib/realize/collection/at_index.rb +24 -0
- data/lib/realize/collection/first.rb +14 -0
- data/lib/realize/collection/last.rb +14 -0
- data/lib/realize/collection/sort.rb +3 -7
- data/lib/realize/collection/sort/direction.rb +5 -27
- data/lib/realize/format/date.rb +2 -4
- data/lib/realize/transformers.rb +6 -0
- data/lib/realize/version.rb +1 -1
- data/realize.gemspec +3 -3
- metadata +19 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3bd172f76576e00c4765b1a5dead05e5692a0b79ad5e6e3eb2e3b6bb2c1667c
|
4
|
+
data.tar.gz: 51c606f8a5d85fe3c5ee893e4acae40f647f60350d0f2a0155af6dee5a0e5eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fbd8b77f12fc4054133adb16f1a1e89544ac24fded6bb144d3b2f0e2f20cbb1c87d5261de28d734c8a88a82f8046623b200e836e7983437e0fd506d1baf753d
|
7
|
+
data.tar.gz: 43fef7ff265071ae18a0ed5ef8d77e270cfcd939d9fed0cc4c825f78dda7f7d59db88c150731ab34f3f061c9522b6f0d54d593292df4ae23447de79e5b152273
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
-
# 1.
|
1
|
+
# 1.1.1 (September 9th, 2020)
|
2
|
+
|
3
|
+
Fixes:
|
4
|
+
|
5
|
+
* Do not leverage #to_datetime even if it is available for date parsing. This removes un-intentional coupling of other libraries into Realize and keeps it based on Ruby standard and core libraries.
|
6
|
+
|
7
|
+
# 1.1.0 (June 24th, 2020)
|
8
|
+
|
9
|
+
Addition of r/collection/at_index, r/collection/first, and r/collection/last
|
10
|
+
|
11
|
+
# 1.0.0 (June 9th, 2020)
|
2
12
|
|
3
13
|
Initial Release, includes 15 initial transformers.
|
data/README.md
CHANGED
@@ -62,6 +62,9 @@ Here is a list of each built-in transformer, their options, and what their funct
|
|
62
62
|
|
63
63
|
#### Collection-oriented Transformers
|
64
64
|
|
65
|
+
* **r/collection/at_index** [index]: Takes an array (or coerces value to an array) and returns the value at the given index position.
|
66
|
+
* **r/collection/first** []: Takes an array (or coerces value to an array) and returns the value at the first index position.
|
67
|
+
* **r/collection/last** []: Takes an array (or coerces value to an array) and returns the value at the last index position.
|
65
68
|
* **r/collection/sort** [key, direction]: Takes an array (or coerces value to an array) and sort it either ascending or descending by some defined key's value.
|
66
69
|
|
67
70
|
#### Filtering Transformers
|
@@ -83,12 +86,12 @@ Here is a list of each built-in transformer, their options, and what their funct
|
|
83
86
|
|
84
87
|
#### Value-oriented Transformers
|
85
88
|
|
86
|
-
* **r/
|
87
|
-
* **r/
|
88
|
-
* **r/
|
89
|
-
* **r/
|
90
|
-
* **r/
|
91
|
-
* **r/
|
89
|
+
* **r/value/blank** []: Always return a blank string.
|
90
|
+
* **r/value/map** [values]: Do a lookup on the value using the `values` hash. If a value is found, then its corresponding value is returned. If it isn't then the input is returned.
|
91
|
+
* **r/value/null** []: Always returns null.
|
92
|
+
* **r/value/resolve** [key]: Dynamically resolves a value based on the record's key. It uses the [Objectable](https://github.com/bluemarblepayroll/objectable) library by default, which provides some goodies like dot-notation for nested objects and type-insensitivity (works for Ruby objects, hashes, structs, etc.)
|
93
|
+
* **r/value/static** [value]: Always returns a hard-coded value.
|
94
|
+
* **r/value/verbatim** []: Default transformer, simply echos back the input.
|
92
95
|
|
93
96
|
### Plugging in Transformers
|
94
97
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Realize
|
4
|
+
class Collection
|
5
|
+
# Transformer to get an item of a collection
|
6
|
+
class AtIndex
|
7
|
+
acts_as_hashable
|
8
|
+
|
9
|
+
attr_reader :index
|
10
|
+
|
11
|
+
def initialize(index:)
|
12
|
+
raise ArgumentError, 'index is required' if index.to_s.empty?
|
13
|
+
|
14
|
+
@index = index.to_i
|
15
|
+
|
16
|
+
freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
def transform(_resolver, value, _time, _record)
|
20
|
+
value.is_a?(Array) ? value[index] : value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Realize
|
4
|
+
class Collection
|
5
|
+
# Transformer to get the first item of a collection
|
6
|
+
class First
|
7
|
+
acts_as_hashable
|
8
|
+
|
9
|
+
def transform(resolver, value, time, record)
|
10
|
+
AtIndex.new(index: 0).transform(resolver, value, time, record)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Realize
|
4
|
+
class Collection
|
5
|
+
# Transformer to get the last item of a collection
|
6
|
+
class Last
|
7
|
+
acts_as_hashable
|
8
|
+
|
9
|
+
def transform(resolver, value, time, record)
|
10
|
+
AtIndex.new(index: -1).transform(resolver, value, time, record)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'sort/direction'
|
4
|
+
|
3
5
|
module Realize
|
4
6
|
class Collection
|
5
|
-
# Transformer to take an array of
|
7
|
+
# Transformer to take an array of objects and sort by the given key
|
6
8
|
# and by the given sort direction. Defaulting to ascending.
|
7
9
|
class Sort
|
8
|
-
module Direction
|
9
|
-
ASCENDING = 'ASC'
|
10
|
-
ASC = 'ASC'
|
11
|
-
DESCENDING = 'DESC'
|
12
|
-
DESC = 'DESC'
|
13
|
-
end
|
14
10
|
include Arrays
|
15
11
|
include Direction
|
16
12
|
acts_as_hashable
|
@@ -1,35 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'sort/direction'
|
4
|
-
|
5
3
|
module Realize
|
6
4
|
class Collection
|
7
|
-
# Transformer to take an array of oibjects and sort by the given key
|
8
|
-
# and by the given sort direction. Defaulting to ascending.
|
9
5
|
class Sort
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
attr_reader :key, :order
|
17
|
-
|
18
|
-
def initialize(key:, order: DEFAULT_ORDER)
|
19
|
-
raise ArgumentError, 'key is required' if key.to_s.empty?
|
20
|
-
|
21
|
-
@key = key
|
22
|
-
@order = Direction.const_get(order.to_s.upcase.to_sym)
|
23
|
-
|
24
|
-
freeze
|
25
|
-
end
|
26
|
-
|
27
|
-
def transform(_resolver, value, _time, _record)
|
28
|
-
records = array(value)
|
29
|
-
|
30
|
-
sorted = records.sort_by { |hsh| hsh[key.to_sym] }
|
31
|
-
|
32
|
-
order == DESCENDING ? sorted.reverse : sorted
|
6
|
+
# Constants describing the possible values of 'direction' for a Sort instance.
|
7
|
+
module Direction
|
8
|
+
# providing a few different ways to specify.
|
9
|
+
ASCENDING = ASC = 'ASC'
|
10
|
+
DESCENDING = DESC = 'DESC'
|
33
11
|
end
|
34
12
|
end
|
35
13
|
end
|
data/lib/realize/format/date.rb
CHANGED
@@ -30,12 +30,10 @@ module Realize
|
|
30
30
|
return nil if value.to_s.empty?
|
31
31
|
|
32
32
|
date_time =
|
33
|
-
if
|
34
|
-
value.to_datetime
|
35
|
-
elsif input_format?
|
33
|
+
if input_format?
|
36
34
|
DateTime.strptime(value, input_format)
|
37
35
|
else
|
38
|
-
DateTime.parse(value)
|
36
|
+
DateTime.parse(value.to_s)
|
39
37
|
end
|
40
38
|
|
41
39
|
date_time.strftime(output_format)
|
data/lib/realize/transformers.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'collection/at_index'
|
4
|
+
require_relative 'collection/first'
|
5
|
+
require_relative 'collection/last'
|
3
6
|
require_relative 'collection/sort'
|
4
7
|
require_relative 'filter/by_key_record_value'
|
5
8
|
require_relative 'filter/by_key_value'
|
@@ -25,6 +28,9 @@ module Realize
|
|
25
28
|
acts_as_hashable_factory
|
26
29
|
|
27
30
|
register '', Value::Verbatim
|
31
|
+
register 'r/collection/at_index', Collection::AtIndex
|
32
|
+
register 'r/collection/first', Collection::First
|
33
|
+
register 'r/collection/last', Collection::Last
|
28
34
|
register 'r/collection/sort', Collection::Sort
|
29
35
|
register 'r/filter/by_key_record_value', Filter::ByKeyRecordValue
|
30
36
|
register 'r/filter/by_key_value', Filter::ByKeyValue
|
data/lib/realize/version.rb
CHANGED
data/realize.gemspec
CHANGED
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
|
|
11
11
|
Derive and transform a value using a configuration-first pipeline.
|
12
12
|
DESCRIPTION
|
13
13
|
|
14
|
-
s.authors = ['Matthew Ruggio']
|
15
|
-
s.email = ['mruggio@bluemarblepayroll.com']
|
14
|
+
s.authors = ['Matthew Ruggio', 'Dan Dewar']
|
15
|
+
s.email = ['mruggio@bluemarblepayroll.com', 'ddewar@bluemarblepayroll.com']
|
16
16
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
17
|
s.bindir = 'exe'
|
18
18
|
s.executables = []
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
|
29
29
|
s.required_ruby_version = '>= 2.5'
|
30
30
|
|
31
|
-
s.add_dependency('acts_as_hashable', '
|
31
|
+
s.add_dependency('acts_as_hashable', '~>1', '>=1.2.0')
|
32
32
|
s.add_dependency('objectable', '~>1')
|
33
33
|
|
34
34
|
s.add_development_dependency('guard-rspec', '~>4.7')
|
metadata
CHANGED
@@ -1,29 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: realize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
|
+
- Dan Dewar
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
+
date: 2020-09-09 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: acts_as_hashable
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1
|
20
|
+
version: '1'
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.0
|
20
24
|
type: :runtime
|
21
25
|
prerelease: false
|
22
26
|
version_requirements: !ruby/object:Gem::Requirement
|
23
27
|
requirements:
|
24
|
-
- -
|
28
|
+
- - "~>"
|
25
29
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1
|
30
|
+
version: '1'
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.0
|
27
34
|
- !ruby/object:Gem::Dependency
|
28
35
|
name: objectable
|
29
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +146,7 @@ dependencies:
|
|
139
146
|
description: " Derive and transform a value using a configuration-first pipeline.\n"
|
140
147
|
email:
|
141
148
|
- mruggio@bluemarblepayroll.com
|
149
|
+
- ddewar@bluemarblepayroll.com
|
142
150
|
executables: []
|
143
151
|
extensions: []
|
144
152
|
extra_rdoc_files: []
|
@@ -159,6 +167,9 @@ files:
|
|
159
167
|
- exe/.gitkeep
|
160
168
|
- lib/realize.rb
|
161
169
|
- lib/realize/arrays.rb
|
170
|
+
- lib/realize/collection/at_index.rb
|
171
|
+
- lib/realize/collection/first.rb
|
172
|
+
- lib/realize/collection/last.rb
|
162
173
|
- lib/realize/collection/sort.rb
|
163
174
|
- lib/realize/collection/sort/direction.rb
|
164
175
|
- lib/realize/filter/by_key_record_value.rb
|
@@ -200,9 +211,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
211
|
version: '2.5'
|
201
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
213
|
requirements:
|
203
|
-
- - "
|
214
|
+
- - ">="
|
204
215
|
- !ruby/object:Gem::Version
|
205
|
-
version:
|
216
|
+
version: '0'
|
206
217
|
requirements: []
|
207
218
|
rubygems_version: 3.0.3
|
208
219
|
signing_key:
|