k_doc 0.0.23 → 0.0.27

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c113abcf9cd5dd3c9a8518c45503afc2fb545e3365b9d0c1ae75dcef02da7c5
4
- data.tar.gz: 1c4edfea6d0e82b5f300946a38880bbb3ee85a7ebb8f3979378bd8e755394028
3
+ metadata.gz: 13425498035dd9742336c907655e6555a37f7b4293c99443921bea29b38b0db9
4
+ data.tar.gz: 63ff3b0ad02f17833cc23318d529c80cc1e0165eae4d18fb096db484f331808b
5
5
  SHA512:
6
- metadata.gz: 5f35384ccc40360f2fe92f99a994933b5a9060c0b1fcd5cd4a2e67dba4f17b49c2ed07ffeca9844510487aeddbe72afd585dd68b57306dccdc2f666e235f998f
7
- data.tar.gz: 594e5175236bdc19405e5ad7d00dc8326d25902dd92e8698e06a778b430172ef6baeb5bf15b0ebcb9a0bcd044fc92ad7e18ffc9bacc7ee5428666d931eac909c
6
+ metadata.gz: d623d3964433ecbd4b33d4c4cce608d5e1923836ab6ffb3ab91c05dc9ae517719d2da2a14ca0ab3c83e5cace4593d2afaad80f24eaa4c8e8e48dd7b6229c886a
7
+ data.tar.gz: 9557e8c8082bcfed3acb10fea6a4516e7aec04a49cfdf3f99fb3800faf32531937df8f52278db7a0e02f6543b8e22e25bbadef7d472e530a5ccaf6c8ae053081
@@ -180,6 +180,6 @@ class Director
180
180
 
181
181
  return if @builder
182
182
 
183
- @builder = KBuilder::BaseBuilder.init(KBuilder.configuration(opts[:builder_config_name]))
183
+ @builder = KBuilder::BaseBuilder.init(KConfig.configuration(opts[:builder_config_name]))
184
184
  end
185
185
  end
@@ -1,5 +1,5 @@
1
1
  KBuilder.reset(:gem)
2
- KBuilder.configure(:gem) do |config|
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
- KBuilder.configure(:design_patterns) do |config|
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
- # KBuilder.configuration(:gem).debug
17
+ # KConfig.configuration(:gem).debug
18
18
 
19
19
  # def builder
20
20
  # @builder ||= KBuilder::BaseBuilder.init
data/.rubocop.yml CHANGED
@@ -44,15 +44,19 @@ Layout/LineLength:
44
44
  Lint/UnusedMethodArgument:
45
45
  AllowUnusedKeywordArguments: true
46
46
 
47
- Style/Documentation:
47
+ Style/AccessorGrouping:
48
48
  Enabled: false
49
-
50
49
  Style/BlockComments:
51
50
  Enabled: false
52
51
  Include:
53
52
  - "**/spec/*"
54
-
55
- # My Preferences - Start
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/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).
@@ -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
@@ -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)
27
29
  initialize_block(opts, &block)
28
30
  end
29
31
 
@@ -32,11 +34,16 @@ module KDoc
32
34
  end
33
35
 
34
36
  def default_data_type
35
- Hash
37
+ @default_data_type ||= Hash
38
+ end
39
+
40
+ def os(**opts)
41
+ OpenStruct.new(opts)
36
42
  end
37
43
 
38
44
  def debug
39
- debug_container
45
+ debug_taggable
46
+ debug_block_processor
40
47
  debug_errors
41
48
  end
42
49
 
@@ -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,12 +6,23 @@ 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
12
14
  end
13
15
 
14
- def execute_block(run_actions: nil)
16
+ def evaluated?
17
+ @block_state == :evaluated || @block_state == :actioned
18
+ end
19
+
20
+ def actioned?
21
+ @block_state == :actioned
22
+ end
23
+
24
+ def execute_block(run_importer: nil, run_actions: nil)
25
+ run_on_import if run_importer
15
26
  eval_block
16
27
  run_on_action if run_actions
17
28
  end
@@ -20,6 +31,7 @@ module KDoc
20
31
  return if @block.nil?
21
32
 
22
33
  instance_eval(&@block)
34
+ @block_state = :evaluated
23
35
  rescue StandardError => e
24
36
  log.error('Standard error in document')
25
37
  # puts "key #{unique_key}"
@@ -32,7 +44,10 @@ module KDoc
32
44
  def run_on_action
33
45
  return if @block.nil?
34
46
 
35
- on_action if respond_to?(:on_action)
47
+ if respond_to?(:on_action)
48
+ on_action
49
+ @block_state = :actioned
50
+ end
36
51
  rescue StandardError => e
