realize 1.1.1.pre.alpha → 1.4.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +24 -1
  4. data/README.md +12 -1
  5. data/lib/realize.rb +2 -0
  6. data/lib/realize/arrays.rb +7 -0
  7. data/lib/realize/collection/at_index.rb +7 -0
  8. data/lib/realize/collection/first.rb +7 -0
  9. data/lib/realize/collection/last.rb +7 -0
  10. data/lib/realize/collection/sort.rb +7 -0
  11. data/lib/realize/collection/sort/direction.rb +7 -0
  12. data/lib/realize/filter/by_key_record_value.rb +7 -0
  13. data/lib/realize/filter/by_key_value.rb +7 -0
  14. data/lib/realize/filter/by_key_value_presence.rb +7 -0
  15. data/lib/realize/filter/inactive.rb +7 -0
  16. data/lib/realize/format/date.rb +7 -0
  17. data/lib/realize/format/lowercase.rb +21 -0
  18. data/lib/realize/format/remove_whitespace.rb +7 -0
  19. data/lib/realize/format/string_replace.rb +7 -0
  20. data/lib/realize/format/string_template.rb +45 -0
  21. data/lib/realize/format/substring.rb +51 -0
  22. data/lib/realize/format/uppercase.rb +21 -0
  23. data/lib/realize/logical/switch.rb +8 -1
  24. data/lib/realize/logical/switch/case.rb +7 -0
  25. data/lib/realize/pipeline.rb +7 -0
  26. data/lib/realize/transformers.rb +34 -2
  27. data/lib/realize/type/base.rb +25 -0
  28. data/lib/realize/type/boolean.rb +39 -0
  29. data/lib/realize/type/string.rb +23 -0
  30. data/lib/realize/value/blank.rb +7 -0
  31. data/lib/realize/value/map.rb +7 -0
  32. data/lib/realize/value/now.rb +31 -0
  33. data/lib/realize/value/null.rb +7 -0
  34. data/lib/realize/value/resolve.rb +7 -0
  35. data/lib/realize/value/static.rb +7 -0
  36. data/lib/realize/value/uuid.rb +21 -0
  37. data/lib/realize/value/verbatim.rb +7 -0
  38. data/lib/realize/version.rb +1 -1
  39. data/realize.gemspec +2 -1
  40. metadata +29 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d584e2249098a82c2719e6feb8410a4e21dada80f9ca42978ef316843fb78a5
4
- data.tar.gz: e5537b12e40b3a65a14aef391e864a13e565ef9040986a0a05b2b19f4ea7851a
3
+ metadata.gz: 65013db138b786888e85a76bb1532122e0faf8ef4d2eff4e5e287231cda4e999
4
+ data.tar.gz: dc4117f7fc4d2c2b39767e24006c6811ca4065621e984554aaa0004a5bf4a9e9
5
5
  SHA512:
6
- metadata.gz: 35d3820ea8b76292d3fc52e80c9e6e20f7fc89909c8df4b3910838f0aa1b986391b295d2feb3e161eac4a1816838e6d20c3baef4f26e2dc5456c6434a57f2068
7
- data.tar.gz: 14ac8614d30bbeef7f5adefb5eeffd773997576e640ac9f22c323e5813ebb052d292bff25da8dd2eef8ffabca1bc388af9bda996336ba65667672f03bfdf84e2
6
+ metadata.gz: c5a90f318c8958386a920fe5643ce5e9851bc5e513c6e31634b3a06abe3e8c00b6e0b4990fca235f5ec8c608743f576ac7a27810499d3454dddd01629f405408
7
+ data.tar.gz: 3d58041bd36ce2ec71254cf17c0b98c883e213e0d3679b8b915b3f0d633f83f9818eeaea53e7395a5104017ad183e220bc8ccf2ed647f60d45c384002a105951
@@ -17,6 +17,7 @@ Metrics/MethodLength:
17
17
 
18
18
  AllCops:
19
19
  TargetRubyVersion: 2.5
20
+ NewCops: enable
20
21
 
21
22
  Metrics/AbcSize:
22
23
  Max: 16
