k_doc 0.0.10 → 0.0.16

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: 4dc18e7f82a4c59368f6870a693781586d274f21b8a8df64bd568aa6d0c43262
4
- data.tar.gz: d2328c38cf349291486d22d46572698817df1e00ce64c628eba90d7451e97ca3
3
+ metadata.gz: 64615008b76feb26a84e9dd808654495cf3f26bf42f6941b00eaca9013081a76
4
+ data.tar.gz: e69ccfb764c6dd9df4ee1fe78df56f717726f733184839020d3df968c34fde63
5
5
  SHA512:
6
- metadata.gz: 0c844d63fc520e5dab619f01214a93df2306d60cc6877b923cda7a0963269bac0e6ba69b28b6f3d26fec4418e821d61fd92e84f58d0555b7f7ee9dd46ad5539b
7
- data.tar.gz: 81f55829133fc0f3a2a581da5ec51d370bdc7050fdef00ef2aed7965cb43119ccd182413298894b6b40302848d0fc84eb0e77381676c820a70e2bb8ddd2adcbf
6
+ metadata.gz: 94d4cd31dddad2f142fa418c24025c866124722e8f93ee3133d1d7c68893640954c7203e5bd5a502eb75f9650c444d7103945af6fa901ece63450a0537b130d3
7
+ data.tar.gz: f1a6e045702b3e9c94146ae413f573fc281472eaf5927e9b27a819445cff112b2a688863c7f0bf2d2d4e996e703dd3f4f7721c7766ecd621feb4971b24cfddba
data/lib/k_doc.rb CHANGED
@@ -10,7 +10,8 @@ require 'k_decor'
10
10
 
11
11
  require 'k_doc/version'
12
12
  require 'k_doc/container'
13
- require 'k_doc/data'
13
+ # require 'k_doc/data'
14
+ require 'k_doc/model'
14
15
  require 'k_doc/fake_opinion'
15
16
  require 'k_doc/settings'
16
17
  require 'k_doc/table'
@@ -24,11 +25,11 @@ module KDoc
24
25
  class Error < StandardError; end
25
26
 
26
27
  class << self
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
28
+ # Factory method to create a new model
29
+ def model(key = nil, **options, &block)
30
+ model = KDoc::Model.new(key, **options, &block)
31
+ model.execute_block
32
+ model
32
33
  end
33
34
 
34
35
  attr_accessor :opinion
@@ -1,15 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KDoc
4
- # A container acts a base data object for any data requires tagging such as
4
+ # A data acts a base data object for any data requires tagging such as
5
5
  # unique key, type and namespace.
6
6
  class Container
7
7
  # include KLog::Logging
8
8
 
9
+ # Seems like there is way too much data here
10
+ # Firstly it should probably be in an interface
11
+ # Secondly some of this (namespace, project_key, error) belongs in k_manager
12
+ # So container would be better off just being key, type, data
9
13
  attr_reader :key
14
+
15
+ # NOTE: This should not be using an opinion in this project
10
16
  attr_reader :type
11
- attr_reader :namespace
12
- attr_reader :project_key
17
+
18
+ # Move this up to k_manager
19
+ # attr_reader :namespace
20
+ # attr_reader :project_key
13
21
  attr_reader :error
14
22
 
15
23
  # Create container for storing data/documents.
@@ -17,27 +25,39 @@ module KDoc
17
25
  # Any container can be uniquely identified via it's
18
26
  # key, type, namespace and project_key attributes
19
27
  #
20
- # @param [String|Symbol] name Name of the container
21
- # @param [String|Symbol] type Type of the container, defaults to KDoc:: FakeOpinion.new.default_document_type if not set
22
- # @param [String|Symbol] namespace Namespace that the container belongs to
23
- # @param [String|Symbol] project_key Project that the container belongs to
24
- def initialize(key: nil, type: nil, namespace: nil, project_key: nil)
25
- @key = key || SecureRandom.alphanumeric(8)
26
- @type = type || KDoc.opinion.default_document_type
27
- @namespace = namespace || ''
28
- @project_key = project_key || ''
29
- end
28
+ # @param [Hash] **opts The options
29
+ # @option opts [String|Symbol] name Name of the container
30
+ # @option opts [String|Symbol] type Type of the container, defaults to KDoc:: FakeOpinion.new.default_model_type if not set
31
+ # @option opts [String|Symbol] namespace Namespace that the container belongs to
32
+ # @option opts [String|Symbol] project_key Project that the container belongs to
33
+ def initialize(**opts)
34
+ @key = opts[:key] || SecureRandom.alphanumeric(4)
35
+ @type = opts[:type] || '' # KDoc.opinion.default_model_type
36
+ # @namespace = opts[:namespace] || ''
37
+ # @project_key = opts[:project_key] || ''
30
38
 
31
- def unique_key
32
- @unique_key ||= KDoc.util.build_unique_key(key, type, namespace, project_key)
39
+ # Old name is default_data, wonder if I still need that idea?
40
+ # Most documents live within a hash, some tabular documents such as CSV will use an []
41
+ # @data = slice_option(:default_data) || {}
42
+ @data = opts[:data] || {}
33
43
  end
34
44
 
45
+ # def unique_key
46
+ # @unique_key ||= KDoc.util.build_unique_key(key, type, namespace, project_key)
47
+ # end
48
+
35
49
  def debug_header
36
50
  log.kv 'key', key
37
51
  log.kv 'type', type
