k_doc 0.0.16 → 0.0.22

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.
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module KDoc
6
+ # YamlDoc is a DSL for modeling YAML data objects
7
+ class YamlDoc < KDoc::Container
8
+ attr_reader :file
9
+
10
+ # Create YAML document
11
+ #
12
+ # @param [String|Symbol] name Name of the document
13
+ # @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new.default_csv_type if not set
14
+ # @param default: Default value (using named params), as above
15
+ def initialize(key = nil, **opts, &block)
16
+ super(**{ key: key }.merge(opts))
17
+
18
+ initialize_file
19
+
20
+ @block = block if block_given?
21
+ end
22
+
23
+ # Load data from file
24
+ #
25
+ # @param [Symbol] load_action The load_action to take if data has already been loaded
26
+ # @param [:once] load_action :once will load the data from content source on first try only
27
+ # @param [:reload] load_action :reload will reload from content source each time
28
+ # @param [Symbol] data_action The data_action to take when setting data, defaults to :replace
29
+ # @param [:replace] data_action :replace will replace the existing data instance with the incoming data value
30
+ # @param [:append] data_action :append will keep existing data and then new value data over the top
31
+ def load(load_action: :once, data_action: :replace)
32
+ return if load_action == :once && loaded?
33
+
34
+ content = File.read(file)
35
+ hash = YAML.safe_load(content)
36
+
37
+ set_data(hash, data_action: data_action)
38
+
39
+ @loaded = true
40
+
41
+ log_any_messages
42
+ end
43
+
44
+ def loaded?
45
+ @loaded
46
+ end
47
+
48
+ private
49
+
50
+ def initialize_file
51
+ @file ||= opts.delete(:file) || ''
52
+ @loaded = false
53
+ end
54
+
55
+ def default_data_type
56
+ Hash
57
+ end
58
+
59
+ def default_container_type
60
+ :yaml
61
+ end
62
+ end
63
+ end
data/lib/k_doc.rb CHANGED
@@ -3,19 +3,27 @@
3
3
  require 'securerandom'
4
4
 
5
5
  require 'table_print'
6
+ require 'forwardable'
6
7
  require 'k_log'
7
8
  require 'k_type'
8
9
  require 'k_util'
9
10
  require 'k_decor'
10
11
 
11
12
  require 'k_doc/version'
13
+ require 'k_doc/mixins/guarded'
14
+ require 'k_doc/mixins/taggable'
15
+ require 'k_doc/mixins/datum'
16
+ require 'k_doc/mixins/block_processor'
17
+ require 'k_doc/mixins/composable_components'
12
18
  require 'k_doc/container'
13
19
  # require 'k_doc/data'
20
+ require 'k_doc/csv_doc'
21
+ require 'k_doc/json_doc'
22
+ require 'k_doc/yaml_doc'
14
23
  require 'k_doc/model'
15
24
  require 'k_doc/fake_opinion'
16
25
  require 'k_doc/settings'
17
26
  require 'k_doc/table'
18
- require 'k_doc/util'
19
27
 
20
28
  require 'k_doc/decorators/settings_decorator'
21
29
  require 'k_doc/decorators/table_decorator'
@@ -25,20 +33,48 @@ module KDoc
25
33
  class Error < StandardError; end
26
34
 
27
35
  class << self
28
- # Factory method to create a new model
29
36
  def model(key = nil, **options, &block)
30
37
  model = KDoc::Model.new(key, **options, &block)
31
38
  model.execute_block
32
39
  model
33
40
  end
34
41
 
42
+ # These need to be registerable
43
+ def document(key = nil, **options, &block)
44
+ model(key, **{ type: :document }.merge(**options), &block)
45
+ end
46
+
47
+ def bootstrap(key = nil, **options, &block)
48
+ model(key, **{ type: :bootstrap }.merge(**options), &block)
49
+ end
50
+
51
+ def app_settings(key = nil, **options, &block)
52
+ model(key, **{ type: :app_settings }.merge(**options), &block)
53
+ end
54
+
55
+ def csv(key = nil, **options, &block)
56
+ doc = KDoc::CsvDoc.new(key, **options, &block)
57
+ doc.execute_block
58
+ doc
59
+ end
60
+
61
+ def json(key = nil, **options, &block)
62
+ doc = KDoc::JsonDoc.new(key, **options, &block)
63
+ doc.execute_block
64
+ doc
65
+ end
66
+
67
+ def yaml(key = nil, **options, &block)
68
+ doc = KDoc::YamlDoc.new(key, **options, &block)
69
+ doc.execute_block
70
+ doc
71
+ end
72
+
35
73
  attr_accessor :opinion
36
- attr_accessor :util
37
74
  attr_accessor :log
38
75
  end
39
76
 
40
77
  KDoc.opinion = KDoc::FakeOpinion.new
41
- KDoc.util = KDoc::Util.new
42
78
  end
43
79
 
44
80
  if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
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.16
4
+ version: 0.0.22
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-24 00:00:00.000000000 Z
11
+ date: 2021-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -88,6 +88,15 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - ".builders/directors/_.rb"
92
+ - ".builders/directors/build_actions.rb"
93
+ - ".builders/directors/design_pattern_director.rb"
94
+ - ".builders/directors/director.rb"
95
+ - ".builders/directors/klue_director.rb"
96
+ - ".builders/initializers/_.rb"
97
+ - ".builders/initializers/configure_builder.rb"
98
+ - ".builders/initializers/handlebars_helpers.rb"
99
+ - ".builders/setup.rb"
91
100
  - ".github/workflows/main.yml"
92
101
  - ".gitignore"
93
102
  - ".rspec"
@@ -111,21 +120,27 @@ files:
111
120
  - k_doc.gemspec
112
121
  - lib/k_doc.rb
113
122
  - lib/k_doc/container.rb
123
+ - lib/k_doc/csv_doc.rb
114
124
  - lib/k_doc/decorators/settings_decorator.rb
115
125
  - lib/k_doc/decorators/table_decorator.rb
116
126
  - lib/k_doc/fake_opinion.rb
127
+ - lib/k_doc/json_doc.rb
128
+ - lib/k_doc/mixins/block_processor.rb
129
+ - lib/k_doc/mixins/composable_components.rb
130
+ - lib/k_doc/mixins/datum.rb
131
+ - lib/k_doc/mixins/guarded.rb
132
+ - lib/k_doc/mixins/taggable.rb
117
133
  - lib/k_doc/model.rb
134
+ - lib/k_doc/model_backup.rb
118
135
  - lib/k_doc/settings.rb
119
136
  - lib/k_doc/table.rb
120
- - lib/k_doc/util.rb
121
137
  - lib/k_doc/version.rb
138
+ - lib/k_doc/yaml_doc.rb
122
139
  homepage: http://appydave.com/gems/k-doc
123
140
  licenses:
124
141
  - MIT
125
142
  metadata:
126
- homepage_uri: http://appydave.com/gems/k-doc
127
- source_code_uri: https://github.com/klueless-io/k_doc
128
- changelog_uri: https://github.com/klueless-io/k_doc/commits/master
143
+ rubygems_mfa_required: 'true'
129
144
  post_install_message:
130
145
  rdoc_options: []
131
146
  require_paths:
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_model_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