@@ -1,4 +1,27 @@
1
- # 1.1.1 (TBD)
1
+ # 1.4.0 (November 16th, 2020)
2
+
3
+ New Transformers:
4
+
5
+ * r/format/lowercase
6
+ * r/format/uppercase
7
+
8
+ # 1.3.0 (November 4th, 2020)
9
+
10
+ New Transformers:
11
+
12
+ * r/format/string_template
13
+ * r/format/substring
14
+
15
+ # 1.2.0 (October 6th, 2020)
16
+
17
+ New Transformers:
18
+
19
+ * r/type/boolean
20
+ * r/type/string
21
+ * r/value/now
22
+ * r/value/uuid
23
+
24
+ # 1.1.1 (September 9th, 2020)
2
25
 
3
26
  Fixes:
4
27
 
data/README.md CHANGED
@@ -13,7 +13,7 @@ It is currently used in production at Blue Marble to power the transformation pi
13
13
  To install through Rubygems:
14
14
 
15
15
  ````
16
- gem install install realize
16
+ gem install realize
17
17
  ````
18
18
 
19
19
  You can also add this to your Gemfile:
@@ -77,20 +77,31 @@ Here is a list of each built-in transformer, their options, and what their funct
77
77
  #### Format-oriented Transformers
78
78
 
79
79
  * **r/format/date** [input_format, output_format]: Parses the incoming value into a Time object using the configured input_format and outputs it as formatted by the configured output_format.
80
+ * **r/format/lowercase** []: Calls `#to_s.downcase` on the value so the returned value is guaranteed to be a lower-cased string.
80
81
  * **r/format/remove_whitespace** []: Removes all whitespace from the incoming value.
81
82
  * **r/format/string_replace** [original, replacement]: Replaces all occurrences of the configured original value with the replacement value.
83
+ * **r/format/string_template** [expression, separator, use_record]: String interpolate an expression using either the record or passed in value. Nested objects can be handled (i.e. key paths like dot-notation) by passing in a separator.
84
+ * **r/format/substring** [start_index, end_index, exclusive]: Cut a string in a given range. All options are optional. If a start_index is not provided, the beginning of the string is used. If no end_index is specified then the end of the string is used. If exclusive is set to true then the last index position will not be included. For example: "hellofriend" with a start_index of 0, an end_index of 5, and exclusive as true would yield: "hello". If exclusive was false then it would yield "hellof"
85
+ * **r/format/uppercase** []: Calls `#to_s.upcase` on the value so the returned value is guaranteed to be an upper-cased string type.
82
86
 
83
87
  #### Logical Transformers
84
88
 
85
89
  * **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
90
 
91
+ #### Type Transformers
92
+
93
+ * **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).
94
+ * **r/type/string** [nullable]: Calls `#to_s` on the value so the returned value is guaranteed to be a string type.
95
+
87
96
  #### Value-oriented Transformers
88
97
 
89
98
  * **r/value/blank** []: Always return a blank string.
90
99
  * **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.
100
+ * **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
101
  * **r/value/null** []: Always returns null.
92
102
  * **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
103
  * **r/value/static** [value]: Always returns a hard-coded value.
104
+ * **r/value/uuid** []: Returns a new 36 character UUID (i.e. 6967fec6-bbde-4497-82d9-55ccc7b87cd0)
94
105
  * **r/value/verbatim** []: Default transformer, simply echos back the input.
95
106
 
96
107
  ### Plugging in Transformers
@@ -9,6 +9,8 @@
9
9
 
10
10
  require 'acts_as_hashable'
11
11
  require 'objectable'
12
+ require 'securerandom'
13
+ require 'stringento'
12
14
  require 'time'
13
15
 
14
16
  require_relative 'realize/arrays'
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  # Mix-in that adds some nice common array helpers.
5
12
  module Arrays
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Collection
5
12
  # Transformer to get an item of a collection
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Collection
5
12
  # Transformer to get the first item of a collection
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Collection
5
12
  # Transformer to get the last item of a collection
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  require_relative 'sort/direction'
4
11
 
