realize 1.1.1 → 1.2.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +7 -0
- data/lib/realize.rb +1 -0
- data/lib/realize/transformers.rb +19 -2
- data/lib/realize/type/boolean.rb +37 -0
- data/lib/realize/type/string.rb +22 -0
- data/lib/realize/value/now.rb +24 -0
- data/lib/realize/value/uuid.rb +14 -0
- data/lib/realize/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a4e738840e298580fc77dfc5ace2d254b63373929c0b09b24783b3b3c639027
|
4
|
+
data.tar.gz: 64a75dcfb103323c9a5bedaad2ba16c9195e18410e860ca8c6a144329cdb488a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57679313d416e0e331c563ef6b756bda9c77a22338812d435f563bf5cbe399e81ace68e183a4c4e897c4bbe719fd3b942fa2cde5bfeabe1dd536416ad9858a57
|
7
|
+
data.tar.gz: 2e3bddcec287597fa11b600488a088ca6f87ea9de75b985e656632f7d87e68c5fcd1de54eaf16d106ed2fbf2b5d1d00550abd1710df557def1c5ab54d376cf20
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -84,13 +84,20 @@ Here is a list of each built-in transformer, their options, and what their funct
|
|
84
84
|
|
85
85
|
* **r/logical/switch** [cases, default_transformers, key]: Provides a value-based logic branching. If a value matches a specific case, the specific cases transformers will be executed. If it does not match any case then the default_transformers will be executed.
|
86
86
|
|
87
|
+
#### Type Transformers
|
88
|
+
|
89
|
+
* **r/type/boolean** [nullable]: Returns `true` if the input is 'truthy', `false` if not. By default nullable is false, which means a nil input will return false. Changing this to true will return nil if nil is passed in. A 'truthy' value is defined as matching: true, t, yes, y, or 1 (case-insensitive).
|
90
|
+
* **r/type/string** []: Calls `#to_s` on the value so the returned value is guaranteed to be a string type.
|
91
|
+
|
87
92
|
#### Value-oriented Transformers
|
88
93
|
|
89
94
|
* **r/value/blank** []: Always return a blank string.
|
90
95
|
* **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.
|
96
|
+
* **r/value/now** [utc_offset]: Returns a Time object, defaulting to UTC offset. You can optionally pass in a different offset in the FORM: "+/-HH:MM"
|
91
97
|
* **r/value/null** []: Always returns null.
|
92
98
|
* **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
99
|
* **r/value/static** [value]: Always returns a hard-coded value.
|
100
|
+
* **r/value/uuid** []: Returns a new 36 character UUID (i.e. 6967fec6-bbde-4497-82d9-55ccc7b87cd0)
|
94
101
|
* **r/value/verbatim** []: Default transformer, simply echos back the input.
|
95
102
|
|
96
103
|
### Plugging in Transformers
|
data/lib/realize.rb
CHANGED
data/lib/realize/transformers.rb
CHANGED
@@ -4,19 +4,28 @@ require_relative 'collection/at_index'
|
|
4
4
|
require_relative 'collection/first'
|
5
5
|
require_relative 'collection/last'
|
6
6
|
require_relative 'collection/sort'
|
7
|
+
|
7
8
|
require_relative 'filter/by_key_record_value'
|
8
9
|
require_relative 'filter/by_key_value'
|
9
10
|
require_relative 'filter/by_key_value_presence'
|
10
11
|
require_relative 'filter/inactive'
|
12
|
+
|
11
13
|
require_relative 'format/date'
|
12
14
|
require_relative 'format/remove_whitespace'
|
13
15
|
require_relative 'format/string_replace'
|
16
|
+
|
14
17
|
require_relative 'logical/switch'
|
18
|
+
|
19
|
+
require_relative 'type/boolean'
|
20
|
+
require_relative 'type/string'
|
21
|
+
|
15
22
|
require_relative 'value/blank'
|
16
23
|
require_relative 'value/map'
|
24
|
+
require_relative 'value/now'
|
17
25
|
require_relative 'value/null'
|
18
26
|
require_relative 'value/resolve'
|
19
27
|
require_relative 'value/static'
|
28
|
+
require_relative 'value/uuid'
|
20
29
|
require_relative 'value/verbatim'
|
21
30
|
|
22
31
|
module Realize
|
@@ -27,24 +36,32 @@ module Realize
|
|
27
36
|
class Transformers
|
28
37
|
acts_as_hashable_factory
|
29
38
|
|
30
|
-
register '', Value::Verbatim
|
31
39
|
register 'r/collection/at_index', Collection::AtIndex
|
32
40
|
register 'r/collection/first', Collection::First
|
33
41
|
register 'r/collection/last', Collection::Last
|
34
42
|
register 'r/collection/sort', Collection::Sort
|
43
|
+
|
35
44
|
register 'r/filter/by_key_record_value', Filter::ByKeyRecordValue
|
36
45
|
register 'r/filter/by_key_value', Filter::ByKeyValue
|
37
46
|
register 'r/filter/by_key_value_presence', Filter::ByKeyValuePresence
|
38
47
|
register 'r/filter/inactive', Filter::Inactive
|
48
|
+
|
39
49
|
register 'r/format/date', Format::Date
|
40
50
|
register 'r/format/remove_whitespace', Format::RemoveWhitespace
|
41
51
|
register 'r/format/string_replace', Format::StringReplace
|
52
|
+
|
42
53
|
register 'r/logical/switch', Logical::Switch
|
54
|
+
|
55
|
+
register 'r/type/boolean', Type::Boolean
|
56
|
+
register 'r/type/string', Type::String
|
57
|
+
|
43
58
|
register 'r/value/blank', Value::Blank
|
44
59
|
register 'r/value/map', Value::Map
|
60
|
+
register 'r/value/now', Value::Now
|
45
61
|
register 'r/value/null', Value::Null
|
46
62
|
register 'r/value/resolve', Value::Resolve
|
47
63
|
register 'r/value/static', Value::Static
|
48
|
-
register 'r/value/
|
64
|
+
register 'r/value/uuid', Value::Uuid
|
65
|
+
register 'r/value/verbatim', '', Value::Verbatim
|
49
66
|
end
|
50
67
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Realize
|
4
|
+
class Type
|
5
|
+
# Convert input into either true, false, or nil.
|
6
|
+
# By default nils will return false unless nullable: true is passed in.
|
7
|
+
# This transformer is very liberal in its parsing and will return true for:
|
8
|
+
# true, 'true', 't', 'TRUE', 'True', 1, '1', 'Y', 'yes', 'Yes', 'YES'
|
9
|
+
# All over non-truthy values will evaluate to false, such as:
|
10
|
+
# false: false, 'false', 'f', 'FALSE', 'False', 0, '0', 'N', 'no', 'No', 'NO', {}, [], ''
|
11
|
+
class Boolean
|
12
|
+
acts_as_hashable
|
13
|
+
|
14
|
+
attr_reader :nullable
|
15
|
+
|
16
|
+
def initialize(nullable: false)
|
17
|
+
@nullable = nullable || false
|
18
|
+
end
|
19
|
+
|
20
|
+
def transform(_resolver, value, _time, _record)
|
21
|
+
if nullable && value.nil?
|
22
|
+
nil
|
23
|
+
elsif truthy?(value)
|
24
|
+
true
|
25
|
+
else
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def truthy?(value)
|
33
|
+
value.to_s.match?(/(true|t|yes|y|1)$/i)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Realize
|
4
|
+
class Type
|
5
|
+
# Call #to_s on the value and return result.
|
6
|
+
class String
|
7
|
+
acts_as_hashable
|
8
|
+
|
9
|
+
attr_reader :nullable
|
10
|
+
|
11
|
+
def initialize(nullable: false)
|
12
|
+
@nullable = nullable || false
|
13
|
+
end
|
14
|
+
|
15
|
+
def transform(_resolver, value, _time, _record)
|
16
|
+
return nil if nullable && value.nil?
|
17
|
+
|
18
|
+
value.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Realize
|
4
|
+
class Value
|
5
|
+
# Return a current Time object.
|
6
|
+
class Now
|
7
|
+
acts_as_hashable
|
8
|
+
|
9
|
+
DEFAULT_UTC_OFFSET = '+00:00'
|
10
|
+
|
11
|
+
attr_reader :utc_offset
|
12
|
+
|
13
|
+
def initialize(utc_offset: DEFAULT_UTC_OFFSET)
|
14
|
+
@utc_offset = utc_offset || DEFAULT_UTC_OFFSET
|
15
|
+
|
16
|
+
freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
def transform(_resolver, _value, _time, _record)
|
20
|
+
Time.now.utc.localtime(utc_offset)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/realize/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: realize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0.pre.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-10-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: acts_as_hashable
|
@@ -183,11 +183,15 @@ files:
|
|
183
183
|
- lib/realize/logical/switch/case.rb
|
184
184
|
- lib/realize/pipeline.rb
|
185
185
|
- lib/realize/transformers.rb
|
186
|
+
- lib/realize/type/boolean.rb
|
187
|
+
- lib/realize/type/string.rb
|
186
188
|
- lib/realize/value/blank.rb
|
187
189
|
- lib/realize/value/map.rb
|
190
|
+
- lib/realize/value/now.rb
|
188
191
|
- lib/realize/value/null.rb
|
189
192
|
- lib/realize/value/resolve.rb
|
190
193
|
- lib/realize/value/static.rb
|
194
|
+
- lib/realize/value/uuid.rb
|
191
195
|
- lib/realize/value/verbatim.rb
|
192
196
|
- lib/realize/version.rb
|
193
197
|
- realize.gemspec
|
@@ -211,9 +215,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
215
|
version: '2.5'
|
212
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
217
|
requirements:
|
214
|
-
- - "
|
218
|
+
- - ">"
|
215
219
|
- !ruby/object:Gem::Version
|
216
|
-
version:
|
220
|
+
version: 1.3.1
|
217
221
|
requirements: []
|
218
222
|
rubygems_version: 3.0.3
|
219
223
|
signing_key:
|