k_doc 0.0.25 → 0.0.32
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/.rubocop.yml +8 -13
- data/lib/k_doc/container.rb +12 -2
- data/lib/k_doc/fake_opinion.rb +0 -4
- data/lib/k_doc/mixins/block_processor.rb +143 -12
- data/lib/k_doc/mixins/taggable.rb +1 -19
- data/lib/k_doc/model.rb +23 -18
- data/lib/k_doc/settings.rb +26 -32
- data/lib/k_doc/table.rb +37 -29
- data/lib/k_doc/version.rb +1 -1
- metadata +2 -3
- data/lib/k_doc/model_backup.rb +0 -191
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 627b725f7a57a7eed231bac5a00c2409cdaaf1e5bf5c9610b15c63725cae0fbc
|
4
|
+
data.tar.gz: 3da6428f327fcf696cf7af358bca4db24f894e52d526e7b096fbf42d1fbdaddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be14c2081ea3656f0d52cad2aef871bd8f31f474ebc2b7f6a004d02a2f9198e79c52fe4b5c9bcf86ad022fc43e2cb7d1373e72cba6d0317e7ff2b40bd163a8e2
|
7
|
+
data.tar.gz: 46ba2d4f053d7548006317c8e5398379ab8a8167cd7e1d02ae9aa8eda988dce8eac42f207e2aa9e7fb7957c7cd91349dda1f5e30df63b320ec0e7b09d43e364a
|
data/.rubocop.yml
CHANGED
@@ -44,15 +44,19 @@ Layout/LineLength:
|
|
44
44
|
Lint/UnusedMethodArgument:
|
45
45
|
AllowUnusedKeywordArguments: true
|
46
46
|
|
47
|
-
Style/
|
47
|
+
Style/AccessorGrouping:
|
48
48
|
Enabled: false
|
49
|
-
|
50
49
|
Style/BlockComments:
|
51
50
|
Enabled: false
|
52
51
|
Include:
|
53
52
|
- "**/spec/*"
|
54
|
-
|
55
|
-
|
53
|
+
Style/Documentation:
|
54
|
+
Enabled: false
|
55
|
+
Style/EmptyMethod:
|
56
|
+
Exclude:
|
57
|
+
- "**/spec/**/*"
|
58
|
+
Style/OpenStructUse:
|
59
|
+
Enabled: false
|
56
60
|
Metrics/ClassLength:
|
57
61
|
Enabled: false
|
58
62
|
Metrics/ModuleLength:
|
@@ -63,23 +67,14 @@ Naming/MemoizedInstanceVariableName:
|
|
63
67
|
Naming/VariableNumber:
|
64
68
|
Exclude:
|
65
69
|
- "**/spec/**/*"
|
66
|
-
Style/EmptyMethod:
|
67
|
-
Exclude:
|
68
|
-
- "**/spec/**/*"
|
69
70
|
Metrics/ParameterLists:
|
70
71
|
Exclude:
|
71
72
|
- "**/spec/**/*"
|
72
73
|
Layout/EmptyLineBetweenDefs:
|
73
74
|
Exclude:
|
74
75
|
- "**/spec/**/*"
|
75
|
-
|
76
76
|
Lint/AmbiguousBlockAssociation:
|
77
77
|
Exclude:
|
78
78
|
- "**/spec/**/*"
|
79
|
-
|
80
|
-
Style/AccessorGrouping:
|
81
|
-
Enabled: false
|
82
|
-
|
83
79
|
Layout/SpaceBeforeComma:
|
84
80
|
Enabled: false
|
85
|
-
# My Preferences - End
|
data/lib/k_doc/container.rb
CHANGED
@@ -10,6 +10,10 @@ module KDoc
|
|
10
10
|
include KDoc::Datum
|
11
11
|
include KDoc::BlockProcessor
|
12
12
|
|
13
|
+
# OpenStruct to be populated with context data, this can be used inside the on_init
|
14
|
+
attr_reader :context
|
15
|
+
|
16
|
+
# Opts that are passed to the container. Some options will be removed when evaluated by different plugins (Taggable, BlockProcessor)
|
13
17
|
attr_reader :opts
|
14
18
|
|
15
19
|
# TODO: Owner/Owned need to be in a module and tested
|
@@ -20,11 +24,12 @@ module KDoc
|
|
20
24
|
end
|
21
25
|
|
22
26
|
def initialize(**opts, &block)
|
27
|
+
@context = OpenStruct.new
|
23
28
|
@opts = opts
|
24
29
|
|
25
30
|
initialize_tag(opts)
|
26
31
|
initialize_data(opts)
|
27
|
-
|
32
|
+
initialize_block_processor(opts, &block)
|
28
33
|
end
|
29
34
|
|
30
35
|
def default_container_type
|
@@ -35,8 +40,13 @@ module KDoc
|
|
35
40
|
@default_data_type ||= Hash
|
36
41
|
end
|
37
42
|
|
43
|
+
def os(**opts)
|
44
|
+
OpenStruct.new(opts)
|
45
|
+
end
|
46
|
+
|
38
47
|
def debug
|
39
|
-
|
48
|
+
debug_taggable
|
49
|
+
debug_block_processor
|
40
50
|
debug_errors
|
41
51
|
end
|
42
52
|
|
data/lib/k_doc/fake_opinion.rb
CHANGED
@@ -3,23 +3,83 @@
|
|
3
3
|
module KDoc
|
4
4
|
# A container acts a base data object for any data that requires tagging
|
5
5
|
# such as unique key, type and namespace.
|
6
|
-
#
|
6
|
+
#
|
7
|
+
# example usage of the container using model as the basis:
|
8
|
+
# KDoc.model do
|
9
|
+
# init do
|
10
|
+
# context.some_data = :xmen
|
11
|
+
# end
|
12
|
+
# settings do
|
13
|
+
# name context.some_data
|
14
|
+
# end
|
15
|
+
# action
|
16
|
+
# puts context.some_data
|
17
|
+
# end
|
18
|
+
# end
|
7
19
|
module BlockProcessor
|
8
|
-
|
20
|
+
include KLog::Logging
|
9
21
|
|
10
|
-
|
22
|
+
attr_reader :block
|
23
|
+
attr_reader :block_state
|
24
|
+
|
25
|
+
attr_reader :init_block
|
26
|
+
attr_reader :action_block
|
27
|
+
attr_reader :children
|
28
|
+
|
29
|
+
def initialize_block_processor(_opts, &block)
|
11
30
|
@block = block if block_given?
|
31
|
+
@block_state = :new
|
32
|
+
|
33
|
+
@init_block = nil
|
34
|
+
@action_block = nil
|
35
|
+
@children = []
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute_block(run_actions: false)
|
39
|
+
# Evaluate the main block of code
|
40
|
+
fire_eval # aka primary eval
|
41
|
+
|
42
|
+
# Call the block of code attached to the init method
|
43
|
+
fire_init
|
44
|
+
|
45
|
+
# Call the each block in the child array of blocks in the order of creation (FIFO)
|
46
|
+
fire_children
|
47
|
+
|
48
|
+
# Call the block of code attached to the action method
|
49
|
+
fire_action if run_actions
|
50
|
+
end
|
51
|
+
|
52
|
+
# The underlying container is created and in the case of k_manager, registered
|
53
|
+
def new?
|
54
|
+
@block_state == :new
|
12
55
|
end
|
13
56
|
|
14
|
-
|
15
|
-
|
16
|
-
|
57
|
+
# The main block has been evaluated, but child blocks are still to be processed
|
58
|
+
def evaluated?
|
59
|
+
@block_state == :evaluated || initialized?
|
17
60
|
end
|
18
61
|
|
19
|
-
|
20
|
-
|
62
|
+
# Has the init block been called?
|
63
|
+
def initialized?
|
64
|
+
@block_state == :initialized || children_evaluated?
|
65
|
+
end
|
21
66
|
|
22
|
-
|
67
|
+
# The block and the data it represents has been evaluated.
|
68
|
+
def children_evaluated?
|
69
|
+
@block_state == :children_evaluated || actioned?
|
70
|
+
end
|
71
|
+
|
72
|
+
# The on_action method has been called.
|
73
|
+
def actioned?
|
74
|
+
@block_state == :actioned
|
75
|
+
end
|
76
|
+
|
77
|
+
def fire_eval
|
78
|
+
return unless new?
|
79
|
+
|
80
|
+
instance_eval(&block) if block
|
81
|
+
|
82
|
+
@block_state = :evaluated
|
23
83
|
rescue StandardError => e
|
24
84
|
log.error('Standard error in document')
|
25
85
|
# puts "key #{unique_key}"
|
@@ -29,10 +89,71 @@ module KDoc
|
|
29
89
|
raise
|
30
90
|
end
|
31
91
|
|
32
|
-
def
|
33
|
-
|
92
|
+
def init(&block)
|
93
|
+
@init_block = block
|
94
|
+
end
|
34
95
|
|
35
|
-
|
96
|
+
def fire_init
|
97
|
+
return unless evaluated?
|
98
|
+
|
99
|
+
instance_eval(&init_block) if init_block
|
100
|
+
|
101
|
+
@block_state = :initialized
|
102
|
+
rescue StandardError => e
|
103
|
+
log.error('Standard error in document on_init')
|
104
|
+
# puts "key #{unique_key}"
|
105
|
+
# puts "file #{KUtil.data.console_file_hyperlink(resource.file, resource.file)}"
|
106
|
+
log.error(e.message)
|
107
|
+
@error = e
|
108
|
+
raise
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_child(block)
|
112
|
+
@children << block
|
113
|
+
end
|
114
|
+
|
115
|
+
# Run blocks associated with the children
|
116
|
+
#
|
117
|
+
# A child can follow one of three patterns:
|
118
|
+
# 1. A block that is evaluated immediately against the parent class
|
119
|
+
# 2. A class that has its own custom block evaluation
|
120
|
+
# 3. A class that has a block which will be evaluated immediately against the child class
|
121
|
+
# rubocop:disable Metrics/AbcSize
|
122
|
+
def fire_children
|
123
|
+
return unless initialized?
|
124
|
+
|
125
|
+
children.each do |child|
|
126
|
+
if child.is_a?(Proc)
|
127
|
+
instance_eval(&child)
|
128
|
+
elsif child.respond_to?(:fire_eval)
|
129
|
+
child.fire_eval
|
130
|
+
elsif child.respond_to?(:block)
|
131
|
+
child.instance_eval(&child.block)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
@block_state = :children_evaluated
|
136
|
+
rescue StandardError => e
|
137
|
+
log.error('Standard error in document with one of the child blocks')
|
138
|
+
# puts "key #{unique_key}"
|
139
|
+
# puts "file #{KUtil.data.console_file_hyperlink(resource.file, resource.file)}"
|
140
|
+
log.error(e.message)
|
141
|
+
@error = e
|
142
|
+
raise
|
143
|
+
end
|
144
|
+
# rubocop:enable Metrics/AbcSize
|
145
|
+
|
146
|
+
def action(&block)
|
147
|
+
@action_block = block
|
148
|
+
end
|
149
|
+
|
150
|
+
def fire_action
|
151
|
+
return unless children_evaluated?
|
152
|
+
|
153
|
+
if action_block
|
154
|
+
instance_eval(&action_block)
|
155
|
+
@block_state = :actioned
|
156
|
+
end
|
36
157
|
rescue StandardError => e
|
37
158
|
log.error('Standard error while running actions')
|
38
159
|
# puts "key #{unique_key}"
|
@@ -41,5 +162,15 @@ module KDoc
|
|
41
162
|
@error = e
|
42
163
|
raise
|
43
164
|
end
|
165
|
+
|
166
|
+
# rubocop:disable Metrics/AbcSize
|
167
|
+
def debug_block_processor
|
168
|
+
log.kv 'block_state' , block_state , debug_pad_size
|
169
|
+
log.kv 'new' , new? , debug_pad_size
|
170
|
+
log.kv 'evaluated' , evaluated? , debug_pad_size
|
171
|
+
log.kv 'children_evaluated' , children_evaluated? , debug_pad_size
|
172
|
+
log.kv 'actioned' , actioned? , debug_pad_size
|
173
|
+
end
|
174
|
+
# rubocop:enable Metrics/AbcSize
|
44
175
|
end
|
45
176
|
end
|
@@ -67,28 +67,10 @@ module KDoc
|
|
67
67
|
@namespace = ns.is_a?(Array) ? ns : [ns]
|
68
68
|
end
|
69
69
|
|
70
|
-
# # Internal data object
|
71
|
-
# def data
|
72
|
-
# @data ||= @tag_options.delete(:data) || @tag_options.delete(:default_data) || default_data_value
|
73
|
-
# # Settings and Table on Model needed access to @data for modification, I don't think this should be a clone
|
74
|
-
# # never return the original data object, but at the same time
|
75
|
-
# # do not re-clone it every time this accessor is called.
|
76
|
-
# # @clone_data ||= @data.clone
|
77
|
-
# end
|
78
|
-
|
79
|
-
# Implement in container
|
80
|
-
# def default_container_type
|
81
|
-
# :container
|
82
|
-
# end
|
83
|
-
|
84
|
-
# def default_data_value
|
85
|
-
# {}
|
86
|
-
# end
|
87
|
-
|
88
70
|
protected
|
89
71
|
|
90
72
|
# rubocop:disable Metrics/AbcSize
|
91
|
-
def
|
73
|
+
def debug_taggable
|
92
74
|
log.kv 'tag' , tag , debug_pad_size
|
93
75
|
log.kv 'project' , project , debug_pad_size unless project.nil? || project.empty?
|
94
76
|
log.kv 'namespace' , namespace , debug_pad_size unless namespace.nil? || namespace.empty?
|
data/lib/k_doc/model.rb
CHANGED
@@ -23,20 +23,29 @@ module KDoc
|
|
23
23
|
|
24
24
|
# Need to look at Director as an alternative to this technique
|
25
25
|
def settings(key = nil, **setting_opts, &block)
|
26
|
-
|
26
|
+
if block.nil?
|
27
|
+
log.warn 'You cannot call settings without a block. Did you mean to call data[:settings] or odata.settings?'
|
28
|
+
return
|
29
|
+
end
|
27
30
|
|
28
|
-
setting_opts = {}.merge(opts)
|
31
|
+
setting_opts = {}.merge(opts) # Container options
|
29
32
|
.merge(setting_opts) # Settings setting_opts
|
30
33
|
.merge(parent: self)
|
31
34
|
|
32
|
-
|
33
|
-
|
35
|
+
child = KDoc::Settings.new(self, data, key, **setting_opts, &block)
|
36
|
+
|
37
|
+
add_child(child)
|
34
38
|
end
|
35
39
|
|
36
40
|
def table(key = :table, **opts, &block)
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
if block.nil?
|
42
|
+
log.warn 'You cannot call table without a block. Did you mean to call data[:table] or odata.table?'
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
child = KDoc::Table.new(self, data, key, **opts, &block)
|
47
|
+
|
48
|
+
add_child(child)
|
40
49
|
end
|
41
50
|
alias rows table
|
42
51
|
|
@@ -75,6 +84,11 @@ module KDoc
|
|
75
84
|
|
76
85
|
raise KDoc::Error, "Node not found: #{node_name}" if node_data.nil?
|
77
86
|
|
87
|
+
if node_data.is_a?(Array)
|
88
|
+
puts 'why is this?'
|
89
|
+
return nil
|
90
|
+
end
|
91
|
+
|
78
92
|
if node_data.keys.length == 2 && (node_data.key?('fields') && node_data.key?('rows'))
|
79
93
|
:table
|
80
94
|
else
|
@@ -115,7 +129,8 @@ module KDoc
|
|
115
129
|
|
116
130
|
def debug_header
|
117
131
|
log.heading self.class.name
|
118
|
-
|
132
|
+
debug_taggable
|
133
|
+
debug_block_processor
|
119
134
|
debug_header_keys
|
120
135
|
|
121
136
|
log.line
|
@@ -126,15 +141,5 @@ module KDoc
|
|
126
141
|
log.kv key, opts[key]
|
127
142
|
end
|
128
143
|
end
|
129
|
-
|
130
|
-
private
|
131
|
-
|
132
|
-
def settings_instance(data, key, **opts, &block)
|
133
|
-
KDoc.opinion.settings_class.new(data, key, **opts, &block)
|
134
|
-
end
|
135
|
-
|
136
|
-
def table_instance(data, key, **opts, &block)
|
137
|
-
KDoc.opinion.table_class.new(data, key, **opts, &block)
|
138
|
-
end
|
139
144
|
end
|
140
145
|
end
|
data/lib/k_doc/settings.rb
CHANGED
@@ -1,36 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'json'
|
4
|
-
|
5
3
|
module KDoc
|
6
4
|
# Builds up key/value settings from the block
|
7
|
-
# and applies them to a key coded node on the hash
|
8
5
|
class Settings
|
9
6
|
include KLog::Logging
|
10
|
-
# include KDoc::Decorators
|
11
7
|
|
12
8
|
attr_reader :parent
|
13
9
|
attr_reader :key
|
14
10
|
attr_reader :decorators
|
11
|
+
attr_reader :block
|
15
12
|
|
16
|
-
|
13
|
+
def initialize(parent, data, key = nil, **opts, &block)
|
14
|
+
@parent = parent
|
15
|
+
@data = data
|
16
|
+
@key = (key || FakeOpinion.new.default_settings_key).to_s
|
17
|
+
@data[@key] = {}
|
18
|
+
@decorators = build_decorators(opts) # TODO: add tests for decorators
|
19
|
+
@block = block
|
20
|
+
end
|
17
21
|
|
18
|
-
def
|
19
|
-
|
22
|
+
def fire_eval
|
23
|
+
return unless block
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
instance_eval(&block) if block_given?
|
25
|
+
instance_eval(&block)
|
26
|
+
run_decorators
|
24
27
|
|
25
|
-
|
28
|
+
# rubocop:disable Style/RescueStandardError
|
29
|
+
rescue => e
|
30
|
+
# rubocop:enable Style/RescueStandardError
|
31
|
+
log.error("Standard error while running settings for key: #{@key}")
|
32
|
+
log.error(e.message)
|
33
|
+
raise
|
34
|
+
end
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
# rubocop:enable Style/RescueStandardError
|
30
|
-
puts "Invalid code block in settings_dsl: #{@key}"
|
31
|
-
puts e.message
|
32
|
-
raise
|
33
|
-
end
|
36
|
+
def context
|
37
|
+
parent.context
|
34
38
|
end
|
35
39
|
|
36
40
|
# Return these settings which are attached to a data container using :key
|
@@ -54,7 +58,7 @@ module KDoc
|
|
54
58
|
# puts "args.length : #{args.length}"
|
55
59
|
|
56
60
|
if name != :type && !@parent.nil? && @parent.respond_to?(name)
|
57
|
-
puts "NAME: #{name}"
|
61
|
+
puts "Settings.method_missing - NAME: #{name}"
|
58
62
|
return @parent.public_send(name, *args, &block)
|
59
63
|
end
|
60
64
|
raise KDoc::Error, 'Multiple setting values is not supported' if args.length > 1
|
@@ -123,21 +127,11 @@ module KDoc
|
|
123
127
|
decorators.each { |decorator| decorator.decorate(self, :settings) }
|
124
128
|
end
|
125
129
|
|
126
|
-
def
|
127
|
-
|
128
|
-
@key = (key || FakeOpinion.new.default_settings_key).to_s
|
129
|
-
|
130
|
-
@parent = options[:parent] if options.key?(:parent)
|
130
|
+
def build_decorators(opts)
|
131
|
+
decorator_list = opts[:decorators].nil? ? [] : opts[:decorators]
|
131
132
|
|
132
|
-
decorator_list
|
133
|
-
|
134
|
-
# This code needs to work differently, it needs to support the 3 different types
|
135
|
-
# Move the query into helpers
|
136
|
-
@decorators = decorator_list
|
137
|
-
.map(&:new)
|
133
|
+
decorator_list.map(&:new)
|
138
134
|
.select { |decorator| decorator.compatible?(self) }
|
139
|
-
|
140
|
-
@data[@key] = {}
|
141
135
|
end
|
142
136
|
end
|
143
137
|
end
|
data/lib/k_doc/table.rb
CHANGED
@@ -6,18 +6,38 @@ module KDoc
|
|
6
6
|
include KLog::Logging
|
7
7
|
|
8
8
|
attr_reader :parent
|
9
|
-
attr_reader :name
|
9
|
+
attr_reader :key # used to be called name
|
10
10
|
attr_reader :decorators
|
11
|
+
attr_reader :block
|
11
12
|
|
12
|
-
def initialize(data,
|
13
|
-
|
13
|
+
def initialize(parent, data, key = nil, **opts, &block)
|
14
|
+
@parent = parent
|
15
|
+
@data = data
|
16
|
+
@key = (key || FakeOpinion.new.default_table_key).to_s
|
17
|
+
@data[@key] = { 'fields' => [], 'rows' => [] }
|
18
|
+
@decorators = build_decorators(opts)
|
19
|
+
@block = block
|
20
|
+
end
|
21
|
+
|
22
|
+
def fire_eval
|
23
|
+
return unless block
|
24
|
+
|
25
|
+
instance_eval(&block)
|
14
26
|
|
15
27
|
@has_executed_field_decorators = false
|
16
28
|
@has_executed_row_decorators = false
|
17
29
|
|
18
|
-
instance_eval(&block) if block_given?
|
19
|
-
|
20
30
|
run_decorators(:update_rows)
|
31
|
+
|
32
|
+
# rubocop:disable Style/RescueStandardError
|
33
|
+
rescue => e
|
34
|
+
# rubocop:enable Style/RescueStandardError
|
35
|
+
log.error("Table error for key: #{@key} - #{e.message}")
|
36
|
+
raise
|
37
|
+
end
|
38
|
+
|
39
|
+
def context
|
40
|
+
parent.context
|
21
41
|
end
|
22
42
|
|
23
43
|
# Pass fields in using the following format
|
@@ -27,7 +47,7 @@ module KDoc
|
|
27
47
|
def fields(*field_definitions)
|
28
48
|
field_definitions = *field_definitions[0] if field_definitions.length == 1 && field_definitions[0].is_a?(Array)
|
29
49
|
|
30
|
-
fields = @data[@
|
50
|
+
fields = @data[@key]['fields']
|
31
51
|
|
32
52
|
field_definitions.each do |fd|
|
33
53
|
fields << if fd.is_a?(String) || fd.is_a?(Symbol)
|
@@ -42,7 +62,7 @@ module KDoc
|
|
42
62
|
|
43
63
|
# rubocop:disable Metrics/AbcSize
|
44
64
|
def row(*args, **named_args)
|
45
|
-
fields = @data[@
|
65
|
+
fields = @data[@key]['fields']
|
46
66
|
|
47
67
|
raise KType::Error, "To many values for row, argument #{args.length}" if args.length > fields.length
|
48
68
|
|
@@ -59,31 +79,31 @@ module KDoc
|
|
59
79
|
end
|
60
80
|
|
61
81
|
# Override with named args
|
62
|
-
named_args.each_key do |
|
63
|
-
row[
|
82
|
+
named_args.each_key do |arg_name|
|
83
|
+
row[arg_name.to_s] = named_args[arg_name] # KUtil.data.clean_symbol(named_args[key])
|
64
84
|
end
|
65
85
|
|
66
|
-
@data[@
|
86
|
+
@data[@key]['rows'] << row
|
67
87
|
row
|
68
88
|
end
|
69
89
|
# rubocop:enable Metrics/AbcSize
|
70
90
|
|
71
91
|
# rubocop:disable Naming/AccessorMethodName
|
72
92
|
def get_fields
|
73
|
-
@data[@
|
93
|
+
@data[@key]['fields']
|
74
94
|
end
|
75
95
|
|
76
96
|
def get_rows
|
77
|
-
@data[@
|
97
|
+
@data[@key]['rows']
|
78
98
|
end
|
79
99
|
# rubocop:enable Naming/AccessorMethodName
|
80
100
|
|
81
101
|
def internal_data
|
82
|
-
@data[@
|
102
|
+
@data[@key]
|
83
103
|
end
|
84
104
|
|
85
105
|
def find_row(key, value)
|
86
|
-
@data[@
|
106
|
+
@data[@key]['rows'].find { |r| r[key] == value }
|
87
107
|
end
|
88
108
|
|
89
109
|
# Field definition
|
@@ -134,24 +154,12 @@ module KDoc
|
|
134
154
|
end
|
135
155
|
# rubocop:enable Metrics/CyclomaticComplexity
|
136
156
|
|
137
|
-
|
138
|
-
|
139
|
-
@data = data
|
140
|
-
@name = (name || FakeOpinion.new.default_table_key.to_s).to_s
|
141
|
-
|
142
|
-
@parent = options[:parent] if !options.nil? && options.key?(:parent)
|
157
|
+
def build_decorators(opts)
|
158
|
+
decorator_list = opts[:decorators].nil? ? [] : opts[:decorators]
|
143
159
|
|
144
|
-
|
145
|
-
# Move the query into helpers
|
146
|
-
decorator_list = options[:decorators].nil? ? [] : options[:decorators]
|
147
|
-
|
148
|
-
@decorators = decorator_list
|
149
|
-
.map(&:new)
|
160
|
+
decorator_list.map(&:new)
|
150
161
|
.select { |decorator| decorator.compatible?(self) }
|
151
|
-
|
152
|
-
@data[@name] = { 'fields' => [], 'rows' => [] }
|
153
162
|
end
|
154
|
-
# rubocop:enable Metrics/AbcSize
|
155
163
|
|
156
164
|
def respond_to_missing?(name, *_args, &_block)
|
157
165
|
(!@parent.nil? && @parent.respond_to?(name, true)) || super
|
data/lib/k_doc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -132,7 +132,6 @@ files:
|
|
132
132
|
- lib/k_doc/mixins/guarded.rb
|
133
133
|
- lib/k_doc/mixins/taggable.rb
|
134
134
|
- lib/k_doc/model.rb
|
135
|
-
- lib/k_doc/model_backup.rb
|
136
135
|
- lib/k_doc/settings.rb
|
137
136
|
- lib/k_doc/table.rb
|
138
137
|
- lib/k_doc/version.rb
|
data/lib/k_doc/model_backup.rb
DELETED
@@ -1,191 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# module KDoc
|
4
|
-
# # Model is a DSL for modeling general purpose data objects
|
5
|
-
# #
|
6
|
-
# # A model can have
|
7
|
-
# # - 0 or more named setting groups each with their key/value pairs
|
8
|
-
# # - 0 or more named table groups each with their own columns and rows
|
9
|
-
# #
|
10
|
-
# # A settings group without a name will default to name: :settings
|
11
|
-
# # A table group without a name will default to name: :table
|
12
|
-
# class Model < KDoc::Container
|
13
|
-
# include KLog::Logging
|
14
|
-
|
15
|
-
# # include KType::Error
|
16
|
-
# # include KType::ManagedState
|
17
|
-
# # include KType::NamedFolder
|
18
|
-
# # include KType::LayeredFolder
|
19
|
-
|
20
|
-
# attr_reader :options
|
21
|
-
|
22
|
-
# # Create document
|
23
|
-
# #
|
24
|
-
# # @param [String|Symbol] name Name of the document
|
25
|
-
# # @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new.default_model_type if not set
|
26
|
-
# # @param default: Default value (using named params), as above
|
27
|
-
# def initialize(key = nil, **options, &block)
|
28
|
-
# super(key: key, type: options[:type] || KDoc.opinion.default_model_type) # , namespace: options[:namespace], project_key: options[:project_key])
|
29
|
-
# initialize_attributes(**options)
|
30
|
-
|
31
|
-
# @block = block if block_given?
|
32
|
-
# end
|
33
|
-
|
34
|
-
# # NOTE: Can this be moved out of the is object?
|
35
|
-
# def execute_block(run_actions: nil)
|
36
|
-
# return if @block.nil?
|
37
|
-
|
38
|
-
# # The DSL actions method will only run on run_actions: true
|
39
|
-
# @run_actions = run_actions
|
40
|
-
|
41
|
-
# instance_eval(&@block)
|
42
|
-
|
43
|
-
# on_action if run_actions && respond_to?(:on_action)
|
44
|
-
# # rescue KDoc::Error => e
|
45
|
-
# # puts('KDoc::Error in document')
|
46
|
-
# # puts "key #{unique_key}"
|
47
|
-
# # # puts "file #{KUtil.data.console_file_hyperlink(resource.file, resource.file)}"
|
48
|
-
# # puts(e.message)
|
49
|
-
# # @error = e
|
50
|
-
# # raise
|
51
|
-
# rescue StandardError => e
|
52
|
-
# log.error('Standard error in document')
|
53
|
-
# # puts "key #{unique_key}"
|
54
|
-
# # puts "file #{KUtil.data.console_file_hyperlink(resource.file, resource.file)}"
|
55
|
-
# log.error(e.message)
|
56
|
-
# @error = e
|
57
|
-
# # log.exception exception2
|
58
|
-
# raise
|
59
|
-
# ensure
|
60
|
-
# @run_actions = nil
|
61
|
-
# end
|
62
|
-
|
63
|
-
# def settings(key = nil, **options, &block)
|
64
|
-
# options ||= {}
|
65
|
-
|
66
|
-
# opts = {}.merge(@options) # Data Options
|
67
|
-
# .merge(options) # Settings Options
|
68
|
-
# .merge(parent: self)
|
69
|
-
|
70
|
-
# settings_instance(@data, key, **opts, &block)
|
71
|
-
# # settings.run_decorators(opts)
|
72
|
-
# end
|
73
|
-
|
74
|
-
# def table(key = :table, **options, &block)
|
75
|
-
# # NEED to add support for run_decorators I think
|
76
|
-
# options.merge(parent: self)
|
77
|
-
# table_instance(@data, key, **options, &block)
|
78
|
-
# end
|
79
|
-
# alias rows table
|
80
|
-
|
81
|
-
# # Sweet add-on would be builders
|
82
|
-
# # def builder(key, &block)
|
83
|
-
# # # example
|
84
|
-
# # KDoc::Builder::Shotstack.new(@data, key, &block)
|
85
|
-
# # end
|
86
|
-
|
87
|
-
# # Need to move this down to container
|
88
|
-
# # Need to use some sort of cache invalidation to know if the internal data has been altered
|
89
|
-
# def odata
|
90
|
-
# @odata ||= data_struct
|
91
|
-
# end
|
92
|
-
|
93
|
-
# def oraw
|
94
|
-
# @oraw ||= raw_data_struct
|
95
|
-
# end
|
96
|
-
|
97
|
-
# def data_struct
|
98
|
-
# KUtil.data.to_open_struct(data)
|
99
|
-
# end
|
100
|
-
# # alias d data_struct
|
101
|
-
|
102
|
-
# def raw_data_struct
|
103
|
-
# KUtil.data.to_open_struct(raw_data)
|
104
|
-
# end
|
105
|
-
|
106
|
-
# def get_node_type(node_name)
|
107
|
-
# node_name = KUtil.data.clean_symbol(node_name)
|
108
|
-
# node_data = @data[node_name]
|
109
|
-
|
110
|
-
# raise KDoc::Error, "Node not found: #{node_name}" if node_data.nil?
|
111
|
-
|
112
|
-
# if node_data.keys.length == 2 && (node_data.key?('fields') && node_data.key?('rows'))
|
113
|
-
# :table
|
114
|
-
# else
|
115
|
-
# :settings
|
116
|
-
# end
|
117
|
-
# end
|
118
|
-
|
119
|
-
# # Removes any meta data eg. "fields" from a table and just returns the raw data
|
120
|
-
# # REFACTOR: IT MAY BE BEST TO MOVE raw_data into each of the node_types
|
121
|
-
# def raw_data
|
122
|
-
# # REFACT, what if this is CSV, meaning it is just an array?
|
123
|
-
# # add specs
|
124
|
-
# result = data
|
125
|
-
|
126
|
-
# result.each_key do |key|
|
127
|
-
# # ANTI: get_node_type uses @data while we are using @data.clone here
|
128
|
-
# result[key] = if get_node_type(key) == :table
|
129
|
-
# # Old format was to keep the rows and delete the fields
|
130
|
-
# # Now the format is to pull the row_value up to the key and remove rows and fields
|
131
|
-
# # result[key].delete('fields')
|
132
|
-
# result[key]['rows']
|
133
|
-
# else
|
134
|
-
# result[key]
|
135
|
-
# end
|
136
|
-
# end
|
137
|
-
|
138
|
-
# result
|
139
|
-
# end
|
140
|
-
|
141
|
-
# # Move this out to the logger function when it has been refactor
|
142
|
-
# def debug(include_header: false)
|
143
|
-
# debug_header if include_header
|
144
|
-
|
145
|
-
# # tp dsls.values, :k_key, :k_type, :state, :save_at, :last_at, :data, :last_data, :source, { :file => { :width => 150 } }
|
146
|
-
# # puts JSON.pretty_generate(data)
|
147
|
-
# log.o(raw_data_struct)
|
148
|
-
# end
|
149
|
-
|
150
|
-
# def debug_header
|
151
|
-
# log.heading self.class.name
|
152
|
-
# debug_container
|
153
|
-
# debug_header_keys
|
154
|
-
|
155
|
-
# log.line
|
156
|
-
# end
|
157
|
-
|
158
|
-
# def debug_header_keys
|
159
|
-
# options&.keys&.reject { |k| k == :namespace }&.each do |key|
|
160
|
-
# log.kv key, options[key]
|
161
|
-
# end
|
162
|
-
# end
|
163
|
-
|
164
|
-
# private
|
165
|
-
|
166
|
-
# def initialize_attributes(**options)
|
167
|
-
# @options = options || {}
|
168
|
-
# # Is parent a part of model, or is it part of k_manager::document_taggable (NOT SURE IF IT IS USED YET)
|
169
|
-
# @parent = slice_option(:parent)
|
170
|
-
|
171
|
-
# # Most documents live within a hash, some tabular documents such as CSV will use an []
|
172
|
-
# @data = slice_option(:default_data) || {}
|
173
|
-
# end
|
174
|
-
|
175
|
-
# def settings_instance(data, key, **options, &block)
|
176
|
-
# KDoc.opinion.settings_class.new(data, key, **options, &block)
|
177
|
-
# end
|
178
|
-
|
179
|
-
# def table_instance(data, key, **options, &block)
|
180
|
-
# KDoc.opinion.table_class.new(data, key, **options, &block)
|
181
|
-
# end
|
182
|
-
|
183
|
-
# def slice_option(key)
|
184
|
-
# return nil unless @options.key?(key)
|
185
|
-
|
186
|
-
# result = @options[key]
|
187
|
-
# @options.delete(key)
|
188
|
-
# result
|
189
|
-
# end
|
190
|
-
# end
|
191
|
-
# end
|