realize 1.0.0 → 1.1.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 +4 -0
- 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/transformers.rb +6 -0
- data/lib/realize/version.rb +1 -1
- data/realize.gemspec +2 -2
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f1004b6b97c8ebd485bac4fb9859ffd28511240f4a9943c73875664be35722c
|
4
|
+
data.tar.gz: 979d68bb86ecc8ba32251c2346a0183158686bf04fb9949f04646e7e16a6a03b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2398a44d581a5e8685ef9c29acbb140fbc2488cb7ffc6411317254325154e30b72b3828b96df5aa7e17f299a79c802f4ece1a50486c0ec62d20bdcb9bd5f073
|
7
|
+
data.tar.gz: 9b87926382b38afda00be7ab8055ab26eea572228489f0d0efd341dd0b709d11d1becafa3e925d79baa5c30bccd0fab30130c8792e646891c902fc6cb7a23aa9
|
data/CHANGELOG.md
CHANGED
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
|
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 = []
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: realize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
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-06-
|
12
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: acts_as_hashable
|
@@ -145,6 +146,7 @@ dependencies:
|
|
145
146
|
description: " Derive and transform a value using a configuration-first pipeline.\n"
|
146
147
|
email:
|
147
148
|
- mruggio@bluemarblepayroll.com
|
149
|
+
- ddewar@bluemarblepayroll.com
|
148
150
|
executables: []
|
149
151
|
extensions: []
|
150
152
|
extra_rdoc_files: []
|
@@ -165,6 +167,9 @@ files:
|
|
165
167
|
- exe/.gitkeep
|
166
168
|
- lib/realize.rb
|
167
169
|
- lib/realize/arrays.rb
|
170
|
+
- lib/realize/collection/at_index.rb
|
171
|
+
- lib/realize/collection/first.rb
|
172
|
+
- lib/realize/collection/last.rb
|
168
173
|
- lib/realize/collection/sort.rb
|
169
174
|
- lib/realize/collection/sort/direction.rb
|
170
175
|
- lib/realize/filter/by_key_record_value.rb
|