k_builder 0.0.51 → 0.0.58

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 528f2587aacba6aa1d13d32737aa081b3ebb5364d3bc7e4628a2935a3746ff15
4
- data.tar.gz: bb780d8e64e7c814e0b51c8561537a2cbdc31a1ab81f5ee4c78e8d3bb3fa1e89
3
+ metadata.gz: f173e365f4bece5981d87548e67b32f9748e2ae8438d2d3bb54c121de957ec87
4
+ data.tar.gz: 3d2c0d23e74b0049a112f8e175fa6dce05a1afad90b80f77a63f82d3231c772a
5
5
  SHA512:
6
- metadata.gz: 2d1dfa3e5875b691576390c970d8005036244566277fee71bbaebe5fc8e63e43588b87780c7616d8e5e07df838dcc3f2ccbf2d4edad8689d2308b8ce41e780e0
7
- data.tar.gz: 2eda2bb2b6caa396b0a7ffa0052d22e1bd98fc2931fbb3eb1352ff0b2e0c4fe86880c70e947f456d862d7279bf862f948ffb1c8eea9f9581b29257eb75ded468
6
+ metadata.gz: 63901b9242e0933f4d6b639fbdbba2212b5f37d614b1cf43cf7ace40d97560bd0afb47cba1879c4e2ba9d923f52c12f5456ce03c734a77d63472977adc996184
7
+ data.tar.gz: eec21944c6e4d9cc64f2fa841ecbe1c655f14146626e04152b9ad152824b19f0a1d7450346781aaba1f0d4994649d99faa00ea39a5f40714a1df143b0adbc22a
data/.rubocop.yml CHANGED
@@ -73,6 +73,9 @@ Layout/EmptyLineBetweenDefs:
73
73
  Exclude:
74
74
  - "**/spec/**/*"
75
75
 
76
+ Style/Documentation:
77
+ Enabled: false
78
+
76
79
  Lint/AmbiguousBlockAssociation:
77
80
  Exclude:
78
81
  - "**/spec/**/*"
data/Rakefile CHANGED
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ GEM_NAME = 'k_builder'
4
+
3
5
  require 'bundler/gem_tasks'
4
6
  require 'rspec/core/rake_task'
7
+ require 'k_builder/version'
5
8
 
6
9
  RSpec::Core::RakeTask.new(:spec)
7
10
 
@@ -14,4 +17,15 @@ Rake::ExtensionTask.new('k_builder') do |ext|
14
17
  ext.lib_dir = 'lib/k_builder'
15
18
  end
16
19
 
20
+ desc 'Publish the gem to RubyGems.org'
21
+ task :publish do
22
+ system 'gem build'
23
+ system "gem push #{GEM_NAME}-#{KBuilder::VERSION}.gem"
24
+ end
25
+
26
+ desc 'Remove old *.gem files'
27
+ task :clean do
28
+ system 'rm *.gem'
29
+ end
30
+
17
31
  task default: %i[clobber compile spec]
data/k_builder.gemspec CHANGED
@@ -39,6 +39,9 @@ Gem::Specification.new do |spec|
39
39
  # spec.extensions = ['ext/k_builder/extconf.rb']
40
40
 
41
41
  spec.add_dependency 'handlebars-helpers', '~> 0'
42
+ spec.add_dependency 'k_log', '~> 0'
43
+ spec.add_dependency 'k_type', '~> 0'
44
+ spec.add_dependency 'k_util', '~> 0'
42
45
  # spec.add_dependency "anyway_config" , ">= 2.0.0"
43
46
  # spec.add_dependency "config" , ">= 3.0.0"
44
47
  end
data/lib/k_builder.rb CHANGED
@@ -1,19 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'k_log'
4
+ require 'k_util'
5
+ require 'k_type'
3
6
  require 'k_builder/version'
4
7
  require 'k_builder/base_builder'
5
8
  require 'k_builder/base_configuration'
6
9
  require 'k_builder/configuration'
7
- require 'k_builder/data_helper'
8
10
  require 'k_builder/file_segments'
9
- require 'k_builder/named_folders'
10
- require 'k_builder/layered_folders'
11
11
 
12
12
  require 'handlebars/helpers/template'
13
13
 
14
14
  module KBuilder
