k_type 0.0.3 → 0.0.8

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: d66f0d61fe53fe8c595df611b7581323c24ed589ad520cfd3cbbe77aa91c4d39
4
- data.tar.gz: 8ca31c3c74b48018bb824d20599a05a93b265c74e6e21edee483e51d3ac8fb9e
3
+ metadata.gz: 81e12c5e1221f34c6932f756316be4cd448b485c864e00032fe1061796dd1b9f
4
+ data.tar.gz: d8219232da4b73d6fb4e475fad17aa883f32c559cd931d89c499c8aa9aa4d1e5
5
5
  SHA512:
6
- metadata.gz: de645c9b8d6298e938b0e5c4d5534f02fd5a9bcc62fa4da2f360769aa8436ba8ebd9c47a0195ff72908de96f68b309e1bdc6e9704fe41f3c4c1a0c1567663d01
7
- data.tar.gz: e7b85f1b1c32117e0ef0d23973663b417792aac8f11e13916fe9b998bef8387b51c86b1202335c9697f9d3bbeb29034b2e47ba95622aa3a8b922688f9951e231
6
+ metadata.gz: fbbb1b900d30e01b39c6df6fe72a8c37f4ebf009f707f24719adf2e955da32f70386b918d26ab65723ed43089eb4d805b2235f50e9646e84e77e99fece1237d8
7
+ data.tar.gz: 5097adb3642706db3f1b10317d2fc8c113b136f38ea39871689918c6d4219307ef86e2c9bf4db4b9e93f234d3c88301ec46d3f96c678b818b9aa3fd07aa8e494
data/Rakefile CHANGED
@@ -6,6 +6,8 @@ GEM_NAME = 'k_type'
6
6
 
7
7
  require 'bundler/gem_tasks'
8
8
  require 'rspec/core/rake_task'
9
+
10
+ require 'pry'
9
11
  require 'k_type/version'
10
12
 
11
13
  RSpec::Core::RakeTask.new(:spec)
data/k_type.gemspec CHANGED
@@ -38,5 +38,6 @@ Gem::Specification.new do |spec|
38
38
  spec.require_paths = ['lib']
39
39
  # spec.extensions = ['ext/k_type/extconf.rb']
40
40
 
41
+ spec.add_dependency 'k_log', '~> 0'
41
42
  # spec.add_dependency 'tty-box', '~> 0.5.0'
42
43
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TODO: future
4
+ # This pattern would be great as a configurable generic class
5
+ #
6
+ # children could be renamed as:
7
+ # - directors
8
+ # - components
9
+ # - elements
10
+ #
11
+ # It may also be relevant to separate parent form children
12
+
13
+ # Parent director allows upwards navigation
14
+ # attr_reader :parent
15
+ # Children directors allow downwards navigation plus access to sub-directors
16
+ # attr_reader :children
17
+
18
+ module KType
19
+ # Composite Design Pattern: https://refactoring.guru/design-patterns/composite
20
+ module Composite
21
+ # Parent allows upwards navigation to components
22
+ attr_reader :parent
23
+
24
+ # Children allow downwards navigation plus access to sub-components
25
+ attr_reader :children
26
+
27
+ def attach_parent(parent)
28
+ @parent = parent
29
+ end
30
+
31
+ def navigate_parent
32
+ parent.nil? ? self : parent
33
+ end
34
+
35
+ def root?
36
+ parent.nil?
37
+ end
38
+
39
+ # Implement as needed (Implement is not provided here because you may want to use hash or array and have additional logic)
40
+ # def reset_children
41
+ # end
42
+ # def add_child
43
+ # end
44
+ # def remove_child
45
+ # end
46
+ # def get_children
47
+ # end
48
+ # def has_child?
49
+ # end
50
+ # def execute
51
+ # end
52
+ end
53
+ end
@@ -1,17 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KType
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
4
  # Layered folders allow files to be found in any of the searchable folders
16
5
  #
