k_doc 0.0.7 → 0.0.13
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/CODE_OF_CONDUCT.md +6 -6
- data/README.md +2 -4
- data/STORIES.md +18 -8
- data/ToDo.md +91 -0
- data/k_doc.gemspec +3 -0
- data/lib/k_doc.rb +13 -12
- data/lib/k_doc/container.rb +55 -0
- data/lib/k_doc/{document.rb → data.rb} +14 -25
- data/lib/k_doc/decorators/settings_decorator.rb +24 -0
- data/lib/k_doc/decorators/table_decorator.rb +31 -0
- data/lib/k_doc/fake_opinion.rb +2 -2
- data/lib/k_doc/settings.rb +28 -18
- data/lib/k_doc/table.rb +55 -2
- data/lib/k_doc/util.rb +8 -2
- data/lib/k_doc/version.rb +1 -1
- metadata +49 -4
- data/lib/k_doc/logging.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c5aa8cc7a7c428e9e15b9a705b9783cfb977b7d49706d3faf95ef17137b2042
|
4
|
+
data.tar.gz: 794988e7fb3451fc307659e6b790cff4b5903bdd708d8172886eaa906bbed716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f3ba7e70149ad585bdd2c8c615a6d21d5dca3b0004c1b9a50b974f2eeeb36637fab456fa9cdc15cf416122864e55ef5f871d2eafaff6f2b1f38ec7b7a606ea7
|
7
|
+
data.tar.gz: 6cd090ae8c0d409e76d830b9370ab292a8678e434c7e13ef49ab24e7aea500a68fab99ac72fac132dd962cf6b1b4a0eb809e8fca79f5e6506f21fb2656842107
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -11,7 +11,7 @@ orientation.
|
|
11
11
|
|
12
12
|
## Our Standards
|
13
13
|
|
14
|
-
Examples of
|
14
|
+
Examples of behaviour that contributes to creating a positive environment
|
15
15
|
include:
|
16
16
|
|
17
17
|
- Using welcoming and inclusive language
|
@@ -20,7 +20,7 @@ include:
|
|
20
20
|
- Focusing on what is best for the community
|
21
21
|
- Showing empathy towards other community members
|
22
22
|
|
23
|
-
Examples of unacceptable
|
23
|
+
Examples of unacceptable behaviour by participants include:
|
24
24
|
|
25
25
|
- The use of sexualized language or imagery and unwelcome sexual attention or
|
26
26
|
advances
|
@@ -34,13 +34,13 @@ Examples of unacceptable behavior by participants include:
|
|
34
34
|
## Our Responsibilities
|
35
35
|
|
36
36
|
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
|
38
|
-
response to any instances of unacceptable
|
37
|
+
behaviour and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behaviour.
|
39
39
|
|
40
40
|
Project maintainers have the right and responsibility to remove, edit, or
|
41
41
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
42
|
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other
|
43
|
+
permanently any contributor for other behaviours that they deem inappropriate,
|
44
44
|
threatening, offensive, or harmful.
|
45
45
|
|
46
46
|
## Scope
|
@@ -54,7 +54,7 @@ further defined and clarified by project maintainers.
|
|
54
54
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behaviour may be
|
58
58
|
reported by contacting the project team at david.cruwys@bugcrowd.com. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
data/README.md
CHANGED
@@ -68,10 +68,8 @@ Aaa::Bbb::Program.execute()
|
|
68
68
|
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).
|
69
69
|
|
70
70
|
```bash
|
71
|
-
|
72
|
-
|
73
|
-
# or push the latest gem
|
74
|
-
ls *.gem | sort -r | head -1 | xargs gem push
|
71
|
+
rake publish
|
72
|
+
rake clean
|
75
73
|
```
|
76
74
|
|
77
75
|
## Contributing
|
data/STORIES.md
CHANGED
@@ -10,22 +10,27 @@ As a Developer, I need flexible data structures defined in DSL, so can model ric
|
|
10
10
|
|
11
11
|
As a Developer, I need flexible data structures defined in DSL, so can model rich documents
|
12
12
|
|
13
|
-
|
13
|
+
## Stories and tasks
|
14
14
|
|
15
|
-
|
15
|
+
### Stories - completed
|
16
16
|
|
17
|
-
|
18
|
-
- Attach documentation to [rubydoc.info](https://rubydoc.info/github/to-do-/k_doc/master)
|
17
|
+
As a Domain Modeler, I can define flexible tabular structures, so I can access dynamic tabular arrays
|
19
18
|
|
20
|
-
|
19
|
+
- add DSL for table with columns and rows
|
20
|
+
- add support for data decorators
|
21
21
|
|
22
|
-
|
23
|
-
- Setup RuboCop action
|
22
|
+
As a Domain Modeler, I can define flexible key/value stores, so I can access settings data
|
24
23
|
|
25
|
-
|
24
|
+
- add DSL for key/value settings
|
25
|
+
- add support for data decorators
|
26
26
|
|
27
27
|
### Tasks - completed
|
28
28
|
|
29
|
+
Setup RubyGems and RubyDoc
|
30
|
+
|
31
|
+
- Build and deploy gem to [rubygems.org](https://rubygems.org/gems/k_doc)
|
32
|
+
- Attach documentation to [rubydoc.info](https://rubydoc.info/github/to-do-/k_doc/master)
|
33
|
+
|
29
34
|
Setup project management, requirement and SCRUM documents
|
30
35
|
|
31
36
|
- Setup readme file
|
@@ -33,6 +38,11 @@ Setup project management, requirement and SCRUM documents
|
|
33
38
|
- Setup a project backlog
|
34
39
|
- Setup an examples/usage document
|
35
40
|
|
41
|
+
Setup GitHub Action (test and lint)
|
42
|
+
|
43
|
+
- Setup Rspec action
|
44
|
+
- Setup RuboCop action
|
45
|
+
|
36
46
|
Setup new Ruby GEM
|
37
47
|
|
38
48
|
- Build out a standard GEM structure
|
data/ToDo.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# K Doc
|
2
|
+
|
3
|
+
> KDoc provides a document in the form a DSL that contains flexible key/value and tabular data
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'k_doc'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
gem install k_doc
|
23
|
+
```
|
24
|
+
|
25
|
+
## Stories
|
26
|
+
|
27
|
+
### Main Story
|
28
|
+
|
29
|
+
As a Developer, I need flexible data structures defined in DSL, so can model rich documents
|
30
|
+
|
31
|
+
See all [stories](./STORIES.md)
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
See all [usage examples](./USAGE.md)
|
36
|
+
|
37
|
+
### Basic Example
|
38
|
+
|
39
|
+
#### Basic example
|
40
|
+
|
41
|
+
Description for a basic example to be featured in the main README.MD file
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class SomeRuby; end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
Checkout the repo
|
50
|
+
|
51
|
+
```bash
|
52
|
+
git clone klueless-io/k_doc
|
53
|
+
```
|
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
|
+
`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
|
+
|
68
|
+
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).
|
69
|
+
|
70
|
+
```bash
|
71
|
+
gem build
|
72
|
+
gem push rspec-usecases-?.?.??.gem
|
73
|
+
# or push the latest gem
|
74
|
+
ls *.gem | sort -r | head -1 | xargs gem push
|
75
|
+
```
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/klueless-io/k_doc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
84
|
+
|
85
|
+
## Code of Conduct
|
86
|
+
|
87
|
+
Everyone interacting in the K Doc project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/klueless-io/k_doc/blob/master/CODE_OF_CONDUCT.md).
|
88
|
+
|
89
|
+
## Copyright
|
90
|
+
|
91
|
+
Copyright (c) David Cruwys. See [MIT License](LICENSE.txt) for further details.
|
data/k_doc.gemspec
CHANGED
@@ -38,7 +38,10 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.require_paths = ['lib']
|
39
39
|
# spec.extensions = ['ext/k_doc/extconf.rb']
|
40
40
|
|
41
|
+
spec.add_dependency 'activesupport' , '~> 6'
|
42
|
+
spec.add_dependency 'k_decor' , '~> 0.0.0'
|
41
43
|
spec.add_dependency 'k_log' , '~> 0.0.0'
|
44
|
+
spec.add_dependency 'k_type' , '~> 0.0.0'
|
42
45
|
spec.add_dependency 'k_util' , '~> 0.0.0'
|
43
46
|
# spec.add_dependency 'tty-box', '~> 0.5.0'
|
44
47
|
end
|
data/lib/k_doc.rb
CHANGED
@@ -2,32 +2,33 @@
|
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
4
|
|
5
|
-
require 'logger'
|
6
5
|
require 'table_print'
|
7
6
|
require 'k_log'
|
7
|
+
require 'k_type'
|
8
8
|
require 'k_util'
|
9
|
-
require '
|
10
|
-
require 'k_log/log_helper'
|
11
|
-
require 'k_log/log_util'
|
9
|
+
require 'k_decor'
|
12
10
|
|
13
11
|
require 'k_doc/version'
|
14
|
-
require 'k_doc/
|
15
|
-
require 'k_doc/
|
12
|
+
require 'k_doc/container'
|
13
|
+
require 'k_doc/data'
|
16
14
|
require 'k_doc/fake_opinion'
|
17
15
|
require 'k_doc/settings'
|
18
16
|
require 'k_doc/table'
|
19
17
|
require 'k_doc/util'
|
20
18
|
|
19
|
+
require 'k_doc/decorators/settings_decorator'
|
20
|
+
require 'k_doc/decorators/table_decorator'
|
21
|
+
|
21
22
|
module KDoc
|
22
23
|
# raise KDoc::Error, 'Sample message'
|
23
24
|
class Error < StandardError; end
|
24
25
|
|
25
26
|
class << self
|
26
|
-
# Factory method to create a new
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
# Factory method to create a new data
|
28
|
+
def data(key = nil, **options, &block)
|
29
|
+
data = KDoc::Data.new(key, **options, &block)
|
30
|
+
data.execute_block
|
31
|
+
data
|
31
32
|
end
|
32
33
|
|
33
34
|
attr_accessor :opinion
|
@@ -43,5 +44,5 @@ if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
|
|
43
44
|
namespace = 'KDoc::Version'
|
44
45
|
file_path = $LOADED_FEATURES.find { |f| f.include?('k_doc/version') }
|
45
46
|
version = KDoc::VERSION.ljust(9)
|
46
|
-
puts "#{namespace.ljust(
|
47
|
+
puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
|
47
48
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDoc
|
4
|
+
# A container acts a base data object for any data requires tagging such as
|
5
|
+
# unique key, type and namespace.
|
6
|
+
class Container
|
7
|
+
# include KLog::Logging
|
8
|
+
|
9
|
+
attr_reader :key
|
10
|
+
attr_reader :type
|
11
|
+
attr_reader :namespace
|
12
|
+
attr_reader :project_key
|
13
|
+
attr_reader :error
|
14
|
+
|
15
|
+
# Create container for storing data/documents.
|
16
|
+
#
|
17
|
+
# Any container can be uniquely identified via it's
|
18
|
+
# key, type, namespace and project_key attributes
|
19
|
+
#
|
20
|
+
# @param [Hash] **opts The options
|
21
|
+
# @option opts [String|Symbol] name Name of the container
|
22
|
+
# @option opts [String|Symbol] type Type of the container, defaults to KDoc:: FakeOpinion.new.default_document_type if not set
|
23
|
+
# @option opts [String|Symbol] namespace Namespace that the container belongs to
|
24
|
+
# @option opts [String|Symbol] project_key Project that the container belongs to
|
25
|
+
def initialize(**opts)
|
26
|
+
@key = opts[:key] || SecureRandom.alphanumeric(4)
|
27
|
+
@type = opts[:type] || KDoc.opinion.default_document_type
|
28
|
+
@namespace = opts[:namespace] || ''
|
29
|
+
@project_key = opts[:project_key] || ''
|
30
|
+
|
31
|
+
# Old name is default_data, wonder if I still need that idea?
|
32
|
+
# Most documents live within a hash, some tabular documents such as CSV will use an []
|
33
|
+
# @data = slice_option(:default_data) || {}
|
34
|
+
@data = opts[:data] || {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def unique_key
|
38
|
+
@unique_key ||= KDoc.util.build_unique_key(key, type, namespace, project_key)
|
39
|
+
end
|
40
|
+
|
41
|
+
def debug_header
|
42
|
+
log.kv 'key', key
|
43
|
+
log.kv 'type', type
|
44
|
+
log.kv 'namespace', namespace
|
45
|
+
log.kv 'project_key', namespace
|
46
|
+
log.kv 'error', error
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_writer :data
|
50
|
+
|
51
|
+
def data
|
52
|
+
@data.clone
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,25 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module KDoc
|
4
|
-
# General purpose
|
4
|
+
# General purpose data DSL
|
5
5
|
#
|
6
6
|
# Made up of 0 or more setting groups and table groups
|
7
|
-
class
|
8
|
-
include
|
7
|
+
class Data < KDoc::Container
|
8
|
+
include KLog::Logging
|
9
|
+
|
10
|
+
# include KType::Error
|
11
|
+
# include KType::ManagedState
|
12
|
+
# include KType::NamedFolder
|
13
|
+
# include KType::LayeredFolder
|
9
14
|
|
10
|
-
attr_reader :key
|
11
|
-
attr_reader :type
|
12
|
-
attr_reader :namespace
|
13
15
|
attr_reader :options
|
14
|
-
attr_reader :error
|
15
16
|
|
16
17
|
# Create document
|
17
18
|
#
|
18
19
|
# @param [String|Symbol] name Name of the document
|
19
20
|
# @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new.default_document_type if not set
|
20
21
|
# @param default: Default value (using named params), as above
|
21
|
-
def initialize(key =
|
22
|
-
|
22
|
+
def initialize(key = nil, **options, &block)
|
23
|
+
super(key: key, type: options[:type], namespace: options[:namespace], project_key: options[:project_key])
|
24
|
+
initialize_attributes(**options)
|
23
25
|
|
24
26
|
@block = block if block_given?
|
25
27
|
end
|
@@ -59,7 +61,7 @@ module KDoc
|
|
59
61
|
def settings(key = nil, **options, &block)
|
60
62
|
options ||= {}
|
61
63
|
|
62
|
-
opts = {}.merge(@options) #
|
64
|
+
opts = {}.merge(@options) # Data Options
|
63
65
|
.merge(options) # Settings Options
|
64
66
|
.merge(parent: self)
|
65
67
|
|
@@ -80,14 +82,6 @@ module KDoc
|
|
80
82
|
# KDoc::Builder::Shotstack.new(@data, key, &block)
|
81
83
|
# end
|
82
84
|
|
83
|
-
# def set_data(data)
|
84
|
-
# @data = data
|
85
|
-
# end
|
86
|
-
|
87
|
-
def data
|
88
|
-
@data.clone
|
89
|
-
end
|
90
|
-
|
91
85
|
def data_struct
|
92
86
|
KUtil.data.to_open_struct(data)
|
93
87
|
end
|
@@ -111,6 +105,7 @@ module KDoc
|
|
111
105
|
end
|
112
106
|
|
113
107
|
# Removes any meta data eg. "fields" from a table and just returns the raw data
|
108
|
+
# REFACTOR: IT MAY BE BEST TO MOVE raw_data into each of the node_types
|
114
109
|
def raw_data
|
115
110
|
# REFACT, what if this is CSV, meaning it is just an array?
|
116
111
|
# add specs
|
@@ -162,18 +157,12 @@ module KDoc
|
|
162
157
|
|
163
158
|
private
|
164
159
|
|
165
|
-
def initialize_attributes(
|
166
|
-
@key = key
|
167
|
-
|
160
|
+
def initialize_attributes(**options)
|
168
161
|
@options = options || {}
|
169
|
-
@type = slice_option(:type) || KDoc.opinion.default_document_type
|
170
|
-
@namespace = slice_option(:namespace) || ''
|
171
162
|
@parent = slice_option(:parent)
|
172
163
|
|
173
164
|
# Most documents live within a hash, some tabular documents such as CSV will use an []
|
174
165
|
@data = slice_option(:default_data) || {}
|
175
|
-
|
176
|
-
@error = nil
|
177
166
|
end
|
178
167
|
|
179
168
|
def settings_instance(data, key, **options, &block)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This could move into KDecor
|
4
|
+
module KDoc
|
5
|
+
module Decorators
|
6
|
+
class SettingsDecorator < KDecor::BaseDecorator
|
7
|
+
def initialize
|
8
|
+
super(KDoc::Settings)
|
9
|
+
end
|
10
|
+
|
11
|
+
# def update(target, behaviour)
|
12
|
+
# update_settings(target, target.internal_data) if %i[all default].include?(behaviour)
|
13
|
+
|
14
|
+
# target
|
15
|
+
# end
|
16
|
+
|
17
|
+
# # What responsibility will this SettingsDecorator take on?
|
18
|
+
# def update(target, **_opts)
|
19
|
+
# def update_settings(_target, _settings)
|
20
|
+
# log.warn('Override this method in your descendant implementation')
|
21
|
+
# end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDoc
|
4
|
+
module Decorators
|
5
|
+
class TableDecorator < KDecor::BaseDecorator
|
6
|
+
def initialize
|
7
|
+
super(KDoc::Table)
|
8
|
+
|
9
|
+
self.implemented_behaviours = %i[update_fields update_rows]
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(target, **opts)
|
13
|
+
behaviour = opts[:behaviour]
|
14
|
+
|
15
|
+
update_fields(target, target.get_fields) if %i[all update_fields].include?(behaviour)
|
16
|
+
update_rows(target, target.get_rows) if %i[all update_rows].include?(behaviour)
|
17
|
+
|
18
|
+
target
|
19
|
+
end
|
20
|
+
|
21
|
+
# What responsibility will this TableDecorator take on?
|
22
|
+
# Update fields/columns, or/and
|
23
|
+
def update_fields(_target, _fields)
|
24
|
+
raise KType::Error, 'Update fields not implement, you need to implement this method and '
|
25
|
+
end
|
26
|
+
|
27
|
+
# Update row values/structure
|
28
|
+
def update_rows(_target, _rows); end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/k_doc/fake_opinion.rb
CHANGED
@@ -10,7 +10,7 @@ module KDoc
|
|
10
10
|
attr_accessor :default_settings_key
|
11
11
|
attr_accessor :default_table_key
|
12
12
|
|
13
|
-
attr_accessor :document_class
|
13
|
+
# attr_accessor :document_class
|
14
14
|
attr_accessor :settings_class
|
15
15
|
attr_accessor :table_class
|
16
16
|
|
@@ -19,7 +19,7 @@ module KDoc
|
|
19
19
|
@default_settings_key = :settings
|
20
20
|
@default_table_key = :table
|
21
21
|
|
22
|
-
@document_class = KDoc::Document
|
22
|
+
# @document_class = KDoc::Document
|
23
23
|
@table_class = KDoc::Table
|
24
24
|
@settings_class = KDoc::Settings
|
25
25
|
end
|
data/lib/k_doc/settings.rb
CHANGED
@@ -6,10 +6,12 @@ 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
|
9
|
+
include KLog::Logging
|
10
|
+
# include KDoc::Decorators
|
10
11
|
|
11
12
|
attr_reader :parent
|
12
13
|
attr_reader :key
|
14
|
+
attr_reader :decorators
|
13
15
|
|
14
16
|
alias kp parent
|
15
17
|
|
@@ -19,6 +21,9 @@ module KDoc
|
|
19
21
|
# Need a way to find out the line number for errors and report it correctly
|
20
22
|
begin
|
21
23
|
instance_eval(&block) if block_given?
|
24
|
+
|
25
|
+
run_decorators
|
26
|
+
|
22
27
|
# rubocop:disable Style/RescueStandardError
|
23
28
|
rescue => e
|
24
29
|
# rubocop:enable Style/RescueStandardError
|
@@ -28,27 +33,19 @@ module KDoc
|
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
|
-
|
36
|
+
# Return these settings which are attached to a data container using :key
|
37
|
+
# internal_data is a bad name, but it is unlikely to interfere with any setting names
|
38
|
+
# Maybe I rename this to raw_data
|
39
|
+
def internal_data
|
32
40
|
@data[@key]
|
33
41
|
end
|
34
42
|
|
35
|
-
# def run_decorators(opts)
|
36
|
-
# decorators = KDoc::Decorator.decorate.decorators(opts[:decorators])
|
37
|
-
|
38
|
-
# return if decorators.empty?
|
39
|
-
|
40
|
-
# decorators.each do |decorator|
|
41
|
-
# decorator.send(:update, my_data) if decorator.respond_to?(:update)
|
42
|
-
# decorator.send(:call, my_data) if decorator.respond_to?(:call)
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
|
46
43
|
def respond_to_missing?(name, *_args, &_block)
|
47
44
|
# puts 'respond_to_missing?'
|
48
45
|
# puts "respond_to_missing: #{name}"
|
49
46
|
n = name.to_s
|
50
47
|
n = n[0..-2] if n.end_with?('=')
|
51
|
-
|
48
|
+
internal_data.key?(n.to_s) || (!@parent.nil? && @parent.respond_to?(name, true)) || super
|
52
49
|
end
|
53
50
|
|
54
51
|
# rubocop:disable Metrics/AbcSize
|
@@ -106,26 +103,39 @@ module KDoc
|
|
106
103
|
define_method("#{name}=") do |value|
|
107
104
|
# log.progress(4, 'add_setter_method')
|
108
105
|
# log.kv 'value', value
|
109
|
-
|
106
|
+
internal_data[name.to_s] = value
|
110
107
|
end
|
111
108
|
end
|
112
109
|
end
|
113
110
|
|
114
111
|
def get_value(name)
|
115
|
-
|
112
|
+
internal_data[name.to_s]
|
116
113
|
end
|
117
114
|
|
118
115
|
def debug
|
119
|
-
puts JSON.pretty_generate(
|
116
|
+
puts JSON.pretty_generate(internal_data)
|
120
117
|
end
|
121
118
|
|
122
119
|
private
|
123
120
|
|
121
|
+
# This method can move into decorator helpers
|
122
|
+
def run_decorators
|
123
|
+
decorators.each { |decorator| decorator.decorate(self, :settings) }
|
124
|
+
end
|
125
|
+
|
124
126
|
def initialize_attributes(data, key = nil, **options)
|
125
127
|
@data = data
|
126
128
|
@key = (key || FakeOpinion.new.default_settings_key).to_s
|
127
129
|
|
128
|
-
@parent = options[:parent] if
|
130
|
+
@parent = options[:parent] if options.key?(:parent)
|
131
|
+
|
132
|
+
decorator_list = options[:decorators].nil? ? [] : options[:decorators]
|
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)
|
138
|
+
.select { |decorator| decorator.compatible?(self) }
|
129
139
|
|
130
140
|
@data[@key] = {}
|
131
141
|
end
|
data/lib/k_doc/table.rb
CHANGED
@@ -3,16 +3,33 @@
|
|
3
3
|
module KDoc
|
4
4
|
# Build rows (aka DataTable) with field definitions and rows of data
|
5
5
|
class Table
|
6
|
+
include KLog::Logging
|
7
|
+
|
6
8
|
attr_reader :parent
|
7
9
|
attr_reader :name
|
10
|
+
attr_reader :decorators
|
8
11
|
|
9
12
|
def initialize(data, name = nil, **options, &block)
|
10
13
|
initialize_attributes(data, name, **options)
|
11
14
|
|
15
|
+
@has_executed_field_decorators = false
|
16
|
+
@has_executed_row_decorators = false
|
17
|
+
|
12
18
|
instance_eval(&block) if block_given?
|
19
|
+
|
20
|
+
run_decorators(:update_rows)
|
13
21
|
end
|
14
22
|
|
15
|
-
|
23
|
+
# Pass fields in using the following format
|
24
|
+
# fields :name, f(:type, :string), :db_type
|
25
|
+
#
|
26
|
+
# The older format of an array is supported via a splat conversion
|
27
|
+
def fields(*field_definitions)
|
28
|
+
if field_definitions.length == 1 && field_definitions[0].is_a?(Array)
|
29
|
+
log.warn('avoid supplying field definitions with array. *Splat fields is the preferred technique.')
|
30
|
+
field_definitions = *field_definitions[0]
|
31
|
+
end
|
32
|
+
|
16
33
|
fields = @data[@name]['fields']
|
17
34
|
|
18
35
|
field_definitions.each do |fd|
|
@@ -22,15 +39,18 @@ module KDoc
|
|
22
39
|
fd
|
23
40
|
end
|
24
41
|
end
|
42
|
+
|
43
|
+
run_decorators(:update_fields)
|
25
44
|
end
|
26
45
|
|
27
46
|
# rubocop:disable Metrics/AbcSize
|
28
47
|
def row(*args, **named_args)
|
29
48
|
fields = @data[@name]['fields']
|
30
49
|
|
31
|
-
raise "To many values for row, argument #{
|
50
|
+
raise KType::Error, "To many values for row, argument #{args.length}" if args.length > fields.length
|
32
51
|
|
33
52
|
# Apply column names with defaults
|
53
|
+
|
34
54
|
row = fields.each_with_object({}) do |f, hash|
|
35
55
|
hash[f['name']] = f['default']
|
36
56
|
end
|
@@ -60,6 +80,10 @@ module KDoc
|
|
60
80
|
end
|
61
81
|
# rubocop:enable Naming/AccessorMethodName
|
62
82
|
|
83
|
+
def internal_data
|
84
|
+
@data[@name]
|
85
|
+
end
|
86
|
+
|
63
87
|
def find_row(key, value)
|
64
88
|
@data[@name]['rows'].find { |r| r[key] == value }
|
65
89
|
end
|
@@ -91,16 +115,45 @@ module KDoc
|
|
91
115
|
end
|
92
116
|
alias f field
|
93
117
|
|
118
|
+
def debug
|
119
|
+
log.o(KUtil.data.to_open_struct(internal_data))
|
120
|
+
end
|
121
|
+
|
94
122
|
private
|
95
123
|
|
124
|
+
# This method can move into decorator helpers
|
125
|
+
# Run decorators a maximum of once for each behaviour
|
126
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
127
|
+
def run_decorators(behaviour)
|
128
|
+
return if behaviour == :update_fields && @has_executed_field_decorators
|
129
|
+
return if behaviour == :update_rows && @has_executed_row_decorators
|
130
|
+
|
131
|
+
@has_executed_field_decorators = true if behaviour == :update_fields
|
132
|
+
|
133
|
+
@has_executed_rows_decorators = true if behaviour == :update_rows
|
134
|
+
|
135
|
+
decorators.each { |decorator| decorator.decorate(self, behaviour) }
|
136
|
+
end
|
137
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
138
|
+
|
139
|
+
# rubocop:disable Metrics/AbcSize
|
96
140
|
def initialize_attributes(data, name = nil, **options)
|
97
141
|
@data = data
|
98
142
|
@name = (name || FakeOpinion.new.default_table_key.to_s).to_s
|
99
143
|
|
100
144
|
@parent = options[:parent] if !options.nil? && options.key?(:parent)
|
101
145
|
|
146
|
+
# This code needs to work differently, it needs to support the 3 different types
|
147
|
+
# Move the query into helpers
|
148
|
+
decorator_list = options[:decorators].nil? ? [] : options[:decorators]
|
149
|
+
|
150
|
+
@decorators = decorator_list
|
151
|
+
.map(&:new)
|
152
|
+
.select { |decorator| decorator.compatible?(self) }
|
153
|
+
|
102
154
|
@data[@name] = { 'fields' => [], 'rows' => [] }
|
103
155
|
end
|
156
|
+
# rubocop:enable Metrics/AbcSize
|
104
157
|
|
105
158
|
def respond_to_missing?(name, *_args, &_block)
|
106
159
|
(!@parent.nil? && @parent.respond_to?(name, true)) || super
|
data/lib/k_doc/util.rb
CHANGED
@@ -3,12 +3,18 @@
|
|
3
3
|
module KDoc
|
4
4
|
# Utility helper methods for KDoc
|
5
5
|
class Util
|
6
|
-
|
6
|
+
# Build a unique key so that resources of the same key do not conflict with
|
7
|
+
# one another across projects, namespaces or types
|
8
|
+
#
|
9
|
+
# @param [String] param_name Param description
|
10
|
+
def build_unique_key(key, type = nil, namespace = nil, project_key = nil)
|
7
11
|
raise KDoc::Error, 'key is required when generating unique key' if key.nil? || key.empty?
|
8
12
|
|
9
13
|
type ||= KDoc.opinion.default_document_type
|
10
14
|
|
11
|
-
namespace.nil? ||
|
15
|
+
keys = [project_key, namespace, key, type].reject { |k| k.nil? || k == '' }.map { |k| k.to_s.gsub('_', '-') }
|
16
|
+
|
17
|
+
keys.join('-')
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
data/lib/k_doc/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
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.13
|
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-
|
11
|
+
date: 2021-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: k_decor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.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.0.0
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: k_log
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +52,20 @@ dependencies:
|
|
24
52
|
- - "~>"
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: 0.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: k_type
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.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.0.0
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: k_util
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,6 +99,7 @@ files:
|
|
57
99
|
- README.md
|
58
100
|
- Rakefile
|
59
101
|
- STORIES.md
|
102
|
+
- ToDo.md
|
60
103
|
- USAGE.md
|
61
104
|
- bin/console
|
62
105
|
- bin/k
|
@@ -67,9 +110,11 @@ files:
|
|
67
110
|
- hooks/update-version
|
68
111
|
- k_doc.gemspec
|
69
112
|
- lib/k_doc.rb
|
70
|
-
- lib/k_doc/
|
113
|
+
- lib/k_doc/container.rb
|
114
|
+
- lib/k_doc/data.rb
|
115
|
+
- lib/k_doc/decorators/settings_decorator.rb
|
116
|
+
- lib/k_doc/decorators/table_decorator.rb
|
71
117
|
- lib/k_doc/fake_opinion.rb
|
72
|
-
- lib/k_doc/logging.rb
|
73
118
|
- lib/k_doc/settings.rb
|
74
119
|
- lib/k_doc/table.rb
|
75
120
|
- lib/k_doc/util.rb
|