5
12
  module Realize
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Collection
5
12
  class Sort
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Filter
5
12
  # This transformer can take an array or a hash (put in array) and it understands how to
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Filter
5
12
  # This transformer can take an array or a hash (put in array) and it understands how to
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Filter
5
12
  # This transformer can take an object (will be converted to array) or array and
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Filter
5
12
  # This transformer can take in an array or hash (put in an array) and filters out
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Format
5
12
  # Formats a date/time value. If the input is nil, it will output nil. If an input_format
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Realize
11
+ class Format
12
+ # Call #to_s.downcase on the value and return result.
13
+ class Lowercase
14
+ acts_as_hashable
15
+
16
+ def transform(_resolver, value, _time, _record)
17
+ value.to_s.downcase
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Format
5
12
  # This transformer takes in a value and replaces any whitespace characters (\t\r\n\f\v)
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Format
5
12
  # This transformer takes in a value and replaces all occurrences of the given
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Realize
11
+ class Format
12
+ # Use an expression as a template and string interpolate it using the Stringento library.
13
+ # Stringento also uses Objectable to provide (optional) key-path notation for handling
14
+ # nested objects.
15
+ # For more information see underlying libraries:
16
+ # * Stringento: https://github.com/bluemarblepayroll/stringento
17
+ # * Objectable: https://github.com/bluemarblepayroll/objectable
18
+ class StringTemplate
19
+ acts_as_hashable
20
+
21
+ DEFAULT_SEPARATOR = '.'
22
+
23
+ attr_reader :expression, :resolver, :use_record
24
+
25
+ def initialize(expression: '', separator: DEFAULT_SEPARATOR, use_record: false)
26
+ @expression = expression.to_s
27
+ @resolver = Objectable.resolver(separator: separator)
28
+ @use_record = use_record || false
29
+
30
+ freeze
31
+ end
32
+
33
+ def transform(_resolver, value, _time, record)
34
+ input = use_record ? record : value
35
+
36
+ Stringento.evaluate(expression, input, resolver: self)
37
+ end
38
+
39
+ # For Stringento consumption
40
+ def resolve(value, input)
41
+ resolver.get(input, value)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Realize
11
+ class Format
12
+ # Cut a string using a range (start and end index). You can also choose whether you wish the
13
+ # range selection to be inclusive (default) or exclusive.
14
+ #
15
+ # Examples using the string: '012-345-6789'
16
+ #
17
+ # Exclusive vs. Inclusive
18
+ #
19
+ # [start_index: 4, end_index: 6, exclusive: false] => '345'
20
+ # [start_index: 4, end_index: 6, exclusive: true] => '34'
21
+ #
22
+ # Default Values / Omitted Options
23
+ #
24
+ # [end_index: 6] => '012-345'
25
+ # [start_index: 4] => '345-6789'
26
+ class Substring
27
+ acts_as_hashable
28
+
29
+ DEFAULT_END_INDEX = -1
30
+ DEFAULT_START_INDEX = 0
31
+
32
+ attr_reader :end_index, :exclusive, :start_index
33
+
34
+ def initialize(
35
+ end_index: DEFAULT_END_INDEX,
36
+ exclusive: false,
37
+ start_index: DEFAULT_START_INDEX
38
+ )
39
+ @end_index = end_index.to_i
40
+ @exclusive = exclusive || false
41
+ @start_index = start_index.to_i
42
+
43
+ freeze
44
+ end
45
+
46
+ def transform(_resolver, value, _time, _record)
47
+ exclusive ? value.to_s[start_index...end_index] : value.to_s[start_index..end_index]
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Realize
11
+ class Format
12
+ # Call #to_s.downcase on the value and return result.
13
+ class Uppercase
14
+ acts_as_hashable
15
+
16
+ def transform(_resolver, value, _time, _record)
17
+ value.to_s.upcase
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  require_relative 'switch/case'
4
11
 
5
12
  module Realize
@@ -14,7 +21,7 @@ module Realize
14
21
 
15
22
  attr_reader :cases, :default_transformers, :key
16
23
 
17
- def initialize(cases: [], default_transformers: [], key:)
24
+ def initialize(key:, cases: [], default_transformers: [])
18
25
  raise ArgumentError, 'key is required' if key.to_s.empty?
19
26
 
20
27
  @cases = Case.array(cases)
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Logical
5
12
  class Switch
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  # Main runner that encapsulates a collection of transformers and knows how to kick off the
5
12
  # transformation process.
@@ -1,22 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  require_relative 'collection/at_index'
4
11
  require_relative 'collection/first'
5
12
  require_relative 'collection/last'
6
13
  require_relative 'collection/sort'
14
+
7
15
  require_relative 'filter/by_key_record_value'
8
16
  require_relative 'filter/by_key_value'
9
17
  require_relative 'filter/by_key_value_presence'
10
18
  require_relative 'filter/inactive'
19
+
11
20
  require_relative 'format/date'
21
+ require_relative 'format/lowercase'
12
22
  require_relative 'format/remove_whitespace'
13
23
  require_relative 'format/string_replace'