17
6
  # They derive from and thus work just like named folders in that they allow folders
@@ -71,8 +60,13 @@ module KType
71
60
  def add(folder_key, *folder_parts)
72
61
  folder = super(folder_key, *folder_parts)
73
62
 
74
- ordered_keys.prepend(folder_key)
75
- ordered_folders.prepend(folder)
63
+ index = ordered_keys.find_index(folder_key)
64
+ if index
65
+ ordered_folders[index] = folder
66
+ else
67
+ ordered_keys.prepend(folder_key)
68
+ ordered_folders.prepend(folder)
69
+ end
76
70
 
77
71
  folder
78
72
  end
@@ -100,5 +94,15 @@ module KType
100
94
  }
101
95
  }.merge(@folders)
102
96
  end
97
+
98
+ def debug(title: 'layered folders')
99
+ log.section_heading title
100
+
101
+ ordered_keys.each do |key|
102
+ folder = folders[key]
103
+ log.kv key.to_s, folder
104
+ end
105
+ nil
106
+ end
103
107
  end
104
108
  end
@@ -34,6 +34,8 @@ module KType
34
34
  #
35
35
  # Do I need to support :default?
36
36
  class NamedFolders
37
+ include KLog::Logging
38
+
37
39
  attr_reader :folders
38
40
 
39
41
  attr_reader :current
@@ -54,6 +56,12 @@ module KType
54
56
  @current = folder_key
55
57
  end
56
58
 
59
+ def current_folder
60
+ return nil unless @current
61
+
62
+ get(@current)
63
+ end
64
+
57
65
  # Add support for file_parts
58
66
  def add(folder_key, *folder_parts)
59
67
  # get a predefined folder by symbol
@@ -89,10 +97,27 @@ module KType
89
97
  @folders.keys
90
98
  end
91
99
 
100
+ def folder_paths
101
+ @folders.values
102
+ end
103
+
92
104
  def to_h
93
105
  @folders
94
106
  end
95
107
 
108
+ def debug(title: 'named folders')
109
+ log.section_heading title
110
+
111
+ log.kv 'current', current
112
+ log.info ''
113
+
114
+ folders.each_key do |key|
115
+ folder = folders[key]
116
+ log.kv key.to_s, folder
117
+ end
118
+ nil
119
+ end
120
+
96
121
  private
97
122
 
98
123
  def join_folder_parts(folder_parts)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KType
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.8'
5
5
  end
data/lib/k_type.rb CHANGED
@@ -1,12 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'k_log'
3
4
  require 'k_type/version'
5
+ require 'k_type/composite'
4
6
  require 'k_type/named_folders'
5
7
  require 'k_type/layered_folders'
6
8
 
7
9
  module KType
8
10
  # raise KType::Error, 'Sample message'
9
11
  class Error < StandardError; end
12
+ end
10
13
 
11
- # Your code goes here...
14
+ if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
15
+ namespace = 'KType::Version'
16
+ file_path = $LOADED_FEATURES.find { |f| f.include?('k_type/version') }
17
+ version = KType::VERSION.ljust(9)
18
+ puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
12
19
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.8
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-04-05 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: k_log
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: " K Type provides base types for KlueLess code generation\n"
14
28
  email:
15
29
  - david@ideasmen.com.au
@@ -38,6 +52,7 @@ files:
38
52
  - hooks/update-version
39
53
  - k_type.gemspec
40
54
  - lib/k_type.rb
55
+ - lib/k_type/composite.rb
41
56
  - lib/k_type/layered_folders.rb
42
57
  - lib/k_type/named_folders.rb
43
58
  - lib/k_type/version.rb
@@ -63,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
78
  - !ruby/object:Gem::Version
64
79
  version: '0'
65
80
  requirements: []
66
- rubygems_version: 3.2.7
81
+ rubygems_version: 3.2.33
67
82
  signing_key:
68
83
  specification_version: 4
69
84
  summary: K Type provides base types for KlueLess code generation