15
15
  # raise KBuilder::Error, 'Sample message'
16
16
  class Error < StandardError; end
17
+ end
17
18
 
18
- # Your code goes here...
19
+ if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
20
+ namespace = 'KBuilder::Version'
21
+ file_path = $LOADED_FEATURES.find { |f| f.include?('k_builder/version') }
22
+ version = KBuilder::VERSION.ljust(9)
23
+ puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
19
24
  end
@@ -8,6 +8,8 @@ module KBuilder
8
8
  # Setter methods (are NOT fluent) can be created as needed
9
9
  # these methods would not be prefixed with the set_
10
10
  class BaseBuilder
11
+ include KLog::Logging
12
+
11
13
  attr_reader :configuration
12
14
 
13
15
  attr_accessor :target_folders
@@ -57,6 +59,17 @@ module KBuilder
57
59
  }
58
60
  end
59
61
 
62
+ def debug
63
+ log.subheading 'kbuilder'
64
+
65
+ target_folders.debug(title: 'target_folders')
66
+
67
+ log.info ''
68
+
69
+ template_folders.debug(title: 'template folders (search order)')
70
+ ''
71
+ end
72
+
60
73
  # ----------------------------------------------------------------------
61
74
  # Fluent interface
62
75
  # ----------------------------------------------------------------------
@@ -92,6 +105,7 @@ module KBuilder
92
105
 
93
106
  # Prettier needs to work with the original file name
94
107
  run_prettier file if opts.key?(:pretty)
108
+ # Need support for rubocop -a
95
109
 
96
110
  self
97
111
  end
@@ -234,9 +248,19 @@ module KBuilder
234
248
 
235
249
  return unless opts[:content_file]
236
250
 
237
- cf = opts[:content_file]
251
+ # NOTE: when using content file, you still want to search for it in the template folders, I THINK?
252
+ cf = find_template_file(opts[:content_file])
253
+
254
+ return "content not found: #{opts[:content_file]}" if cf.nil?
255
+
256
+ # cf = opts[:content_file]
257
+
258
+ # unless File.exist?(cf)
259
+ # cf_from_template_folders = find_template_file(cf)
260
+ # return "Content not found: #{File.expand_path(cf)}" unless File.exist?(cf_from_template_folders)
238
261
 
239
- return "Content not found: #{File.expand_path(cf)}" unless File.exist?(cf)
262
+ # cf = cf_from_template_folders
263
+ # end
240
264
 
241
265
  File.read(cf)
242
266
  end
@@ -298,6 +322,8 @@ module KBuilder
298
322
 
299
323
  puts build_command
300
324
 
325
+ # need to support the fork process options as I was not able to run
326
+ # k_builder_watch -n because it hid all the following output
301
327
  system(build_command)
302
328
  end
303
329
  alias rc run_command
@@ -3,17 +3,25 @@
3
3
  module KBuilder
4
4
  # Base configuration object for all k_builder* GEM
5
5
  class BaseConfiguration
6
- def self.attach_to(klass_me, klass_target, accessor_name)
7
- # Create a memoized getter to an instance of the attaching class (:klass_me)
6
+ class << self
7
+ # Attach a child configuration with it's own settings to a parent configuration
8
8
  #
9
- # def third_party
10
- # @third_party ||= KBuilder::ThirdPartyGem::Configuration.new
11
- # end
12
- klass_target.send(:define_method, accessor_name) do
13
- return instance_variable_get("@#{accessor_name}") if instance_variable_defined?("@#{accessor_name}")
9
+ # @param [Class] klass_child what class would you like as the child
10
+ # @param [Class] klass_parent what class would you like to extend with a new child configuration
11
+ # @param [Symbol] accessor_name what is the name of the accessor that you are adding
12
+ def attach_config_to_parent(klass_child, klass_parent, accessor_name)
13
+ # Create a memoized getter to an instance of the attaching class (:klass_child)
14
+ #
15
+ # def third_party
16
+ # @third_party ||= KBuilder::ThirdPartyGem::Configuration.new
17
+ # end
18
+ klass_parent.send(:define_method, accessor_name) do
19
+ return instance_variable_get("@#{accessor_name}") if instance_variable_defined?("@#{accessor_name}")
14
20
 
