k_doc 0.0.22 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/directors/director.rb +1 -1
- data/.builders/initializers/configure_builder.rb +3 -3
- data/.rubocop.yml +9 -13
- data/README.md +0 -11
- data/lib/k_doc/action.rb +28 -0
- data/lib/k_doc/container.rb +5 -2
- data/lib/k_doc/fake_opinion.rb +4 -1
- data/lib/k_doc/mixins/block_processor.rb +21 -1
- data/lib/k_doc/mixins/guarded.rb +13 -1
- data/lib/k_doc/mixins/importable.rb +52 -0
- data/lib/k_doc/mixins/taggable.rb +10 -26
- data/lib/k_doc/model.rb +2 -1
- data/lib/k_doc/version.rb +1 -1
- data/lib/k_doc.rb +8 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e43e7408a95cf8bf701922e28ef33115d12dd66dd77af00ca1f8b0e492c0952d
|
4
|
+
data.tar.gz: 74506c87934ece30b1e5e37b111fc6ff347ae277b8085aff50a0dce698946b7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92427570dd666fa9d679472fe48dd79771a877209ddd80df4143db1b03cf75ed587af99b1bca3f39e4f039e6ffa4e074c2173f19f8047811a17ca6c7d25cf248
|
7
|
+
data.tar.gz: 553d2c7d0bbf1304b7814e3196b3bf4d90a413c920c2209865918dd3351edabcd6fdad345cb4deb53fb5cb2678b637992caf00a7349218030a37518605071206
|
@@ -1,5 +1,5 @@
|
|
1
1
|
KBuilder.reset(:gem)
|
2
|
-
|
2
|
+
KConfig.configure(:gem) do |config|
|
3
3
|
# config.template_folders.add(:global , '~/dev/kgems/k_templates/definitions/genesis')
|
4
4
|
config.target_folders.add(:root , File.expand_path('..', Dir.getwd))
|
5
5
|
config.target_folders.add(:lib , :root, 'lib', 'k_doc')
|
@@ -7,14 +7,14 @@ KBuilder.configure(:gem) do |config|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
KBuilder.reset(:design_patterns)
|
10
|
-
|
10
|
+
KConfig.configure(:design_patterns) do |config|
|
11
11
|
config.template_folders.add(:global , '~/dev/kgems/k_templates/templates/ruby_design_patterns')
|
12
12
|
config.target_folders.add(:root , File.expand_path('..', Dir.getwd))
|
13
13
|
config.target_folders.add(:lib , :root, 'lib', 'k_doc')
|
14
14
|
config.target_folders.add(:spec , :root, 'spec', 'k_doc')
|
15
15
|
end
|
16
16
|
|
17
|
-
#
|
17
|
+
# KConfig.configuration(:gem).debug
|
18
18
|
|
19
19
|
# def builder
|
20
20
|
# @builder ||= KBuilder::BaseBuilder.init
|
data/.rubocop.yml
CHANGED
@@ -44,15 +44,20 @@ 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
|
+
Exclude:
|
60
|
+
- "**/spec/**/*"
|
56
61
|
Metrics/ClassLength:
|
57
62
|
Enabled: false
|
58
63
|
Metrics/ModuleLength:
|
@@ -63,23 +68,14 @@ Naming/MemoizedInstanceVariableName:
|
|
63
68
|
Naming/VariableNumber:
|
64
69
|
Exclude:
|
65
70
|
- "**/spec/**/*"
|
66
|
-
Style/EmptyMethod:
|
67
|
-
Exclude:
|
68
|
-
- "**/spec/**/*"
|
69
71
|
Metrics/ParameterLists:
|
70
72
|
Exclude:
|
71
73
|
- "**/spec/**/*"
|
72
74
|
Layout/EmptyLineBetweenDefs:
|
73
75
|
Exclude:
|
74
76
|
- "**/spec/**/*"
|
75
|
-
|
76
77
|
Lint/AmbiguousBlockAssociation:
|
77
78
|
Exclude:
|
78
79
|
- "**/spec/**/*"
|
79
|
-
|
80
|
-
Style/AccessorGrouping:
|
81
|
-
Enabled: false
|
82
|
-
|
83
80
|
Layout/SpaceBeforeComma:
|
84
81
|
Enabled: false
|
85
|
-
# My Preferences - End
|
data/README.md
CHANGED
@@ -52,17 +52,6 @@ Checkout the repo
|
|
52
52
|
git clone klueless-io/k_doc
|
53
53
|
```
|
54
54
|
|
55
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
56
|
-
|
57
|
-
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
-
|
59
|
-
```bash
|
60
|
-
bin/console
|
61
|
-
|
62
|
-
Aaa::Bbb::Program.execute()
|
63
|
-
# => ""
|
64
|
-
```
|
65
|
-
|
66
55
|
`k_doc` is setup with Guard, run `guard`, this will watch development file changes and run tests automatically, if successful, it will then run rubocop for style quality.
|
67
56
|
|
68
57
|
To release a new version, update the version number in `version.rb`, build the gem and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/lib/k_doc/action.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDoc
|
4
|
+
# Action is a DSL for modeling JSON data objects
|
5
|
+
class Action < KDoc::Container
|
6
|
+
attr_reader :file
|
7
|
+
|
8
|
+
# Simple Ruby Action
|
9
|
+
#
|
10
|
+
# @param [String|Symbol] name Name of the document
|
11
|
+
# @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new.default_action_type if not set
|
12
|
+
# @param default: Default value (using named params), as above
|
13
|
+
# @param [Proc] block The block is stored and accessed different types in the document loading workflow.
|
14
|
+
def initialize(key = nil, **opts, &_block)
|
15
|
+
super(**{ key: key }.merge(opts))
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def default_data_type
|
21
|
+
String
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_container_type
|
25
|
+
:action
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/k_doc/container.rb
CHANGED
@@ -9,6 +9,7 @@ module KDoc
|
|
9
9
|
include KDoc::Taggable
|
10
10
|
include KDoc::Datum
|
11
11
|
include KDoc::BlockProcessor
|
12
|
+
include KDoc::Importable
|
12
13
|
|
13
14
|
attr_reader :opts
|
14
15
|
|
@@ -24,6 +25,7 @@ module KDoc
|
|
24
25
|
|
25
26
|
initialize_tag(opts)
|
26
27
|
initialize_data(opts)
|
28
|
+
initialize_import(opts) if respond_to?(:initialize_import)
|
27
29
|
initialize_block(opts, &block)
|
28
30
|
end
|
29
31
|
|
@@ -32,11 +34,12 @@ module KDoc
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def default_data_type
|
35
|
-
Hash
|
37
|
+
@default_data_type ||= Hash
|
36
38
|
end
|
37
39
|
|
38
40
|
def debug
|
39
|
-
|
41
|
+
debug_taggable
|
42
|
+
debug_block_processor
|
40
43
|
debug_errors
|
41
44
|
end
|
42
45
|
|
data/lib/k_doc/fake_opinion.rb
CHANGED
@@ -7,6 +7,7 @@ module KDoc
|
|
7
7
|
# how I want to implement this
|
8
8
|
# Need to look at the configuration patterns, this is really a configuration
|
9
9
|
class FakeOpinion
|
10
|
+
attr_accessor :default_action_type
|
10
11
|
attr_accessor :default_model_type
|
11
12
|
attr_accessor :default_csv_type
|
12
13
|
attr_accessor :default_json_type
|
@@ -19,7 +20,9 @@ module KDoc
|
|
19
20
|
attr_accessor :table_class
|
20
21
|
|
21
22
|
def initialize
|
22
|
-
@default_model_type = :entity
|
23
|
+
# @default_model_type = :entity
|
24
|
+
@default_action_type = :action
|
25
|
+
@default_model_type = :kdoc
|
23
26
|
@default_csv_type = :csv
|
24
27
|
@default_json_type = :json
|
25
28
|
@default_yaml_type = :yaml
|
@@ -6,9 +6,19 @@ module KDoc
|
|
6
6
|
# Rename: BlockProcessor
|
7
7
|
module BlockProcessor
|
8
8
|
attr_accessor :block
|
9
|
+
attr_accessor :block_state
|
9
10
|
|
10
11
|
def initialize_block(_opts, &block)
|
11
12
|
@block = block if block_given?
|
13
|
+
@block_state = :initial
|
14
|
+
end
|
15
|
+
|
16
|
+
def evaluated?
|
17
|
+
@block_state == :evaluated || @block_state == :actioned
|
18
|
+
end
|
19
|
+
|
20
|
+
def actioned?
|
21
|
+
@block_state == :actioned
|
12
22
|
end
|
13
23
|
|
14
24
|
def execute_block(run_actions: nil)
|
@@ -20,6 +30,7 @@ module KDoc
|
|
20
30
|
return if @block.nil?
|
21
31
|
|
22
32
|
instance_eval(&@block)
|
33
|
+
@block_state = :evaluated
|
23
34
|
rescue StandardError => e
|
24
35
|
log.error('Standard error in document')
|
25
36
|
# puts "key #{unique_key}"
|
@@ -32,7 +43,10 @@ module KDoc
|
|
32
43
|
def run_on_action
|
33
44
|
return if @block.nil?
|
34
45
|
|
35
|
-
|
46
|
+
if respond_to?(:on_action)
|
47
|
+
on_action
|
48
|
+
@block_state = :actioned
|
49
|
+
end
|
36
50
|
rescue StandardError => e
|
37
51
|
log.error('Standard error while running actions')
|
38
52
|
# puts "key #{unique_key}"
|
@@ -41,5 +55,11 @@ module KDoc
|
|
41
55
|
@error = e
|
42
56
|
raise
|
43
57
|
end
|
58
|
+
|
59
|
+
def debug_block_processor
|
60
|
+
log.kv 'block_state', block_state , debug_pad_size if respond_to?(:block_state)
|
61
|
+
log.kv 'evaluated' , evaluated? , debug_pad_size if respond_to?(:evaluated?)
|
62
|
+
log.kv 'actioned' , actioned? , debug_pad_size if respond_to?(:actioned?)
|
63
|
+
end
|
44
64
|
end
|
45
65
|
end
|
data/lib/k_doc/mixins/guarded.rb
CHANGED
@@ -7,7 +7,7 @@ module KDoc
|
|
7
7
|
module Guarded
|
8
8
|
Guard = Struct.new(:type, :message)
|
9
9
|
|
10
|
-
def guard(message)
|
10
|
+
def guard(message, log: false)
|
11
11
|
errors << Guard.new(:guard, message)
|
12
12
|
end
|
13
13
|
|
@@ -24,6 +24,14 @@ module KDoc
|
|
24
24
|
errors.map(&:message)
|
25
25
|
end
|
26
26
|
|
27
|
+
def error_hash
|
28
|
+
errors.map(&:to_h)
|
29
|
+
end
|
30
|
+
|
31
|
+
# TODO: Add these predicates
|
32
|
+
# def errors?
|
33
|
+
# def warnings?
|
34
|
+
|
27
35
|
def valid?
|
28
36
|
errors.length.zero?
|
29
37
|
end
|
@@ -34,5 +42,9 @@ module KDoc
|
|
34
42
|
log.error error.message if error.type == :guard
|
35
43
|
end
|
36
44
|
end
|
45
|
+
|
46
|
+
def clear_errors
|
47
|
+
errors.clear
|
48
|
+
end
|
37
49
|
end
|
38
50
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDoc
|
4
|
+
# Alow documents to import data from other sources (usually other documents)
|
5
|
+
|
6
|
+
module Importable
|
7
|
+
include KLog::Logging
|
8
|
+
|
9
|
+
attr_reader :importer
|
10
|
+
attr_reader :imports
|
11
|
+
|
12
|
+
# Imports are provided via an options hash, these imports are remove from the hash as they are read
|
13
|
+
#
|
14
|
+
# Any container can import data from an existing container via the import options
|
15
|
+
# rubocop:disable Style/OpenStructUse
|
16
|
+
def initialize_import(opts)
|
17
|
+
# log.error 'initialize_import'
|
18
|
+
@importer = opts.delete(:importer)
|
19
|
+
@imports = OpenStruct.new
|
20
|
+
end
|
21
|
+
# rubocop:enable Style/OpenStructUse
|
22
|
+
|
23
|
+
def call_importer
|
24
|
+
return unless importer
|
25
|
+
|
26
|
+
importer.call(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
# def import(tag)
|
30
|
+
# KManager.find_document(tag)
|
31
|
+
# end
|
32
|
+
|
33
|
+
# def import_data(tag, as: :document)
|
34
|
+
# doc = KManager.find_document(tag)
|
35
|
+
|
36
|
+
# return nil unless doc&.data
|
37
|
+
|
38
|
+
# # log.error 'about to import'
|
39
|
+
# doc.debug(include_header: true)
|
40
|
+
|
41
|
+
# return KUtil.data.to_open_struct(doc.data) if %i[open_struct ostruct].include?(as)
|
42
|
+
|
43
|
+
# doc.data
|
44
|
+
# end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def debug_importable
|
49
|
+
# log.kv 'class type' , self.class.name , debug_pad_size
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -44,6 +44,7 @@ module KDoc
|
|
44
44
|
@type ||= @tag_options.delete(:type) || default_container_type
|
45
45
|
end
|
46
46
|
|
47
|
+
# TODO: rename to area (or area root namespace)
|
47
48
|
# Project name
|
48
49
|
#
|
49
50
|
# Examples
|
@@ -66,39 +67,22 @@ module KDoc
|
|
66
67
|
@namespace = ns.is_a?(Array) ? ns : [ns]
|
67
68
|
end
|
68
69
|
|
69
|
-
# # Internal data object
|
70
|
-
# def data
|
71
|
-
# @data ||= @tag_options.delete(:data) || @tag_options.delete(:default_data) || default_data_value
|
72
|
-
# # Settings and Table on Model needed access to @data for modification, I don't think this should be a clone
|
73
|
-
# # never return the original data object, but at the same time
|
74
|
-
# # do not re-clone it every time this accessor is called.
|
75
|
-
# # @clone_data ||= @data.clone
|
76
|
-
# end
|
77
|
-
|
78
|
-
# Implement in container
|
79
|
-
# def default_container_type
|
80
|
-
# :container
|
81
|
-
# end
|
82
|
-
|
83
|
-
# def default_data_value
|
84
|
-
# {}
|
85
|
-
# end
|
86
|
-
|
87
70
|
protected
|
88
71
|
|
89
72
|
# rubocop:disable Metrics/AbcSize
|
90
|
-
def
|
91
|
-
log.kv 'tag'
|
92
|
-
log.kv 'project'
|
93
|
-
log.kv 'namespace', namespace
|
94
|
-
log.kv 'key'
|
95
|
-
log.kv 'type'
|
73
|
+
def debug_taggable
|
74
|
+
log.kv 'tag' , tag , debug_pad_size
|
75
|
+
log.kv 'project' , project , debug_pad_size unless project.nil? || project.empty?
|
76
|
+
log.kv 'namespace' , namespace , debug_pad_size unless namespace.nil? || namespace.empty?
|
77
|
+
log.kv 'key' , key , debug_pad_size
|
78
|
+
log.kv 'type' , type , debug_pad_size
|
79
|
+
log.kv 'class type' , self.class.name , debug_pad_size
|
96
80
|
# log.kv 'error' , error , debug_kv_pad_size
|
97
81
|
end
|
98
82
|
# rubocop:enable Metrics/AbcSize
|
99
83
|
|
100
84
|
def debug_pad_size
|
101
|
-
@debug_pad_size ||= @tag_options.delete(:debug_pad_size) ||
|
85
|
+
@debug_pad_size ||= @tag_options.delete(:debug_pad_size) || 20
|
102
86
|
end
|
103
87
|
|
104
88
|
private
|
@@ -107,8 +91,8 @@ module KDoc
|
|
107
91
|
values = []
|
108
92
|
values << project if project
|
109
93
|
values += namespace
|
110
|
-
values << type if type
|
111
94
|
values << key
|
95
|
+
values << type if type
|
112
96
|
values -= [nil, '']
|
113
97
|
@tag = values.join('_').to_sym
|
114
98
|
end
|
data/lib/k_doc/model.rb
CHANGED
data/lib/k_doc/version.rb
CHANGED
data/lib/k_doc.rb
CHANGED
@@ -15,8 +15,10 @@ require 'k_doc/mixins/taggable'
|
|
15
15
|
require 'k_doc/mixins/datum'
|
16
16
|
require 'k_doc/mixins/block_processor'
|
17
17
|
require 'k_doc/mixins/composable_components'
|
18
|
+
require 'k_doc/mixins/importable'
|
18
19
|
require 'k_doc/container'
|
19
20
|
# require 'k_doc/data'
|
21
|
+
require 'k_doc/action'
|
20
22
|
require 'k_doc/csv_doc'
|
21
23
|
require 'k_doc/json_doc'
|
22
24
|
require 'k_doc/yaml_doc'
|
@@ -52,6 +54,12 @@ module KDoc
|
|
52
54
|
model(key, **{ type: :app_settings }.merge(**options), &block)
|
53
55
|
end
|
54
56
|
|
57
|
+
def action(key = nil, **options, &block)
|
58
|
+
doc = KDoc::Action.new(key, **options, &block)
|
59
|
+
doc.execute_block
|
60
|
+
doc
|
61
|
+
end
|
62
|
+
|
55
63
|
def csv(key = nil, **options, &block)
|
56
64
|
doc = KDoc::CsvDoc.new(key, **options, &block)
|
57
65
|
doc.execute_block
|
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.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:
|
11
|
+
date: 2022-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- hooks/update-version
|
120
120
|
- k_doc.gemspec
|
121
121
|
- lib/k_doc.rb
|
122
|
+
- lib/k_doc/action.rb
|
122
123
|
- lib/k_doc/container.rb
|
123
124
|
- lib/k_doc/csv_doc.rb
|
124
125
|
- lib/k_doc/decorators/settings_decorator.rb
|
@@ -129,6 +130,7 @@ files:
|
|
129
130
|
- lib/k_doc/mixins/composable_components.rb
|
130
131
|
- lib/k_doc/mixins/datum.rb
|
131
132
|
- lib/k_doc/mixins/guarded.rb
|
133
|
+
- lib/k_doc/mixins/importable.rb
|
132
134
|
- lib/k_doc/mixins/taggable.rb
|
133
135
|
- lib/k_doc/model.rb
|
134
136
|
- lib/k_doc/model_backup.rb
|
@@ -156,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
158
|
- !ruby/object:Gem::Version
|
157
159
|
version: '0'
|
158
160
|
requirements: []
|
159
|
-
rubygems_version: 3.2.
|
161
|
+
rubygems_version: 3.2.33
|
160
162
|
signing_key:
|
161
163
|
specification_version: 4
|
162
164
|
summary: KDoc provides a document in the form a DSL that contains flexible key/value
|