k_doc 0.0.12 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1bb7261302051361f705cc9c726702f02722e7f55c028e07acf8a84b55ee168
4
- data.tar.gz: 7d3a27cd2a16cfc2bbc513d29d02aff1faa0d9ca9844a45e86b30bf2d417cdd3
3
+ metadata.gz: 28959da3b25b7817899193c0b0057e42750783a561e8190de4f6af82be5116c9
4
+ data.tar.gz: c55996060304324b439d6a02d3a0993279a9f76dee8468802486a9e92cf958e3
5
5
  SHA512:
6
- metadata.gz: 0b6602d011acb3d1f3763618cd87452a35ea9835c89f86c985fb34100b3c084d40b08e08f04e8c25e20c5034fc10c1b352579c16cbf1febe70ec8d5cb29d09ca
7
- data.tar.gz: 3381001de7214affe1298bf398c2e19749fa22d098f39f4c2c24f09a4ed14158e981c8654bfa478ea3d6e5c06ea0f29c832c6987fdeaf63c996b57a19216eb53
6
+ metadata.gz: e5c7303c8d1d9f0b6b90c1071c46d20852ed7796ba3410e2267f5fc42af55dc9ac7d20ff43d1c9a228f6779b67a1e9da0ecdde0b0fffe42b2b87811571af7d72
7
+ data.tar.gz: e464b9117c83fdd72fc25a1bb17815ff62cf58a74b6e4f197c070eccf588ecd45e99ca25ff7985b06b1dd889e0fa62c1fd7adffc29c6b3bc2b50870ae13e88eb
data/lib/k_doc.rb CHANGED
@@ -10,11 +10,11 @@ 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'
17
- require 'k_doc/util'
18
18
 
19
19
  require 'k_doc/decorators/settings_decorator'
20
20
  require 'k_doc/decorators/table_decorator'
@@ -24,20 +24,19 @@ module KDoc
24
24
  class Error < StandardError; end
25
25
 
26
26
  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
27
+ # Is this needed
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
35
- attr_accessor :util
36
36
  attr_accessor :log
37
37
  end
38
38
 
39
39
  KDoc.opinion = KDoc::FakeOpinion.new
40
- KDoc.util = KDoc::Util.new
41
40
  end
42
41
 
43
42
  if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
@@ -1,15 +1,27 @@
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
+ # Name of the document (required)
10
+ #
11
+ # Examples: user, account, country
9
12
  attr_reader :key
13
+
14
+ # Type of data
15
+ #
16
+ # Examples by data type
17
+ # :csv, :yaml, :json, :xml
18
+ #
19
+ # Examples by shape of the data in a DSL
20
+ # :entity, :microapp, blueprint
10
21
  attr_reader :type
11
- attr_reader :namespace
12
- attr_reader :project_key
22
+
23
+ attr_writer :data
24
+
13
25
  attr_reader :error
14
26
 
15
27
  # Create container for storing data/documents.
@@ -19,35 +31,18 @@ module KDoc
19
31
  #
20
32
  # @param [Hash] **opts The options
21
33
  # @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
34
+ # @option opts [String|Symbol] type Type of the container, defaults to KDoc:: FakeOpinion.new.default_model_type if not set
25
35
  def initialize(**opts)
26
- @key = opts[:key] || SecureRandom.alphanumeric(8)
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) || {}
36
+ @key = opts[:key] || SecureRandom.alphanumeric(4)
37
+ @type = opts[:type] || ''
34
38
  @data = opts[:data] || {}
35
39
  end
36
40
 
37
- def unique_key
38
- @unique_key ||= KDoc.util.build_unique_key(key, type, namespace, project_key)
39
- end
40
-
41
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
42
+ log.kv 'key' , key , 15
43
+ log.kv 'type' , type , 15
47
44
  end
48
45
 
49
- attr_writer :data
50
-
51
46
  def data
52
47
  @data.clone
53
48
  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
 
@@ -44,7 +50,7 @@ module KDoc
44
50
  # raise
45
51
  rescue StandardError => e
46
52
  log.error('Standard error in document')
47
- puts "key #{unique_key}"
53
+ # puts "key #{unique_key}"
48
54
  # puts "file #{KUtil.data.console_file_hyperlink(resource.file, resource.file)}"
49
55
  log.error(e.message)
50
56
  @error = e
@@ -54,10 +60,6 @@ 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
60
-
61
63
  def settings(key = nil, **options, &block)
62
64
  options ||= {}
63
65
 
@@ -135,19 +137,17 @@ module KDoc
135
137
  log.o(raw_data_struct)
136
138
  end
137
139
 
138
- # rubocop:disable Metrics/AbcSize
139
140
  def debug_header
140
141
  log.heading self.class.name
141
- log.kv 'key', key
142
- log.kv 'type', type
143
- log.kv 'namespace', namespace
144
- log.kv 'error', error
142
+ log.kv 'key' , key , 15
143
+ log.kv 'type' , type , 15
144
+ # log.kv 'namespace', namespace
145
+ log.kv 'error' , error , 15
145
146
 
146
147
  debug_header_keys
147
148
 
148
149
  log.line
149
150
  end
150
- # rubocop:enable Metrics/AbcSize
151
151
 
152
152
  def debug_header_keys
153
153
  options&.keys&.reject { |k| k == :namespace }&.each do |key|
@@ -159,6 +159,7 @@ module KDoc
159
159
 
160
160
  def initialize_attributes(**options)
161
161
  @options = options || {}
162
+ # Is parent a part of model, or is it part of k_manager::document_taggable
162
163
  @parent = slice_option(:parent)
163
164
 
164
165
  # Most documents live within a hash, some tabular documents such as CSV will use an []
data/lib/k_doc/table.rb CHANGED
@@ -55,14 +55,15 @@ module KDoc
55
55
  hash[f['name']] = f['default']
56
56
  end
57
57
 
58
+ # TODO: clean_symbol should be an option that is turned on or off for the table
58
59
  # Override with positional arguments
59
60
  args.each_with_index do |arg, i|
60
- row[fields[i]['name']] = KUtil.data.clean_symbol(arg)
61
+ row[fields[i]['name']] = arg # KUtil.data.clean_symbol(arg)
61
62
  end
62
63
 
63
64
  # Override with named args
64
65
  named_args.each_key do |key|
65
- row[key.to_s] = named_args[key]
66
+ row[key.to_s] = named_args[key] # KUtil.data.clean_symbol(named_args[key])
66
67
  end
67
68
 
68
69
  @data[@name]['rows'] << row
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.12'
4
+ VERSION = '0.0.18'
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.12
4
+ version: 0.0.18
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-23 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -111,13 +111,12 @@ 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
- - lib/k_doc/util.rb
121
120
  - lib/k_doc/version.rb
122
121
  homepage: http://appydave.com/gems/k-doc
123
122
  licenses:
data/lib/k_doc/util.rb DELETED
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDoc
4
- # Utility helper methods for KDoc
5
- class Util
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)
11
- raise KDoc::Error, 'key is required when generating unique key' if key.nil? || key.empty?
12
-
13
- type ||= KDoc.opinion.default_document_type
14
-
15
- keys = [project_key, namespace, key, type].reject { |k| k.nil? || k == '' }.map { |k| k.to_s.gsub('_', '-') }
16
-
17
- keys.join('-')
18
- end
19
- end
20
- end