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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abc9118f3f615884f1f0176c77ecfffa90bdf5d198c2c4d554df2a4c524b2ea6
4
- data.tar.gz: c40ea449aaad67a03c946b9fbe5e9e132917e7632138b9321c74b925c10f8560
3
+ metadata.gz: ec75b1356060e7075bd481790769fb8f3fd80112a07247fb3a5ac1f6bac36993
4
+ data.tar.gz: 388c3f334b6864e973a4fbfd1f41d6bdbf769c3b58fb5d72a9bafeb847e11656
5
5
  SHA512:
6
- metadata.gz: 0e1b1ff0f3c742e69305d1dbd3b6ec1a34a70c0b9bf0a4a2f9ab0e25451dfba4a873281b65fd13af217c9785a4e795cfc7eb766da395d8f14bcf1012ddb51a37
7
- data.tar.gz: e7fd23e135807ebf5f491765ba854fb0fe8ac0fcec1e5f3963e974ae6c1d40d8344dc46685c270b2141279ab3dcf8a7ad4cc906a34a965f8106e22845711eff9
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KBuilder
4
- VERSION = '0.0.25'
4
+ VERSION = '0.0.26'
5
5
  end
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.25
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-14 00:00:00.000000000 Z
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