24
+ require_relative 'format/string_template'
25
+ require_relative 'format/substring'
26
+ require_relative 'format/uppercase'
27
+
14
28
  require_relative 'logical/switch'
29
+
30
+ require_relative 'type/boolean'
31
+ require_relative 'type/string'
32
+
15
33
  require_relative 'value/blank'
16
34
  require_relative 'value/map'
35
+ require_relative 'value/now'
17
36
  require_relative 'value/null'
18
37
  require_relative 'value/resolve'
19
38
  require_relative 'value/static'
39
+ require_relative 'value/uuid'
20
40
  require_relative 'value/verbatim'
21
41
 
22
42
  module Realize
@@ -27,24 +47,36 @@ module Realize
27
47
  class Transformers
28
48
  acts_as_hashable_factory
29
49
 
30
- register '', Value::Verbatim
31
50
  register 'r/collection/at_index', Collection::AtIndex
32
51
  register 'r/collection/first', Collection::First
33
52
  register 'r/collection/last', Collection::Last
34
53
  register 'r/collection/sort', Collection::Sort
54
+
35
55
  register 'r/filter/by_key_record_value', Filter::ByKeyRecordValue
36
56
  register 'r/filter/by_key_value', Filter::ByKeyValue
37
57
  register 'r/filter/by_key_value_presence', Filter::ByKeyValuePresence
38
58
  register 'r/filter/inactive', Filter::Inactive
59
+
39
60
  register 'r/format/date', Format::Date
61
+ register 'r/format/lowercase', Format::Lowercase
40
62
  register 'r/format/remove_whitespace', Format::RemoveWhitespace
41
63
  register 'r/format/string_replace', Format::StringReplace
64
+ register 'r/format/string_template', Format::StringTemplate
65
+ register 'r/format/substring', Format::Substring
66
+ register 'r/format/uppercase', Format::Uppercase
67
+
42
68
  register 'r/logical/switch', Logical::Switch
69
+
70
+ register 'r/type/boolean', Type::Boolean
71
+ register 'r/type/string', Type::String
72
+
43
73
  register 'r/value/blank', Value::Blank
44
74
  register 'r/value/map', Value::Map
75
+ register 'r/value/now', Value::Now
45
76
  register 'r/value/null', Value::Null
46
77
  register 'r/value/resolve', Value::Resolve
47
78
  register 'r/value/static', Value::Static
48
- register 'r/value/verbatim', Value::Verbatim
79
+ register 'r/value/uuid', Value::Uuid
80
+ register 'r/value/verbatim', '', Value::Verbatim
49
81
  end
50
82
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Realize
11
+ class Type
12
+ # Common code for all Type Transformer subclasses.
13
+ class Base
14
+ acts_as_hashable
15
+
16
+ attr_reader :nullable
17
+
18
+ def initialize(nullable: false)
19
+ @nullable = nullable || false
20
+
21
+ freeze
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'base'
11
+
12
+ module Realize
13
+ class Type
14
+ # Convert input into either true, false, or nil.
15
+ # By default nils will return false unless nullable: true is passed in.
16
+ # This transformer is very liberal in its parsing and will return true for:
17
+ # true, 'true', 't', 'TRUE', 'True', 1, '1', 'Y', 'yes', 'Yes', 'YES'
18
+ # All other non-truthy values will evaluate to false, such as:
19
+ # false, 'false', 'f', 'FALSE', 'False', 0, '0', 'N', 'no', 'No', 'NO', {}, [], '',
20
+ # 'abc', 123, :abc, etc...
21
+ class Boolean < Base
22
+ def transform(_resolver, value, _time, _record)
23
+ if nullable && value.nil?
24
+ nil
25
+ elsif truthy?(value)
26
+ true
27
+ else
28
+ false
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def truthy?(value)
35
+ value.to_s.match?(/(true|t|yes|y|1)$/i)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'base'
11
+
12
+ module Realize
13
+ class Type
14
+ # Call #to_s on the value and return result.
15
+ class String < Base
16
+ def transform(_resolver, value, _time, _record)
17
+ return nil if nullable && value.nil?
18
+
19
+ value.to_s
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Value
5
12
  # Always returns blank string
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Value
5
12
  # This transformer can take in a hash of: "value" -> "new value". It's basically a
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Realize
11
+ class Value
12
+ # Return a current Time object.
13
+ class Now
14
+ acts_as_hashable
15
+
16
+ DEFAULT_UTC_OFFSET = '+00:00'
17
+
18
+ attr_reader :utc_offset
19
+
20
+ def initialize(utc_offset: DEFAULT_UTC_OFFSET)
21
+ @utc_offset = utc_offset || DEFAULT_UTC_OFFSET
22
+
23
+ freeze
24
+ end
25
+
26
+ def transform(_resolver, _value, _time, _record)
27
+ Time.now.utc.localtime(utc_offset)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Value
5
12
  # Transformer that always returns nil
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Value
5
12
  # Basic transformer that can take an object and extract a value based off the transformer's
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Value
5
12
  # Transformer that always returns a static value
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Realize
11
+ class Value
12
+ # Return a current Time object.
13
+ class Uuid
14
+ acts_as_hashable
15
+
16
+ def transform(_resolver, _value, _time, _record)
17
+ SecureRandom.uuid
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
3
10
  module Realize