37
52
  log.error('Standard error while running actions')
38
53
  # puts "key #{unique_key}"
@@ -41,5 +56,11 @@ module KDoc
41
56
  @error = e
42
57
  raise
43
58
  end
59
+
60
+ def debug_block_processor
61
+ log.kv 'block_state', block_state , debug_pad_size if respond_to?(:block_state)
62
+ log.kv 'evaluated' , evaluated? , debug_pad_size if respond_to?(:evaluated?)
63
+ log.kv 'actioned' , actioned? , debug_pad_size if respond_to?(:actioned?)
64
+ end
44
65
  end
45
66
  end
@@ -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
 
@@ -42,5 +42,9 @@ module KDoc
42
42
  log.error error.message if error.type == :guard
43
43
  end
44
44
  end
45
+
46
+ def clear_errors
47
+ errors.clear
48
+ end
45
49
  end
46
50
  end
@@ -0,0 +1,27 @@
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
+ # Proc/Handler to be called when importing data
10
+ attr_reader :on_import
11
+
12
+ # OpenStruct to be populated with data from import
13
+ attr_reader :imports
14
+
15
+ def initialize_import(opts)
16
+ # log.error 'initialize_import'
17
+ @on_import = opts.delete(:on_import)
18
+ @imports = OpenStruct.new
19
+ end
20
+
21
+ def run_on_import
22
+ return unless on_import
23
+
24
+ instance_eval(&on_import)
25
+ end
26
+ end
27
+ end
@@ -67,39 +67,22 @@ 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 debug_container
92
- log.kv 'tag' , tag , debug_pad_size
93
- log.kv 'project' , project , debug_pad_size unless project.nil? || project.empty?
94
- log.kv 'namespace', namespace , debug_pad_size unless namespace.nil? || namespace.empty?
95
- log.kv 'key' , key , debug_pad_size
96
- log.kv 'type' , type , debug_pad_size
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
97
80
  # log.kv 'error' , error , debug_kv_pad_size
98
81
  end
99
82
  # rubocop:enable Metrics/AbcSize
100
83
 
101
84
  def debug_pad_size
102
- @debug_pad_size ||= @tag_options.delete(:debug_pad_size) || 15
85
+ @debug_pad_size ||= @tag_options.delete(:debug_pad_size) || 20
103
86
  end
104
87
 
105
88
  private
data/lib/k_doc/model.rb CHANGED
@@ -23,6 +23,12 @@ 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
+ # TODO: add test
27
+ if block.nil?
28
+ log.warn 'You cannot call settings without a block. Did you mean to call data[:settings] or odata.settings?'
29
+ return
30
+ end
31
+
26
32
  setting_opts ||= {}
27
33
 
28
34
  setting_opts = {}.merge(opts) # Container options
@@ -34,6 +40,11 @@ module KDoc
34
40
  end
35
41
 
36
42
  def table(key = :table, **opts, &block)
43
+ if block.nil?
44
+ log.warn 'You cannot call table without a block. Did you mean to call data[:table] or odata.table?'
45
+ return
46
+ end
47
+
37
48
  # NEED to add support for run_decorators I think
38
49
  opts.merge(parent: self)
39
50
  table_instance(data, key, **opts, &block)
@@ -115,7 +126,8 @@ module KDoc
115
126
 
116
127
  def debug_header
117
128
  log.heading self.class.name
118
- debug_container
129
+ debug_taggable
130
+ debug_block_processor
119
131
  debug_header_keys
120
132
 
121
133
  log.line
@@ -33,6 +33,10 @@ module KDoc
33
33
  end
34
34
  end
35
35
 
36
+ def imports
37
+ parent.imports
38
+ end
39
+
36
40
  # Return these settings which are attached to a data container using :key
37
41
  # internal_data is a bad name, but it is unlikely to interfere with any setting names
38
42
  # Maybe I rename this to raw_data
data/lib/k_doc/table.rb CHANGED
@@ -20,6 +20,10 @@ module KDoc
20
20
  run_decorators(:update_rows)
21
21
  end
22
22
 
23
+ def imports
24
+ parent.imports
25
+ end
26
+
23
27
  # Pass fields in using the following format
24
28
  # fields :name, f(:type, :string), :db_type
25
29
  #
data/lib/k_doc/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KDoc
4
- VERSION = '0.0.23'
4
+ VERSION = '0.0.27'
5
5
  end
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.23
4
+ version: 0.0.27
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-12-07 00:00:00.000000000 Z
11
+ date: 2022-02-14 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.7
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