15
- instance_variable_set("@#{accessor_name}", klass_me.new)
21
+ instance_variable_set("@#{accessor_name}", klass_child.new)
22
+ end
16
23
  end
24
+ alias attach_to attach_config_to_parent
17
25
  end
18
26
 
19
27
  # move out into module
@@ -22,13 +30,14 @@ module KBuilder
22
30
  instance_variables.each do |var|
23
31
  value = instance_variable_get(var)
24
32
 
25
- value = KBuilder.data.struct_to_hash(value) if complex_type?(value)
33
+ value = KUtil.data.to_hash(value) if complex_type?(value)
26
34
 
27
35
  hash[var.to_s.delete('@')] = value
28
36
  end
29
37
  hash
30
38
  end
31
39
 
40
+ # This code is being moved into k_util (data)
32
41
  # Any basic (aka primitive) type
33
42
  def basic_type?(value)
34
43
  value.is_a?(String) ||
@@ -19,9 +19,17 @@ module KBuilder
19
19
  yield(configuration)
20
20
  end
21
21
 
22
+ # Does this class need to move out into k_types?
23
+ # It is being used with k_manager in a similar fashion
24
+ #
22
25
  # Configuration class
23
26
  class Configuration < BaseConfiguration
27
+ include KLog::Logging
28
+
29
+ # Target folders provide a set named folders that can be written to
24
30
  attr_accessor :target_folders
31
+
32
+ # Template folders provides layered folders that templates can exist within
25
33
  attr_accessor :template_folders
26
34
 
27
35
  def initialize
@@ -29,8 +37,8 @@ module KBuilder
29
37
  # @target_folder = Dir.getwd
30
38
  # @template_folder = File.join(Dir.getwd, '.templates')
31
39
  # @global_template_folder = nil
32
- @target_folders = NamedFolders.new
33
- @template_folders = LayeredFolders.new
40
+ @target_folders = KType::NamedFolders.new
41
+ @template_folders = KType::LayeredFolders.new
34
42
  end
35
43
 
36
44
  def initialize_copy(orig)
@@ -40,22 +48,15 @@ module KBuilder
40
48
  @template_folders = orig.template_folders.clone
41
49
  end
42
50
 
43
- # rubocop:disable Metrics/AbcSize
44
51
  def debug
45
- puts '-' * 120
46
- puts 'kbuilder base configuration'
47
-
48
- puts 'target_folders'
49
- target_folders.folders.each_key do |key|
50
- folder = target_folders.folders[key]
51
- kv key.to_s, folder
52
- end
53
-
54
- puts 'template folders (search order)'
55
- template_folders.ordered_folders.each do |folder|
56
- puts folder.to_s
57
- end
52
+ log.subheading 'kbuilder base configuration'
53
+
54
+ target_folders.debug(title: 'target_folders')
55
+
56
+ log.info ''
57
+
58
+ template_folders.debug(title: 'template folders (search order)')
59
+ ''
58
60
  end
59
- # rubocop:enable Metrics/AbcSize
60
61
  end
61
62
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KBuilder
4
- VERSION = '0.0.51'
4
+ VERSION = '0.0.58'
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.51
4
+ version: 0.0.58
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-30 00:00:00.000000000 Z
11
+ date: 2021-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: handlebars-helpers
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: k_log
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: k_type
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: k_util
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  description: " K Builder provides various fluent builders for initializing applications
28
70
  with different language requirements\n"
29
71
  email:
@@ -56,10 +98,7 @@ files:
56
98
  - lib/k_builder/base_builder.rb
57
99
  - lib/k_builder/base_configuration.rb
58
100
  - lib/k_builder/configuration.rb
59
- - lib/k_builder/data_helper.rb
60
101
  - lib/k_builder/file_segments.rb
61
- - lib/k_builder/layered_folders.rb
62
- - lib/k_builder/named_folders.rb
63
102
  - lib/k_builder/version.rb
64
103
  - usage/_out1.png
65
104
  - usage/_out2.png