4
11
  class Value
5
12
  # Default transformer that does nothing.
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Realize
11
- VERSION = '1.1.1-alpha'
11
+ VERSION = '1.4.0'
12
12
  end
@@ -30,12 +30,13 @@ Gem::Specification.new do |s|
30
30
 
31
31
  s.add_dependency('acts_as_hashable', '~>1', '>=1.2.0')
32
32
  s.add_dependency('objectable', '~>1')
33
+ s.add_dependency('stringento', '~>2.1')
33
34
 
34
35
  s.add_development_dependency('guard-rspec', '~>4.7')
35
36
  s.add_development_dependency('pry', '~>0')
36
37
  s.add_development_dependency('rake', '~> 13')
37
38
  s.add_development_dependency('rspec')
38
- s.add_development_dependency('rubocop', '~>0.79.0')
39
+ s.add_development_dependency('rubocop', '~>1.1')
39
40
  s.add_development_dependency('simplecov', '~>0.17.0')
40
41
  s.add_development_dependency('simplecov-console', '~>0.6.0')
41
42
  end
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.1.1.pre.alpha
4
+ version: 1.4.0
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-09-09 00:00:00.000000000 Z
12
+ date: 2020-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: acts_as_hashable
@@ -45,6 +45,20 @@ dependencies:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1'
48
+ - !ruby/object:Gem::Dependency
49
+ name: stringento
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: guard-rspec
50
64
  requirement: !ruby/object:Gem::Requirement
@@ -107,14 +121,14 @@ dependencies:
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 0.79.0
124
+ version: '1.1'
111
125
  type: :development
112
126
  prerelease: false
113
127
  version_requirements: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: 0.79.0
131
+ version: '1.1'
118
132
  - !ruby/object:Gem::Dependency
119
133
  name: simplecov
120
134
  requirement: !ruby/object:Gem::Requirement
@@ -177,17 +191,26 @@ files:
177
191
  - lib/realize/filter/by_key_value_presence.rb
178
192
  - lib/realize/filter/inactive.rb
179
193
  - lib/realize/format/date.rb
194
+ - lib/realize/format/lowercase.rb
180
195
  - lib/realize/format/remove_whitespace.rb
181
196
  - lib/realize/format/string_replace.rb
197
+ - lib/realize/format/string_template.rb
198
+ - lib/realize/format/substring.rb
199
+ - lib/realize/format/uppercase.rb
182
200
  - lib/realize/logical/switch.rb
183
201
  - lib/realize/logical/switch/case.rb
184
202
  - lib/realize/pipeline.rb
185
203
  - lib/realize/transformers.rb
204
+ - lib/realize/type/base.rb
205
+ - lib/realize/type/boolean.rb
206
+ - lib/realize/type/string.rb
186
207
  - lib/realize/value/blank.rb
187
208
  - lib/realize/value/map.rb
209
+ - lib/realize/value/now.rb
188
210
  - lib/realize/value/null.rb
189
211
  - lib/realize/value/resolve.rb
190
212
  - lib/realize/value/static.rb
213
+ - lib/realize/value/uuid.rb
191
214
  - lib/realize/value/verbatim.rb
192
215
  - lib/realize/version.rb
193
216
  - realize.gemspec
@@ -211,9 +234,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
234
  version: '2.5'
212
235
  required_rubygems_version: !ruby/object:Gem::Requirement
213
236
  requirements:
214
- - - ">"
237
+ - - ">="
215
238
  - !ruby/object:Gem::Version
216
- version: 1.3.1
239
+ version: '0'
217
240
  requirements: []
218
241
  rubygems_version: 3.0.3
219
242
  signing_key: