k_doc 0.0.5 → 0.0.6
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 +4 -4
- data/lib/k_doc.rb +1 -13
- data/lib/k_doc/document.rb +15 -11
- data/lib/k_doc/logging.rb +10 -0
- data/lib/k_doc/settings.rb +13 -11
- data/lib/k_doc/version.rb +1 -1
- metadata +2 -2
- data/lib/k_doc/data.rb +0 -258
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a09106429335b14c4ee45ec10c378f620261b22f086e45065fa37a2e797c9246
|
4
|
+
data.tar.gz: d9ceb85d7df7c168579258624328a096cdf664d00d007b4fc71aa2d611d78531
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41e58349fd4b47312ac209c0d70afd49ee66b5370ab97e4bf5cc4615bd35461f8e3f8fb6849001bf655851fe266a2ea1f0ef997a1ac8b292a56fa13c2397dc65
|
7
|
+
data.tar.gz: 78ca5c98f0f1d25a7d5148dd28dfb477cedad276f44a49177bd9b8e5e4508daa1138f995bfef49ab337c4d67f9674b1130cc9e8c381b075cef8b20fd1b14dc49
|
data/lib/k_doc.rb
CHANGED
@@ -11,7 +11,7 @@ require 'k_log/log_helper'
|
|
11
11
|
require 'k_log/log_util'
|
12
12
|
|
13
13
|
require 'k_doc/version'
|
14
|
-
require 'k_doc/
|
14
|
+
require 'k_doc/logging'
|
15
15
|
require 'k_doc/document'
|
16
16
|
require 'k_doc/fake_opinion'
|
17
17
|
require 'k_doc/settings'
|
@@ -37,18 +37,6 @@ module KDoc
|
|
37
37
|
|
38
38
|
KDoc.opinion = KDoc::FakeOpinion.new
|
39
39
|
KDoc.util = KDoc::Util.new
|
40
|
-
|
41
|
-
# Need to move this into a KLog factory
|
42
|
-
def self.configure_logger
|
43
|
-
logger = Logger.new($stdout)
|
44
|
-
logger.level = Logger::DEBUG
|
45
|
-
logger.formatter = KLog::LogFormatter.new
|
46
|
-
KLog::LogUtil.new(logger)
|
47
|
-
end
|
48
|
-
|
49
|
-
# KDoc.log = configure_logger
|
50
40
|
end
|
51
41
|
|
52
|
-
L = KDoc.configure_logger
|
53
|
-
|
54
42
|
puts "KDoc::Version: #{KDoc::VERSION}" if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
|
data/lib/k_doc/document.rb
CHANGED
@@ -5,6 +5,8 @@ module KDoc
|
|
5
5
|
#
|
6
6
|
# Made up of 0 or more setting groups and table groups
|
7
7
|
class Document
|
8
|
+
include KDoc::Logging
|
9
|
+
|
8
10
|
attr_reader :key
|
9
11
|
attr_reader :type
|
10
12
|
attr_reader :namespace
|
@@ -39,12 +41,12 @@ module KDoc
|
|
39
41
|
# @error = e
|
40
42
|
# raise
|
41
43
|
rescue StandardError => e
|
42
|
-
|
44
|
+
log.error('Standard error in document')
|
43
45
|
puts "key #{unique_key}"
|
44
46
|
# puts "file #{KUtil.data.console_file_hyperlink(resource.file, resource.file)}"
|
45
|
-
|
47
|
+
log.error(e.message)
|
46
48
|
@error = e
|
47
|
-
#
|
49
|
+
# log.exception exception2
|
48
50
|
raise
|
49
51
|
ensure
|
50
52
|
@run_actions = nil
|
@@ -132,24 +134,26 @@ module KDoc
|
|
132
134
|
|
133
135
|
# tp dsls.values, :k_key, :k_type, :state, :save_at, :last_at, :data, :last_data, :source, { :file => { :width => 150 } }
|
134
136
|
# puts JSON.pretty_generate(data)
|
135
|
-
|
137
|
+
log.o(raw_data_struct)
|
136
138
|
end
|
137
139
|
|
140
|
+
# rubocop:disable Metrics/AbcSize
|
138
141
|
def debug_header
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
142
|
+
log.heading self.class.name
|
143
|
+
log.kv 'key', key
|
144
|
+
log.kv 'type', type
|
145
|
+
log.kv 'namespace', namespace
|
146
|
+
log.kv 'error', error
|
144
147
|
|
145
148
|
debug_header_keys
|
146
149
|
|
147
|
-
|
150
|
+
log.line
|
148
151
|
end
|
152
|
+
# rubocop:enable Metrics/AbcSize
|
149
153
|
|
150
154
|
def debug_header_keys
|
151
155
|
options&.keys&.reject { |k| k == :namespace }&.each do |key|
|
152
|
-
|
156
|
+
log.kv key, options[key]
|
153
157
|
end
|
154
158
|
end
|
155
159
|
|
data/lib/k_doc/settings.rb
CHANGED
@@ -6,6 +6,8 @@ module KDoc
|
|
6
6
|
# Builds up key/value settings from the block
|
7
7
|
# and applies them to a key coded node on the hash
|
8
8
|
class Settings
|
9
|
+
include Logging
|
10
|
+
|
9
11
|
attr_reader :parent
|
10
12
|
attr_reader :key
|
11
13
|
|
@@ -73,14 +75,14 @@ module KDoc
|
|
73
75
|
# object.my_name
|
74
76
|
# object.my_name('david')
|
75
77
|
def add_getter_or_param_method(name)
|
76
|
-
#
|
78
|
+
# log.progress(1, 'add_getter_or_param_method')
|
77
79
|
self.class.class_eval do
|
78
|
-
#
|
80
|
+
# log.progress(2, 'add_getter_or_param_method')
|
79
81
|
name = name.to_s.gsub(/=$/, '')
|
80
|
-
#
|
82
|
+
# log.progress(3, 'add_getter_or_param_method')
|
81
83
|
define_method(name) do |*args|
|
82
|
-
#
|
83
|
-
#
|
84
|
+
# log.progress(4, 'add_getter_or_param_method')
|
85
|
+
# log.kv 'add_getter_or_param_method', name
|
84
86
|
raise KDoc::Error, 'Multiple setting values is not supported' if args.length > 1
|
85
87
|
|
86
88
|
if args.length.zero?
|
@@ -95,15 +97,15 @@ module KDoc
|
|
95
97
|
# Handles Setter method
|
96
98
|
# object.my_name = 'david'
|
97
99
|
def add_setter_method(name)
|
98
|
-
#
|
100
|
+
# log.progress(1, 'add_setter_method')
|
99
101
|
self.class.class_eval do
|
100
|
-
#
|
102
|
+
# log.progress(2, 'add_setter_method')
|
101
103
|
name = name.to_s.gsub(/=$/, '')
|
102
|
-
#
|
103
|
-
#
|
104
|
+
# log.progress(3, 'add_setter_method')
|
105
|
+
# log.kv 'add_setter_method', name
|
104
106
|
define_method("#{name}=") do |value|
|
105
|
-
#
|
106
|
-
#
|
107
|
+
# log.progress(4, 'add_setter_method')
|
108
|
+
# log.kv 'value', value
|
107
109
|
my_data[name.to_s] = value
|
108
110
|
end
|
109
111
|
end
|
data/lib/k_doc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
@@ -67,9 +67,9 @@ files:
|
|
67
67
|
- hooks/update-version
|
68
68
|
- k_doc.gemspec
|
69
69
|
- lib/k_doc.rb
|
70
|
-
- lib/k_doc/data.rb
|
71
70
|
- lib/k_doc/document.rb
|
72
71
|
- lib/k_doc/fake_opinion.rb
|
72
|
+
- lib/k_doc/logging.rb
|
73
73
|
- lib/k_doc/settings.rb
|
74
74
|
- lib/k_doc/table.rb
|
75
75
|
- lib/k_doc/util.rb
|
data/lib/k_doc/data.rb
DELETED
@@ -1,258 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# module KDoc
|
4
|
-
# # TODO
|
5
|
-
# # Missing tests around errors
|
6
|
-
# # Make sure that error writes to resource or document appropriately
|
7
|
-
# # Puts errors onto a project manager pipeline so that they can be be printed out after the documents
|
8
|
-
# #
|
9
|
-
# # General purpose document DSL
|
10
|
-
# #
|
11
|
-
# # Made up of 0 or more setting groups and table groups
|
12
|
-
# class Data
|
13
|
-
# extend Forwardable
|
14
|
-
|
15
|
-
# attr_reader :key
|
16
|
-
# attr_reader :type
|
17
|
-
# attr_reader :namespace
|
18
|
-
# attr_reader :options
|
19
|
-
# attr_reader :error
|
20
|
-
|
21
|
-
# # State of document
|
22
|
-
# # - :initializing
|
23
|
-
# # - :initialized
|
24
|
-
# # - :loading
|
25
|
-
# # - :loaded
|
26
|
-
# # - :executing
|
27
|
-
# # - :executed
|
28
|
-
# attr_reader :state
|
29
|
-
|
30
|
-
# # Shortcut to formatter
|
31
|
-
# attr_reader :f
|
32
|
-
|
33
|
-
# attr_accessor :resource
|
34
|
-
|
35
|
-
# def_delegator :resource, :project
|
36
|
-
|
37
|
-
# def state=(state)
|
38
|
-
# @state = state
|
39
|
-
# # if [:initialized, :loaded, :executed].include?(state) &&
|
40
|
-
# # (project.nil? || project.name == 'k_dsl')
|
41
|
-
# # # pname = project.nil? ? '' : "#{project&.name} "
|
42
|
-
# # L.kv "#{unique_key} - state", state
|
43
|
-
# # end
|
44
|
-
# @state
|
45
|
-
# end
|
46
|
-
|
47
|
-
# # Create document
|
48
|
-
# #
|
49
|
-
# # @param [String|Symbol] name Name of the document
|
50
|
-
# # @param args[0] Type of the document, defaults to KDsl.config.default_document_type if not set
|
51
|
-
# # @param default: Default value (using named params), as above
|
52
|
-
# def initialize(key = SecureRandom.alphanumeric(8), *args, **options, &block)
|
53
|
-
# @key = key
|
54
|
-
# @type = args.length.positive? ? args[0] || KDsl.config.default_document_type : KDsl.config.default_document_type
|
55
|
-
|
56
|
-
# @options = options || {}
|
57
|
-
# @namespace = options[:namespace] || ''
|
58
|
-
# default_data = options[:default_data] || {}
|
59
|
-
|
60
|
-
# @namespace = @namespace.to_s
|
61
|
-
# @error = nil
|
62
|
-
|
63
|
-
# self.state = :initializing
|
64
|
-
|
65
|
-
# # Most documents live within a hash, some tabular documents such as
|
66
|
-
# # CSV will use an []
|
67
|
-
# set_data(default_data)
|
68
|
-
|
69
|
-
# @f = KDsl::Util.format
|
70
|
-
|
71
|
-
# @block = block if block_given?
|
72
|
-
|
73
|
-
# self.state = :initialized
|
74
|
-
# end
|
75
|
-
|
76
|
-
# def execute_block(run_actions: nil)
|
77
|
-
# return if @block.nil?
|
78
|
-
|
79
|
-
# # The DSL actions method will only run on run_actions: true
|
80
|
-
# @run_actions = run_actions
|
81
|
-
|
82
|
-
# # if unique_key == 'template_options_entity'
|
83
|
-
# # L.kv '2:CLASS_ID', object_id
|
84
|
-
# # end
|
85
|
-
# if initialized?
|
86
|
-
# self.state = :loading
|
87
|
-
# instance_eval(&@block)
|
88
|
-
# self.state = :loaded
|
89
|
-
# end
|
90
|
-
# # if unique_key == 'template_options_entity'
|
91
|
-
# # L.kv '3:CLASS_ID', resource_document.object_id
|
92
|
-
# # end
|
93
|
-
|
94
|
-
# if loaded? && run_actions && respond_to?(:on_action)
|
95
|
-
# @state = :executed
|
96
|
-
# on_action
|
97
|
-
# end
|
98
|
-
# rescue KDsl::Error => e
|
99
|
-
# L.error('KDsl::Error in document')
|
100
|
-
# L.kv 'key', unique_key
|
101
|
-
# L.kv 'file', KDsl::Util.data.console_file_hyperlink(resource.file, resource.file)
|
102
|
-
# L.error(e.message)
|
103
|
-
# @error = e
|
104
|
-
# # L.heading "Invalid code block in document_dsl during registration: #{k_key}"
|
105
|
-
# # L.exception exception
|
106
|
-
# raise
|
107
|
-
# rescue StandardError => e
|
108
|
-
# L.error('Standard error in document')
|
109
|
-
# L.kv 'key', unique_key
|
110
|
-
# L.kv 'file', KDsl::Util.data.console_file_hyperlink(resource.file, resource.file)
|
111
|
-
# L.error(e.message)
|
112
|
-
# @error = e
|
113
|
-
# # L.exception exception2
|
114
|
-
# raise
|
115
|
-
# ensure
|
116
|
-
# @run_actions = nil
|
117
|
-
# return
|
118
|
-
# end
|
119
|
-
|
120
|
-
# def initialized?
|
121
|
-
# @state == :initialized
|
122
|
-
# end
|
123
|
-
|
124
|
-
# def loaded?
|
125
|
-
# @state == :loaded
|
126
|
-
# end
|
127
|
-
|
128
|
-
# def executed?
|
129
|
-
# @state == :executed
|
130
|
-
# end
|
131
|
-
|
132
|
-
# def unique_key
|
133
|
-
# @unique_key ||= KDsl::Util.dsl.build_unique_key(key, type, namespace)
|
134
|
-
# end
|
135
|
-
|
136
|
-
# def settings(key = nil, **options, &block)
|
137
|
-
# options ||= {}
|
138
|
-
|
139
|
-
# opts = {}.merge(@options) # Document Options
|
140
|
-
# .merge(options) # Settings Options
|
141
|
-
|
142
|
-
# settings = settings_instance(@data, key, parent: self, &block)
|
143
|
-
# settings.run_decorators(opts)
|
144
|
-
# settings
|
145
|
-
# end
|
146
|
-
|
147
|
-
# def table(key = :table, &block)
|
148
|
-
# # NEED to add support for run_decorators I think
|
149
|
-
# table_instance(@data, key, parent: self, &block)
|
150
|
-
# end
|
151
|
-
# alias rows table
|
152
|
-
|
153
|
-
# # Sweet add-on would be builders
|
154
|
-
# # def builder(key, &block)
|
155
|
-
# # # example
|
156
|
-
# # KDsl::Builder::Shotstack.new(@data, key, &block)
|
157
|
-
# # end
|
158
|
-
|
159
|
-
# def set_data(data)
|
160
|
-
# @data = data
|
161
|
-
# end
|
162
|
-
|
163
|
-
# def data
|
164
|
-
# @data.clone
|
165
|
-
# end
|
166
|
-
|
167
|
-
# def data_struct
|
168
|
-
# KDsl::Util.data.to_struct(data)
|
169
|
-
# end
|
170
|
-
# alias d data_struct
|
171
|
-
|
172
|
-
# def raw_data_struct
|
173
|
-
# KDsl::Util.data.to_struct(raw_data)
|
174
|
-
# end
|
175
|
-
|
176
|
-
# def get_node_type(node_name)
|
177
|
-
# node_name = KDsl::Util.data.clean_symbol(node_name)
|
178
|
-
# node_data = @data[node_name]
|
179
|
-
|
180
|
-
# raise KDsl::Error, "Node not found: #{node_name}" if node_data.nil?
|
181
|
-
|
182
|
-
# if node_data.keys.length == 2 && (node_data.key?('fields') && node_data.key?('rows'))
|
183
|
-
# :table
|
184
|
-
# else
|
185
|
-
# :settings
|
186
|
-
# end
|
187
|
-
# end
|
188
|
-
|
189
|
-
# # Removes any meta data eg. "fields" from a table and just returns the raw data
|
190
|
-
# def raw_data
|
191
|
-
# # REFACT, what if this is CSV, meaning it is just an array?
|
192
|
-
# # add specs
|
193
|
-
# result = data
|
194
|
-
|
195
|
-
# result.each_key do |key|
|
196
|
-
# # ANTI: get_node_type uses @data while we are using @data.clone here
|
197
|
-
# data[key] = if get_node_type(key) == :table
|
198
|
-
# result[key].delete('fields')
|
199
|
-
# else
|
200
|
-
# result[key]
|
201
|
-
# end
|
202
|
-
# end
|
203
|
-
|
204
|
-
# data
|
205
|
-
# end
|
206
|
-
|
207
|
-
# # Move this out to the logger function when it has been refactor
|
208
|
-
# def debug(include_header = false)
|
209
|
-
# debug_header if include_header
|
210
|
-
|
211
|
-
# # tp dsls.values, :k_key, :k_type, :state, :save_at, :last_at, :data, :last_data, :source, { :file => { :width => 150 } }
|
212
|
-
# # puts JSON.pretty_generate(data)
|
213
|
-
# L.o(raw_data_struct)
|
214
|
-
# end
|
215
|
-
|
216
|
-
# def debug_header
|
217
|
-
# L.heading self.class.name
|
218
|
-
# L.kv 'key', key
|
219
|
-
# L.kv 'type', type
|
220
|
-
# L.kv 'namespace', namespace
|
221
|
-
# L.kv 'error', error
|
222
|
-
# L.kv 'state', state
|
223
|
-
# L.kv 'respond_to?(:on_import)', respond_to?(:on_import)
|
224
|
-
# L.kv 'respond_to?(:david)', respond_to?(:david)
|
225
|
-
# david if respond_to?(:david)
|
226
|
-
# # L.kv 'INITALIZED', resource_document.initialized?
|
227
|
-
# # L.kv 'EXECUTED', resource_document.executed?
|
228
|
-
|
229
|
-
# options&.keys.reject { |k| k == :namespace }&.each do |key|
|
230
|
-
# L.kv key, options[key]
|
231
|
-
# end
|
232
|
-
|
233
|
-
# L.line
|
234
|
-
# end
|
235
|
-
|
236
|
-
# # Helpers that often get called by extensions
|
237
|
-
|
238
|
-
# def project
|
239
|
-
# project ||= resource&.project
|
240
|
-
# end
|
241
|
-
|
242
|
-
# # Warning message
|
243
|
-
# def warn(message)
|
244
|
-
# L.warn message
|
245
|
-
# nil
|
246
|
-
# end
|
247
|
-
|
248
|
-
# private
|
249
|
-
|
250
|
-
# def settings_instance(data, key, **options, &block)
|
251
|
-
# KDsl.config.settings_class.new(data, key, **options, &block)
|
252
|
-
# end
|
253
|
-
|
254
|
-
# def table_instance(data, key, **options, &block)
|
255
|
-
# KDsl.config.table_class.new(data, key, **options, &block)
|
256
|
-
# end
|
257
|
-
# end
|
258
|
-
# end
|