@@ -1,66 +0,0 @@
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, Metrics/PerceivedComplexity
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
- return struct_to_hash(data.to_h) if !data.is_a?(Hash) && data.respond_to?(:to_h)
42
-
43
- data.each_pair.with_object({}) do |(key, value), hash|
44
- case value
45
- when OpenStruct, Struct, Hash
46
- hash[key] = struct_to_hash(value)
47
- when Array
48
- # No test yet
49
- values = value.map do |v|
50
- v.is_a?(OpenStruct) || v.is_a?(Struct) || v.is_a?(Hash) ? struct_to_hash(v) : v
51
- end
52
- hash[key] = values
53
- else
54
- hash[key] = value
55
- end
56
- end
57
- end
58
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
59
-
60
- def clean_symbol(value)
61
- return value if value.nil?
62
-
63
- value.is_a?(Symbol) ? value.to_s : value
64
- end
65
- end
66
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KBuilder
4
- #
5
- # Named folders makes sense for generated/output folders because you may want
6
- # more than one type of location to generate output.
7
- #
8
- # Don't confuse multiple named output folders with sub-paths, when you want to
9
- # build up a file name in a child folder, you can do that as part of building
10
- # the filename.
11
- #
12
- # The idea behind named folders is for when you have two or more totally different
13
- # outputs that (may live in the a similar location) or live in different locations.
14
-
15
- # Layered folders allow files to be found in any of the searchable folders
16
- #
17
- # They derive from and thus work just like named folders in that they allow folders
18
- # to be stored with easy to remember names/alias's.
19
- #
20
- # Where they differ is that they are retrieved in preferential search order that is
21
- # by default (First In, Last Out) priority aka a Stack (Last In, First Out) or
22
- # optionally over ridden via the search_order method
23
- #
24
- # Layered folders makes sense for use with template files and source data/model
25
- # where you can have specific usage files available and if they are not found then
26
- # you can use fall-back files in other folders.
27
- #
28
- # example:
29
- # folders = LayeredFolders.new
30
- # folders.add(:global , '~/global_templates')
31
- # folders.add(:domain , '/my-project/domain_templates')
32
- # folders.add(:app , '/my-project/my-app/.templates')
33
- #
34
- # # Find a file and folder will in folders in this order
35
- # # app_templates, then domain_templates and then finally global templates
36
- # # ['/my-project/my-app/.templates', '/my-project/domain_templates', '~/global_templates']
37
- # #
38
- # # Find a file called template1.txt and return its fully-qualified path
39
- # folders.find_file('template1.txt')
40
- #
41
- # # As above, but returns the folder only, file name and sub-paths are ignored
42
- # folders.find_file_folder('template1.txt')
43
- # folders.find_file_folder('abc/xyz/deep-template.txt')
44
- #
45
- # # If an additional folder is added, say in child configuration that is designed
46
- # # to override some of the global templates, then you can run a search_order
47
- # # method to re-order the templates
48
- #
49
- # folders.add(:global_shim , '~/global_templates_shim')
50
- # folders.search_order(:app, :domain, :global_shim, :global)
51
- #
52
- # class Builder < KBuilder::BaseBuilder
53
- class LayeredFolders < KBuilder::NamedFolders
54
- attr_reader :ordered_keys
55
- attr_reader :ordered_folders
56
-
57
- def initialize
58
- super()
59
-
60
- @ordered_keys = []
61
- @ordered_folders = []
62
- end
63
-
64
- def initialize_copy(orig)
65
- super(orig)
66
-
67
- @ordered_keys = orig.ordered_keys.clone
68
- @ordered_folders = orig.ordered_folders.clone
69
- end
70
-
71
- def add(folder_key, *folder_parts)
72
- folder = super(folder_key, *folder_parts)
73
-
74
- ordered_keys.prepend(folder_key)
75
- ordered_folders.prepend(folder)
76
-
77
- folder
78
- end
79
-
80
- # File name or array of sub-paths plus file
81
- #
82
- # Return the folder that a file is found in
83
- def find_file(file_parts)
84
- folder = find_file_folder(file_parts)
85
- folder.nil? ? nil : File.join(folder, file_parts)
86
- end
87
-
88
- # File name or array of sub-paths plus file
89
- #
90
- # Return the folder that a file is found in
91
- def find_file_folder(file_parts)
92
- ordered_folders.find { |folder| File.exist?(File.join(folder, file_parts)) }
93
- end
94
-
95
- def to_h
96
- {
97
- ordered: {
98
- keys: ordered_keys,
99
- folders: ordered_folders
100
- }
101
- }.merge(@folders)
102
- end
103
- end
104
- end
@@ -1,116 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KBuilder
4
- # Named folders allow folders to be stored with easy to remember names/alias's
5
- # Secondarily, you can also build up file names based on these named folders.
6
- #
7
- # Named folders makes sense for generated/output folders because you may want
8
- # more than one type of location to generate output.
9
- #
10
- # Don't confuse multiple named output folders with sub-paths, when you want to
11
- # build up a file name in a child folder, you can do that as part of building
12
- # the filename.
13
- #
14
- # The idea behind named folders is for when you have two or more totally different
15
- # outputs that (may live in the a similar location) or live in different locations.
16
- # Samples:
17
- # name: :code - generating source code into a project
18
- # name: :slide - generating slide deck into a documentation folder
19
- # name: :webpack - folder where you might generate webpack files, e.g. webpack.config.*.json
20
- #
21
- # example:
22
- # folders = NamedFolders.new
23
- # folders.add(:csharp , '~/dev/csharp/cool-project')
24
- # folders.add(:package_json , :csharp)
25
- # folders.add(:webpack , folders.join(:csharp, 'config'))
26
- # folders.add(:builder , folders.join(:csharp, 'builder'))
27
- # folders.add(:slides , '~/doc/csharp/cool-project')
28
- #
29
- # puts folders.get(:builder)
30
- #
31
- # puts folders.get_filename(:csharp, 'Program.cs')
32
- # puts folders.get_filename(:csharp, 'Models/Order.cs')
33
- # puts folders.get_filename(:csharp, 'Models', 'Order.cs')
34
- #
35
- # Do I need to support :default?
36
- class NamedFolders
37
- attr_reader :folders
38
-
39
- attr_reader :current
40
-
41
- def initialize
42
- @folders = {}
43
- @current = nil
44
- end
45
-
46
- def initialize_copy(orig)
47
- super(orig)
48
-
49
- @folders = orig.folders.clone
50
- end
51
-
52
- def current=(folder_key)
53
- guard_folder_key(folder_key)
54
- @current = folder_key
55
- end
56
-
57
- # Add support for file_parts
58
- def add(folder_key, *folder_parts)
59
- # get a predefined folder by symbol
60
- folder = join_folder_parts(folder_parts)
61
- if folder.is_a?(Symbol)
62
- folder = get(folder)
63
- elsif folder.start_with?('~')
64
- folder = File.expand_path(folder)
65
- end
66
-
67
- @current = folder_key if @current.nil?
68
- folders[folder_key] = folder
69
- end
70
-
71
- # Get a folder
72
- def get(folder_key)
73
- guard_folder_key(folder_key)
74
- folders[folder_key]
75
- end
76
-
77
- # Join the lookup folder key with the subpath folder parts (optionally + filename) and return the folder or filename
78
- #
79
- # Return fully qualified filename
80
- def join(folder_key, *file_folder_parts)
81
- folder = get(folder_key)
82
-
83
- File.join(folder, file_folder_parts)
84
- end
85
- # Get a file name using the lookup folder key and the file name or array of sub-paths plus filename
86
- alias get_filename join
87
-
88
- def folder_keys
89
- @folders.keys
90
- end
91
-
92
- def to_h
93
- @folders
94
- end
95
-
96
- private
97
-
98
- def join_folder_parts(folder_parts)
99
- raise KBuilder::Error, 'No folder part provided' if folder_parts.nil? || folder_parts.length.zero?
100
-
101
- # If only one part, and that can be a folder or :folder_key, then just return it
102
- return folder_parts.first if folder_parts.length == 1
103
-
104
- folder_parts = folder_parts.map.with_index do |folder_part, index|
105
- folder_part = get(folder_part) if index.zero? && folder_part.is_a?(Symbol)
106
- folder_part
107
- end
108
-
109
- File.join(folder_parts)
110
- end
111
-
112
- def guard_folder_key(folder_key)
113
- raise KBuilder::Error, "Folder not found, this folder key not found: #{folder_key}" unless folders.key?(folder_key)
114
- end
115
- end
116
- end