38
- log.kv 'namespace', namespace
39
- log.kv 'project_key', namespace
40
- log.kv 'error', error
52
+ # log.kv 'namespace', namespace
53
+ # log.kv 'project_key', namespace
54
+ # log.kv 'error', error
55
+ end
56
+
57
+ attr_writer :data
58
+
59
+ def data
60
+ @data.clone
41
61
  end
42
62
  end
43
63
  end
@@ -6,7 +6,7 @@ module KDoc
6
6
  # This is called fake opinion because I have not figured out
7
7
  # how I want to implement this
8
8
  class FakeOpinion
9
- attr_accessor :default_document_type
9
+ attr_accessor :default_model_type
10
10
  attr_accessor :default_settings_key
11
11
  attr_accessor :default_table_key
12
12
 
@@ -15,7 +15,7 @@ module KDoc
15
15
  attr_accessor :table_class
16
16
 
17
17
  def initialize
18
- @default_document_type = :entity
18
+ @default_model_type = :entity
19
19
  @default_settings_key = :settings
20
20
  @default_table_key = :table
21
21
 
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KDoc
4
- # General purpose data DSL
4
+ # Model is a DSL for modeling general purpose data objects
5
5
  #
6
- # Made up of 0 or more setting groups and table groups
7
- class Data < KDoc::Container
6
+ # A mode 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
8
13
  include KLog::Logging
9
14
 
10
15
  # include KType::Error
@@ -17,15 +22,16 @@ module KDoc
17
22
  # Create document
18
23
  #
19
24
  # @param [String|Symbol] name Name of the document
20
- # @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new.default_document_type if not set
25
+ # @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new.default_model_type if not set
21
26
  # @param default: Default value (using named params), as above
22
27
  def initialize(key = nil, **options, &block)
23
- super(key: key, type: options[:type], namespace: options[:namespace], project_key: options[:project_key])
28
+ super(key: key, type: options[:type] || KDoc.opinion.default_model_type) # , namespace: options[:namespace], project_key: options[:project_key])
24
29
  initialize_attributes(**options)
25
30
 
26
31
  @block = block if block_given?
27
32
  end
28
33
 
34
+ # NOTE: Can this be moved out of the is object?
29
35
  def execute_block(run_actions: nil)
30
36
  return if @block.nil?
31
37
 
@@ -54,9 +60,10 @@ module KDoc
54
60
  @run_actions = nil
55
61
  end
56
62
 
57
- def unique_key
58
- @unique_key ||= KDoc.util.build_unique_key(key, type, namespace)
59
- end
63
+ # Move this up to k_manager
64
+ # def unique_key
65
+ # @unique_key ||= KDoc.util.build_unique_key(key, type, namespace)
66
+ # end
60
67
 
61
68
  def settings(key = nil, **options, &block)
62
69
  options ||= {}
@@ -82,14 +89,6 @@ module KDoc
82
89
  # KDoc::Builder::Shotstack.new(@data, key, &block)
83
90
  # end
84
91
 
85
- # def set_data(data)
86
- # @data = data
87
- # end
88
-
89
- def data
90
- @data.clone
91
- end
92
-
93
92
  def data_struct
94
93
  KUtil.data.to_open_struct(data)
95
94
  end
@@ -143,19 +142,17 @@ module KDoc
143
142
  log.o(raw_data_struct)
144
143
  end
145
144
 
146
- # rubocop:disable Metrics/AbcSize
147
145
  def debug_header
148
146
  log.heading self.class.name
149
147
  log.kv 'key', key
150
148
  log.kv 'type', type
151
- log.kv 'namespace', namespace
149
+ # log.kv 'namespace', namespace
152
150
  log.kv 'error', error
153
151
 
154
152
  debug_header_keys
155
153
 
156
154
  log.line
157
155
  end
158
- # rubocop:enable Metrics/AbcSize
159
156
 
160
157
  def debug_header_keys
161
158
  options&.keys&.reject { |k| k == :namespace }&.each do |key|
data/lib/k_doc/util.rb CHANGED
@@ -10,11 +10,11 @@ module KDoc
10
10
  def build_unique_key(key, type = nil, namespace = nil, project_key = nil)
11
11
  raise KDoc::Error, 'key is required when generating unique key' if key.nil? || key.empty?
12
12
 
13
- type ||= KDoc.opinion.default_document_type
13
+ type ||= KDoc.opinion.default_model_type
14
14
 
15
- keys = [project_key, namespace, key, type].reject { |k| k.nil? || k == '' }
15
+ keys = [project_key, namespace, key, type].reject { |k| k.nil? || k == '' }.map { |k| k.to_s.gsub('_', '-') }
16
16
 
17
- keys.join('_')
17
+ keys.join('-')
18
18
  end
19
19
  end
20
20
  end
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.10'
4
+ VERSION = '0.0.16'
5
5
  end
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.10
4
+ version: 0.0.16
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-21 00:00:00.000000000 Z
11
+ date: 2021-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -111,10 +111,10 @@ files:
111
111
  - k_doc.gemspec
112
112
  - lib/k_doc.rb
113
113
  - lib/k_doc/container.rb
114
- - lib/k_doc/data.rb
115
114
  - lib/k_doc/decorators/settings_decorator.rb
116
115
  - lib/k_doc/decorators/table_decorator.rb
117
116
  - lib/k_doc/fake_opinion.rb
117
+ - lib/k_doc/model.rb
118
118
  - lib/k_doc/settings.rb
119
119
  - lib/k_doc/table.rb
120
120
  - lib/k_doc/util.rb