k_builder 0.0.25 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/k_builder.rb +3 -2
- data/lib/k_builder/data_helper.rb +62 -0
- data/lib/k_builder/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec75b1356060e7075bd481790769fb8f3fd80112a07247fb3a5ac1f6bac36993
|
4
|
+
data.tar.gz: 388c3f334b6864e973a4fbfd1f41d6bdbf769c3b58fb5d72a9bafeb847e11656
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6937c692f052d1ec7b0f6abae35cce72e775e65a962e05ca21ba5dda647cb85c3215fb465e86ba76428bffc66038727afde3ca60666920773467bc36996cbef
|
7
|
+
data.tar.gz: 3988883cfe6543a2c97fe56c4b99bf634b4a77c3210eccf2d1e56711d045729144aa0735edd94238c400f9ed82fcf7db847343949e0d04b325fa66f52c0073b6
|
data/lib/k_builder.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'k_builder/version'
|
4
|
-
require 'k_builder/base_configuration'
|
5
|
-
require 'k_builder/configuration'
|
6
4
|
require 'k_builder/base_builder'
|
5
|
+
require 'k_builder/base_configuration'
|
7
6
|
require 'k_builder/builder'
|
7
|
+
require 'k_builder/configuration'
|
8
|
+
require 'k_builder/data_helper'
|
8
9
|
|
9
10
|
require 'handlebars/helpers/template'
|
10
11
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Attach data helper to the KBuilder module
|
4
|
+
module KBuilder
|
5
|
+
# Data helpers/utils for Kbuilder
|
6
|
+
class << self
|
7
|
+
attr_writer :data
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.data
|
11
|
+
@data ||= DataHelper.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Helper methods attached to the namespace for working with Data
|
15
|
+
#
|
16
|
+
# Usage: KBuilder.data.to_struct(data)
|
17
|
+
class DataHelper
|
18
|
+
# Convert a hash into a deep OpenStruct or array an array
|
19
|
+
# of objects into an array of OpenStruct
|
20
|
+
def to_struct(data)
|
21
|
+
case data
|
22
|
+
when Hash
|
23
|
+
OpenStruct.new(data.transform_values { |v| to_struct(v) })
|
24
|
+
|
25
|
+
when Array
|
26
|
+
data.map { |o| to_struct(o) }
|
27
|
+
|
28
|
+
else
|
29
|
+
# Some primitave type: String, True/False, Symbol or an ObjectStruct
|
30
|
+
data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
35
|
+
def struct_to_hash(data)
|
36
|
+
# No test yet
|
37
|
+
if data.is_a?(Array)
|
38
|
+
return data.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
39
|
+
end
|
40
|
+
|
41
|
+
data.each_pair.with_object({}) do |(key, value), hash|
|
42
|
+
case value
|
43
|
+
when OpenStruct
|
44
|
+
hash[key] = struct_to_hash(value)
|
45
|
+
when Array
|
46
|
+
# No test yet
|
47
|
+
values = value.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
48
|
+
hash[key] = values
|
49
|
+
else
|
50
|
+
hash[key] = value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
55
|
+
|
56
|
+
def clean_symbol(value)
|
57
|
+
return value if value.nil?
|
58
|
+
|
59
|
+
value.is_a?(Symbol) ? value.to_s : value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/k_builder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: handlebars-helpers
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/k_builder/base_configuration.rb
|
58
58
|
- lib/k_builder/builder.rb
|
59
59
|
- lib/k_builder/configuration.rb
|
60
|
+
- lib/k_builder/data_helper.rb
|
60
61
|
- lib/k_builder/version.rb
|
61
62
|
- usage/_out1.png
|
62
63
|
- usage/_out2.png
|