hashcraft 1.0.0.pre.alpha.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -3
- data/CHANGELOG.md +1 -1
- data/README.md +1 -1
- data/hashcraft.gemspec +2 -2
- data/lib/hashcraft/base.rb +5 -8
- data/lib/hashcraft/dsl.rb +6 -7
- data/lib/hashcraft/mutators.rb +45 -0
- data/lib/hashcraft/option.rb +4 -4
- data/lib/hashcraft/transformers.rb +40 -0
- data/lib/hashcraft/version.rb +1 -1
- metadata +10 -19
- data/lib/hashcraft/mutator_registry.rb +0 -32
- data/lib/hashcraft/mutators/always_false.rb +0 -21
- data/lib/hashcraft/mutators/always_true.rb +0 -21
- data/lib/hashcraft/mutators/array.rb +0 -26
- data/lib/hashcraft/mutators/flat_array.rb +0 -30
- data/lib/hashcraft/mutators/hash.rb +0 -25
- data/lib/hashcraft/mutators/property.rb +0 -22
- data/lib/hashcraft/transformer_registry.rb +0 -26
- data/lib/hashcraft/transformers/camel_case.rb +0 -27
- data/lib/hashcraft/transformers/pascal_case.rb +0 -25
- data/lib/hashcraft/transformers/pass_thru.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38c94cd212c01aa72103257b3d053e3dd9beeb190641fcb82df4ac1896db27ba
|
4
|
+
data.tar.gz: 21de2c24f3a98e759b68e4783b29d9c8e11f45cc3e71b71bd779e0319ba52986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ab0f421744e572638f75ccf04508471f7df8131f105b8e55ae806b90255340f8b45193f72c94dfb84ee1b6037e836e8d29050c8963417d41484c2f83efe97b5
|
7
|
+
data.tar.gz: 3c2e2f61c4eeea3af9fdc95d493461bd727e9b49134c60a8577b5a7c149ae3a4da1796c05f3db6257afed23b2abd29bf1ef146359dc3d5726185ec73b7c6a221
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
NewCops: enable
|
4
|
+
|
1
5
|
Layout/LineLength:
|
2
6
|
Max: 100
|
3
7
|
Exclude:
|
@@ -15,9 +19,6 @@ Metrics/BlockLength:
|
|
15
19
|
Metrics/MethodLength:
|
16
20
|
Max: 30
|
17
21
|
|
18
|
-
AllCops:
|
19
|
-
TargetRubyVersion: 2.5
|
20
|
-
|
21
22
|
Metrics/AbcSize:
|
22
23
|
Max: 16
|
23
24
|
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -276,7 +276,7 @@ config = Grid.new do
|
|
276
276
|
end.to_h
|
277
277
|
````
|
278
278
|
|
279
|
-
Assuming our en.yml looks like the above example and our locale is set to:en then the resulting `config` value will now be:
|
279
|
+
Assuming our en.yml looks like the above example and our locale is set to :en then the resulting `config` value will now be:
|
280
280
|
|
281
281
|
````ruby
|
282
282
|
{
|
data/hashcraft.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_development_dependency('pry', '~>0')
|
33
33
|
s.add_development_dependency('rake', '~> 13')
|
34
34
|
s.add_development_dependency('rspec')
|
35
|
-
s.add_development_dependency('rubocop', '~>0.
|
36
|
-
s.add_development_dependency('simplecov', '~>0.
|
35
|
+
s.add_development_dependency('rubocop', '~>0.88.0')
|
36
|
+
s.add_development_dependency('simplecov', '~>0.18.5')
|
37
37
|
s.add_development_dependency('simplecov-console', '~>0.6.0')
|
38
38
|
end
|
data/lib/hashcraft/base.rb
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
#
|
9
9
|
|
10
10
|
require_relative 'dsl'
|
11
|
+
require_relative 'transformers'
|
11
12
|
|
12
13
|
module Hashcraft
|
13
14
|
# Super-class for craftable objects.
|
@@ -59,11 +60,7 @@ module Hashcraft
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def evaluate_values!(data, key, values)
|
62
|
-
data[key]
|
63
|
-
|
64
|
-
values.each do |value|
|
65
|
-
data[key] << (value.is_a?(Hashcraft::Base) ? value.to_h : value)
|
66
|
-
end
|
63
|
+
data[key] = values.map { |value| value.is_a?(Hashcraft::Base) ? value.to_h : value }
|
67
64
|
|
68
65
|
self
|
69
66
|
end
|
@@ -78,7 +75,7 @@ module Hashcraft
|
|
78
75
|
return self unless option.eager?
|
79
76
|
|
80
77
|
key = hash_key(option)
|
81
|
-
value =
|
78
|
+
value = Transformers.instance.transform(value_transformer_to_use, option.default.dup, option)
|
82
79
|
|
83
80
|
data[key] = value
|
84
81
|
|
@@ -88,7 +85,7 @@ module Hashcraft
|
|
88
85
|
def value!(option, value, &block)
|
89
86
|
key = hash_key(option)
|
90
87
|
value = option.craft_value(value, &block)
|
91
|
-
value =
|
88
|
+
value = Transformers.instance.transform(value_transformer_to_use, value, option)
|
92
89
|
|
93
90
|
option.value!(data, key, value)
|
94
91
|
|
@@ -96,7 +93,7 @@ module Hashcraft
|
|
96
93
|
end
|
97
94
|
|
98
95
|
def hash_key(option)
|
99
|
-
|
96
|
+
Transformers.instance.transform(key_transformer_to_use, option.hash_key, option)
|
100
97
|
end
|
101
98
|
end
|
102
99
|
end
|
data/lib/hashcraft/dsl.rb
CHANGED
@@ -8,7 +8,6 @@
|
|
8
8
|
#
|
9
9
|
|
10
10
|
require_relative 'option'
|
11
|
-
require_relative 'transformer_registry'
|
12
11
|
|
13
12
|
module Hashcraft
|
14
13
|
# The class API used to define options for a craftable class. Each class stores its own
|
@@ -22,32 +21,32 @@ module Hashcraft
|
|
22
21
|
# It will follow the typical inheritance chain and find the closest
|
23
22
|
# transformer to use (child-first).
|
24
23
|
def key_transformer(name)
|
25
|
-
tap { @local_key_transformer =
|
24
|
+
tap { @local_key_transformer = name }
|
26
25
|
end
|
27
26
|
|
28
27
|
# DSL Method used to declare what the sub-class should use as a transformer for all values.
|
29
28
|
# It will follow the typical inheritance chain and find the closest
|
30
29
|
# transformer to use (child-first).
|
31
30
|
def value_transformer(name)
|
32
|
-
tap { @local_value_transformer =
|
31
|
+
tap { @local_value_transformer = name }
|
33
32
|
end
|
34
33
|
|
35
34
|
def key_transformer_to_use # :nodoc:
|
36
35
|
return @key_transformer_to_use if @key_transformer_to_use
|
37
36
|
|
38
|
-
@
|
37
|
+
@key_transformer_to_use =
|
39
38
|
ancestors.select { |a| a < Base }
|
40
39
|
.find(&:local_key_transformer)
|
41
|
-
&.local_key_transformer
|
40
|
+
&.local_key_transformer
|
42
41
|
end
|
43
42
|
|
44
43
|
def value_transformer_to_use # :nodoc:
|
45
44
|
return @value_transformer_to_use if @value_transformer_to_use
|
46
45
|
|
47
|
-
@
|
46
|
+
@value_transformer_to_use =
|
48
47
|
ancestors.select { |a| a < Base }
|
49
48
|
.find(&:local_value_transformer)
|
50
|
-
&.local_value_transformer
|
49
|
+
&.local_value_transformer
|
51
50
|
end
|
52
51
|
|
53
52
|
def find_option(name) # :nodoc:
|
@@ -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 Hashcraft
|
11
|
+
# Singleton that knows how to register and retrieve mutator instances.
|
12
|
+
# Entries can either be instances that respond to value! or procs that accept three arguments.
|
13
|
+
class Mutators < Generic::Registry # :nodoc:
|
14
|
+
FUNCTIONS = {
|
15
|
+
always_false: ->(data, key, _value) { data[key] = false },
|
16
|
+
always_true: ->(data, key, _value) { data[key] = true },
|
17
|
+
array: ->(data, key, value) { (data[key] ||= []) << value },
|
18
|
+
flat_array: lambda do |data, key, value|
|
19
|
+
data[key] ||= []
|
20
|
+
|
21
|
+
if value.is_a?(::Array)
|
22
|
+
data[key] += value
|
23
|
+
else
|
24
|
+
data[key] << value
|
25
|
+
end
|
26
|
+
end,
|
27
|
+
hash: ->(data, key, value) { (data[key] ||= {}).merge!(value || {}) },
|
28
|
+
property: ->(data, key, value) { data[key] = value },
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
private_constant :FUNCTIONS
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
# append on the default case
|
35
|
+
super(FUNCTIONS.merge('': FUNCTIONS[:property]))
|
36
|
+
end
|
37
|
+
|
38
|
+
def value!(name, data, key, value)
|
39
|
+
object = resolve(name)
|
40
|
+
method = object.is_a?(Proc) ? :call : :value!
|
41
|
+
|
42
|
+
object.send(method, data, key, value)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/hashcraft/option.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# LICENSE file in the root directory of this source tree.
|
8
8
|
#
|
9
9
|
|
10
|
-
require_relative '
|
10
|
+
require_relative 'mutators'
|
11
11
|
|
12
12
|
module Hashcraft
|
13
13
|
# Defines a method and corresponding attribute for a craftable class.
|
@@ -29,14 +29,14 @@ module Hashcraft
|
|
29
29
|
@eager = opts[:eager] || false
|
30
30
|
@internal_meta = symbolize_keys(opts[:meta] || {})
|
31
31
|
@key = opts[:key].to_s
|
32
|
-
@mutator =
|
32
|
+
@mutator = opts[:mutator]
|
33
33
|
@name = name.to_s
|
34
34
|
|
35
35
|
freeze
|
36
36
|
end
|
37
37
|
|
38
38
|
def value!(data, key, value) # :nodoc:
|
39
|
-
|
39
|
+
Mutators.instance.value!(mutator, data, key, value)
|
40
40
|
end
|
41
41
|
|
42
42
|
# Options are sent into transformers as arguments. Leverage the meta key for an option
|
@@ -59,7 +59,7 @@ module Hashcraft
|
|
59
59
|
attr_reader :internal_meta
|
60
60
|
|
61
61
|
def symbolize_keys(hash)
|
62
|
-
hash.
|
62
|
+
hash.transform_keys(&:to_sym)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -0,0 +1,40 @@
|
|
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 Hashcraft
|
11
|
+
# Singleton that knows how to register and retrieve transformer instances.
|
12
|
+
# Entries can either be instances that respond to transform or procs that accept two arguments.
|
13
|
+
class Transformers < Generic::Registry # :nodoc:
|
14
|
+
FUNCTIONS = {
|
15
|
+
camel_case: lambda do |value, _option|
|
16
|
+
return value.to_s if value.to_s.empty?
|
17
|
+
|
18
|
+
name = value.to_s.split('_').collect(&:capitalize).join
|
19
|
+
|
20
|
+
name[0, 1].downcase + name[1..-1]
|
21
|
+
end,
|
22
|
+
pascal_case: ->(value, _option) { value.to_s.split('_').collect(&:capitalize).join },
|
23
|
+
pass_thru: ->(value, _option) { value }
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
private_constant :FUNCTIONS
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
# append on the default case
|
30
|
+
super(FUNCTIONS.merge('': FUNCTIONS[:pass_thru]))
|
31
|
+
end
|
32
|
+
|
33
|
+
def transform(name, value, option)
|
34
|
+
object = resolve(name)
|
35
|
+
method = object.is_a?(Proc) ? :call : :transform
|
36
|
+
|
37
|
+
object.send(method, value, option)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/hashcraft/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashcraft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard-rspec
|
@@ -72,28 +72,28 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.88.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.88.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.18.5
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.18.5
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov-console
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,18 +136,9 @@ files:
|
|
136
136
|
- lib/hashcraft/generic.rb
|
137
137
|
- lib/hashcraft/generic/dictionary.rb
|
138
138
|
- lib/hashcraft/generic/registry.rb
|
139
|
-
- lib/hashcraft/
|
140
|
-
- lib/hashcraft/mutators/always_false.rb
|
141
|
-
- lib/hashcraft/mutators/always_true.rb
|
142
|
-
- lib/hashcraft/mutators/array.rb
|
143
|
-
- lib/hashcraft/mutators/flat_array.rb
|
144
|
-
- lib/hashcraft/mutators/hash.rb
|
145
|
-
- lib/hashcraft/mutators/property.rb
|
139
|
+
- lib/hashcraft/mutators.rb
|
146
140
|
- lib/hashcraft/option.rb
|
147
|
-
- lib/hashcraft/
|
148
|
-
- lib/hashcraft/transformers/camel_case.rb
|
149
|
-
- lib/hashcraft/transformers/pascal_case.rb
|
150
|
-
- lib/hashcraft/transformers/pass_thru.rb
|
141
|
+
- lib/hashcraft/transformers.rb
|
151
142
|
- lib/hashcraft/version.rb
|
152
143
|
homepage: https://github.com/bluemarblepayroll/hashcraft
|
153
144
|
licenses:
|
@@ -169,9 +160,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
160
|
version: '2.5'
|
170
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
162
|
requirements:
|
172
|
-
- - "
|
163
|
+
- - ">="
|
173
164
|
- !ruby/object:Gem::Version
|
174
|
-
version:
|
165
|
+
version: '0'
|
175
166
|
requirements: []
|
176
167
|
rubygems_version: 3.0.3
|
177
168
|
signing_key:
|
@@ -1,32 +0,0 @@
|
|
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 'mutators/always_false'
|
11
|
-
require_relative 'mutators/always_true'
|
12
|
-
require_relative 'mutators/array'
|
13
|
-
require_relative 'mutators/flat_array'
|
14
|
-
require_relative 'mutators/hash'
|
15
|
-
require_relative 'mutators/property'
|
16
|
-
|
17
|
-
module Hashcraft
|
18
|
-
# Singleton that knows how to register and retrieve mutator instances.
|
19
|
-
class MutatorRegistry < Generic::Registry # :nodoc:
|
20
|
-
def initialize
|
21
|
-
super(
|
22
|
-
'' => Mutators::Property.instance,
|
23
|
-
'always_false' => Mutators::AlwaysFalse.instance,
|
24
|
-
'always_true' => Mutators::AlwaysTrue.instance,
|
25
|
-
'array' => Mutators::Array.instance,
|
26
|
-
'flat_array' => Mutators::FlatArray.instance,
|
27
|
-
'hash' => Mutators::Hash.instance,
|
28
|
-
'property' => Mutators::Property.instance
|
29
|
-
)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Mutators # :nodoc: all
|
12
|
-
# Set to false, no matter what.
|
13
|
-
class AlwaysFalse
|
14
|
-
include Singleton
|
15
|
-
|
16
|
-
def value!(data, key, _value)
|
17
|
-
tap { data[key] = false }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Mutators # :nodoc: all
|
12
|
-
# Set to true, no matter what.
|
13
|
-
class AlwaysTrue
|
14
|
-
include Singleton
|
15
|
-
|
16
|
-
def value!(data, key, _value)
|
17
|
-
tap { data[key] = true }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,26 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Mutators # :nodoc: all
|
12
|
-
# When a hash's key is an array then this mutator can be used to push a new value on the
|
13
|
-
# respective array.
|
14
|
-
class Array
|
15
|
-
include Singleton
|
16
|
-
|
17
|
-
def value!(data, key, value)
|
18
|
-
data[key] ||= []
|
19
|
-
|
20
|
-
data[key] << value
|
21
|
-
|
22
|
-
self
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,30 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Mutators # :nodoc: all
|
12
|
-
# If the value is an array then concat, if it is not an array then push.
|
13
|
-
class FlatArray
|
14
|
-
include Singleton
|
15
|
-
|
16
|
-
def value!(data, key, value)
|
17
|
-
data[key] ||= []
|
18
|
-
|
19
|
-
# Prefixed Array with double colons to not get confused with our Array mutator class.
|
20
|
-
if value.is_a?(::Array)
|
21
|
-
data[key] += value
|
22
|
-
else
|
23
|
-
data[key] << value
|
24
|
-
end
|
25
|
-
|
26
|
-
self
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,25 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Mutators # :nodoc: all
|
12
|
-
# When a hash's key a Hash then this mutator can be used to merge a new value on the
|
13
|
-
# respective hash.
|
14
|
-
class Hash
|
15
|
-
include Singleton
|
16
|
-
|
17
|
-
def value!(data, key, value)
|
18
|
-
data[key] ||= {}
|
19
|
-
data[key].merge!(value || {})
|
20
|
-
|
21
|
-
self
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,22 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Mutators # :nodoc: all
|
12
|
-
# When a hash key can be simply assigned to (like a property) then this mutator can be used to
|
13
|
-
# simply do the assignment.
|
14
|
-
class Property
|
15
|
-
include Singleton
|
16
|
-
|
17
|
-
def value!(data, key, value)
|
18
|
-
tap { data[key] = value }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,26 +0,0 @@
|
|
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 'transformers/camel_case'
|
11
|
-
require_relative 'transformers/pascal_case'
|
12
|
-
require_relative 'transformers/pass_thru'
|
13
|
-
|
14
|
-
module Hashcraft
|
15
|
-
# Singleton that knows how to register and retrieve transformer instances.
|
16
|
-
class TransformerRegistry < Generic::Registry # :nodoc:
|
17
|
-
def initialize
|
18
|
-
super(
|
19
|
-
'' => Transformers::PassThru.instance,
|
20
|
-
'camel_case' => Transformers::CamelCase.instance,
|
21
|
-
'pascal_case' => Transformers::PascalCase.instance,
|
22
|
-
'pass_thru' => Transformers::PassThru.instance
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,27 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Transformers # :nodoc: all
|
12
|
-
# Transform snake-cased to camel-cased string. Example:
|
13
|
-
# date_of_birth => dateOfBirth
|
14
|
-
# DATE_OF_BIRTH => dateOfBirth
|
15
|
-
class CamelCase
|
16
|
-
include Singleton
|
17
|
-
|
18
|
-
def transform(value, _option)
|
19
|
-
return '' if value.to_s.empty?
|
20
|
-
|
21
|
-
name = value.to_s.split('_').collect(&:capitalize).join
|
22
|
-
|
23
|
-
name[0, 1].downcase + name[1..-1]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,25 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Transformers # :nodoc: all
|
12
|
-
# Transform snake-cased to pascal-cased string. Example:
|
13
|
-
# date_of_birth => DateOfBirth
|
14
|
-
# DATE_OF_BIRTH => DateOfBirth
|
15
|
-
class PascalCase
|
16
|
-
include Singleton
|
17
|
-
|
18
|
-
def transform(value, _option)
|
19
|
-
return '' if value.to_s.empty?
|
20
|
-
|
21
|
-
value.to_s.split('_').collect(&:capitalize).join
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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 Hashcraft
|
11
|
-
module Transformers # :nodoc: all
|
12
|
-
# Default transformer, simply returns the value passed in.
|
13
|
-
class PassThru
|
14
|
-
include Singleton
|
15
|
-
|
16
|
-
def transform(value, _option)
|
17
|
-
value
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|