k_doc 0.0.18 → 0.0.24

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: 28959da3b25b7817899193c0b0057e42750783a561e8190de4f6af82be5116c9
4
- data.tar.gz: c55996060304324b439d6a02d3a0993279a9f76dee8468802486a9e92cf958e3
3
+ metadata.gz: 62acce8bfac2c242082dd6cf050db2d7e6c535bc6af229f50b4185aec7573261
4
+ data.tar.gz: 23b23c0dffa5da8de05f88c0f470aa63dbdfe3f734582872debf0a74edd1c8fc
5
5
  SHA512:
6
- metadata.gz: e5c7303c8d1d9f0b6b90c1071c46d20852ed7796ba3410e2267f5fc42af55dc9ac7d20ff43d1c9a228f6779b67a1e9da0ecdde0b0fffe42b2b87811571af7d72
7
- data.tar.gz: e464b9117c83fdd72fc25a1bb17815ff62cf58a74b6e4f197c070eccf588ecd45e99ca25ff7985b06b1dd889e0fa62c1fd7adffc29c6b3bc2b50870ae13e88eb
6
+ metadata.gz: 3762d2ab76f5d4128a2330ea7ad84db2234bea4a56bec313ade497691a46df0f0e20aec4445268647b49d2d68279c3c5730d0ebdecd0b2dba0e48d15b7d77ded
7
+ data.tar.gz: 8e9054976e5e0fbe40e9a27cb3e5244cbd451b5d67c30246d874348b75fd17877774ac0dd819da017db8a3c02439e7fe70aa1fee9887c292d4d0c8997187fad6
@@ -0,0 +1,10 @@
1
+ require_relative './build_actions'
2
+ require_relative './director'
3
+ # require_relative './gem_director'
4
+ require_relative './klue_director'
5
+ require_relative './design_pattern_director'
6
+
7
+ def klue
8
+ @klue ||= KlueDirector.new
9
+ end
10
+
@@ -0,0 +1,39 @@
1
+ module BuildActions
2
+ def cd(folder_key)
3
+ @builder.cd(folder_key)
4
+
5
+ self
6
+ end
7
+
8
+ def add_file(file, **opts)
9
+ @builder.add_file(file, **opts)
10
+
11
+ self
12
+ end
13
+
14
+ def delete_file(file, **opts)
15
+ @builder.delete_file(file, **opts)
16
+
17
+ self
18
+ end
19
+
20
+ def add_clipboard(**opts)
21
+ @builder.add_clipboard(**opts)
22
+
23
+ self
24
+ end
25
+
26
+ def open
27
+ builder.open
28
+
29
+ self
30
+ end
31
+ alias o open
32
+
33
+ def open_template
34
+ builder.open_template
35
+
36
+ self
37
+ end
38
+ alias ot open_template
39
+ end
@@ -0,0 +1,39 @@
1
+ class DesignPatternDirector < Director
2
+ include BuildActions
3
+
4
+ def del(file, *_params, **opts)
5
+ delete_file(file, **opts)
6
+
7
+ self
8
+ end
9
+ alias dadd del
10
+
11
+ def add(output_file, template_file = nil, **opts)
12
+ template_file = output_file if template_file.nil?
13
+
14
+ opts = {
15
+ template_file: template_file,
16
+ on_exist: :write
17
+ }.merge(opts)
18
+
19
+ add_file(output_file, **opts)
20
+ puts output_file
21
+
22
+ self
23
+ end
24
+
25
+ # This pattern would be great as a configurable generic class
26
+ #
27
+ # children could be renamed as:
28
+ # - directors
29
+ # - components
30
+ # - elements
31
+ def composite(name:, relative_path:, **opts)
32
+ opts = { name: name }.merge(opts)
33
+ cd(:lib)
34
+ add(File.join(relative_path, "#{name}.rb"), "composite/composite.rb", **opts)
35
+ cd(:spec)
36
+ add(File.join(relative_path, "#{name}_spec.rb"), "composite/composite_spec.rb", **opts)
37
+ self
38
+ end
39
+ end
@@ -0,0 +1,185 @@
1
+ class Director
2
+ include KType::Composite
3
+ # Should this be on the base class, or setup as needed on child directors?
4
+
5
+ attr_reader :builder
6
+
7
+ # Maybe Deprecate
8
+ attr_reader :director_types
9
+
10
+ def initialize(parent = nil, **opts)
11
+ attach_parent(parent)
12
+
13
+ reset_settings
14
+ process_options(opts)
15
+ end
16
+
17
+ def init(opts)
18
+ reset_settings
19
+ process_options(opts)
20
+
21
+ self
22
+ rescue => ex
23
+ log.exception(ex)
24
+ end
25
+
26
+ def reset
27
+ reset_settings
28
+
29
+ self
30
+ rescue => ex
31
+ log.exception(ex)
32
+ end
33
+
34
+ def register(name, klass)
35
+ register_director(name, klass)
36
+
37
+ self
38
+ rescue => ex
39
+ log.exception(ex)
40
+ end
41
+
42
+ def back
43
+ navigate_parent
44
+ end
45
+
46
+ def with(director, &block)
47
+ change_director = director(director)
48
+ change_director.instance_eval(&block)
49
+ navigate_parent
50
+ end
51
+
52
+ def help(*topics) #**opts)
53
+ if topics.blank?
54
+ help_actions
55
+ return
56
+ end
57
+
58
+ help_actions if topics.include?(:all)
59
+ help_channels if topics.include?(:channels)
60
+ rescue => ex
61
+ log.exception(ex)
62
+ end
63
+
64
+ def director(name)
65
+ @director ||= Hash.new do |add_to_hash, key|
66
+ raise "Director not registered: #{key}" unless has_child?(key)
67
+ director = get_child(key)
68
+ add_to_hash[key] = director.klass.new(self).init(builder_config_name: key)
69
+ end
70
+ @director[name]
71
+ rescue => ex
72
+ log.exception(ex)
73
+ end
74
+
75
+ def guard(message)
76
+ log.error(message)
77
+
78
+ self
79
+ end
80
+
81
+
82
+ # def director(type, name)
83
+ # Setup.config(type).debug
84
+ # end
85
+
86
+ def debug
87
+ # puts 'debug'
88
+ # puts children
89
+ # puts director_types
90
+ if builder
91
+ builder.debug
92
+ else
93
+ log.error "No builder"
94
+ end
95
+
96
+ director_types.keys.each do |key|
97
+ log.section_heading(key)
98
+ log.structure director_types[key]
99
+ end
100
+
101
+ self
102
+ end
103
+
104
+ private
105
+
106
+ # Composite Pattern Custom Implementation - BEGIN
107
+
108
+ def has_child?(key)
109
+ @children.key?(key)
110
+ end
111
+
112
+ def get_child(key)
113
+ @children[key]
114
+ end
115
+
116
+ def add_child(key, child)
117
+ @children[key] = child
118
+ end
119
+
120
+ def reset_children
121
+ @children = {}
122
+ end
123
+
124
+ # Composite Pattern Custom Implementation - END
125
+
126
+ def register_director(name, klass)
127
+ if has_child?(name)
128
+ log.error "Director has already been registered: #{name}"
129
+ return
130
+ end
131
+
132
+ add_director(name, klass)
133
+ rescue => ex
134
+ log.exception(ex)
135
+ end
136
+
137
+ def add_director(name, klass)
138
+ director = OpenStruct.new(name: name, klass: klass)
139
+
140
+ # Adding a director should create a new method for accessing that director
141
+ add_child(name, director)
142
+ rescue => ex
143
+ log.exception(ex)
144
+ end
145
+
146
+ # HELP
147
+
148
+ def help_actions
149
+ log.warn 'Help about actions available from this class'
150
+ end
151
+
152
+ def help_channels
153
+ log.warn 'Help about channels'
154
+ debug
155
+ end
156
+
157
+ def reset_settings
158
+ @builder = nil
159
+ reset_children
160
+ @director_types = {}
161
+ end
162
+
163
+ def process_options(opts)
164
+ attach_builder(opts)
165
+ rescue => ex
166
+ log.exception(ex)
167
+ end
168
+
169
+ # If builder is provided then use it
170
+ # If builder configuration is provided
171
+ # If builder config_name is provided
172
+
173
+ def attach_builder(opts)
174
+ return if @builder
175
+
176
+ log.warning("options :builder and :builder_config_name are mutually exclusive, will use opts[:builder]") if opts[:builder] && opts[:builder_config_name]
177
+
178
+ # Use the provided builder
179
+ @builder = opts[:builder] if opts[:builder]
180
+
181
+ return if @builder
182
+
183
+ @builder = KBuilder::BaseBuilder.init(KBuilder.configuration(opts[:builder_config_name]))
184
+ end
185
+ end
@@ -0,0 +1,5 @@
1
+ class KlueDirector < Director
2
+ def design_patterns
3
+ director(:design_patterns)
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'k_log'
2
+ require 'k_util'
3
+
4
+ include KLog::Logging
5
+
6
+ require_relative './configure_builder'
7
+ require_relative './handlebars_helpers'
@@ -0,0 +1,38 @@
1
+ KBuilder.reset(:gem)
2
+ KBuilder.configure(:gem) do |config|
3
+ # config.template_folders.add(:global , '~/dev/kgems/k_templates/definitions/genesis')
4
+ config.target_folders.add(:root , File.expand_path('..', Dir.getwd))
5
+ config.target_folders.add(:lib , :root, 'lib', 'k_doc')
6
+ config.target_folders.add(:spec , :root, 'spec', 'k_doc')
7
+ end
8
+
9
+ KBuilder.reset(:design_patterns)
10
+ KBuilder.configure(:design_patterns) do |config|
11
+ config.template_folders.add(:global , '~/dev/kgems/k_templates/templates/ruby_design_patterns')
12
+ config.target_folders.add(:root , File.expand_path('..', Dir.getwd))
13
+ config.target_folders.add(:lib , :root, 'lib', 'k_doc')
14
+ config.target_folders.add(:spec , :root, 'spec', 'k_doc')
15
+ end
16
+
17
+ # KBuilder.configuration(:gem).debug
18
+
19
+ # def builder
20
+ # @builder ||= KBuilder::BaseBuilder.init
21
+ # end
22
+
23
+ puts ':)'
24
+
25
+ # Setup.configure(:microapp) do |config|
26
+ # config.template_folders.add(:microapp , '~/dev/kgems/k_templates/definitions/microapp')
27
+ # config.target_folders.add(:root , Dir.getwd)
28
+ # end
29
+
30
+ # Setup.configure(:data) do |config|
31
+ # # config.template_folders.add(:microapp , '~/dev/kgems/k_templates/definitions/microapp')
32
+ # config.target_folders.add(:root , File.expand_path('..', Dir.getwd), '.data')
33
+ # end
34
+
35
+ # Setup.configure(:actual_app) do |config|
36
+ # # config.template_folders.add(:microapp , '~/dev/kgems/k_templates/definitions/microapp')
37
+ # config.target_folders.add(:root , File.expand_path('..', Dir.getwd))
38
+ # end
@@ -0,0 +1,27 @@
1
+ Handlebars::Helpers.configure do |config|
2
+ config_file = File.join(Gem.loaded_specs['handlebars-helpers'].full_gem_path, '.handlebars_helpers.json')
3
+ config.helper_config_file = config_file
4
+
5
+ string_config_file = File.join(Gem.loaded_specs['handlebars-helpers'].full_gem_path, '.handlebars_string_formatters.json')
6
+ config.string_formatter_config_file = string_config_file
7
+ end
8
+
9
+ def camel
10
+ require 'handlebars/helpers/string_formatting/camel'
11
+ Handlebars::Helpers::StringFormatting::Camel.new
12
+ end
13
+
14
+ def titleize
15
+ require 'handlebars/helpers/string_formatting/titleize'
16
+ Handlebars::Helpers::StringFormatting::Titleize.new
17
+ end
18
+
19
+ def pluralize
20
+ require 'handlebars/helpers/inflection/pluralize'
21
+ Handlebars::Helpers::Inflection::Pluralize.new
22
+ end
23
+
24
+ def singularize
25
+ require 'handlebars/helpers/inflection/singularize'
26
+ Handlebars::Helpers::Inflection::Singularize.new
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'initializers/_'
2
+ require 'directors/_'
3
+
4
+ klue
5
+ .reset
6
+ .register(:design_patterns , DesignPatternDirector)
7
+
8
+ klue
9
+ .with(:design_patterns) do
10
+ composite(
11
+ relative_path: 'mixins',
12
+ name: :composite_spec,
13
+ namespace: 'KDoc',
14
+ children_name: :child,
15
+ children_name_plural: :children)
16
+ end
17
+
18
+ puts '...'
data/Guardfile CHANGED
@@ -19,7 +19,7 @@ group :green_pass_then_cop, halt_on_fail: true do
19
19
  # Ruby files
20
20
  ruby = dsl.ruby
21
21
  dsl.watch_spec_files_for(ruby.lib_files)
22
- watch(%r{^lib/k_doc/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
22
+ watch(%r{^lib/k_doc/**/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
23
23
  watch(%r{^lib/k_doc/commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
24
24
  end
25
25
 
data/k_doc.gemspec CHANGED
@@ -44,4 +44,7 @@ Gem::Specification.new do |spec|
44
44
  spec.add_dependency 'k_type' , '~> 0.0.0'
45
45
  spec.add_dependency 'k_util' , '~> 0.0.0'
46
46
  # spec.add_dependency 'tty-box', '~> 0.5.0'
47
+ spec.metadata = {
48
+ 'rubygems_mfa_required' => 'true'
49
+ }
47
50
  end
@@ -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
@@ -1,50 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KDoc
4
- # A data acts a base data object for any data requires tagging such as
5
- # unique key, type and namespace.
4
+ # A container acts a base data object for any data that requires tagging
5
+ # such as unique key, type and namespace.
6
6
  class Container
7
- # include KLog::Logging
8
-
9
- # Name of the document (required)
10
- #
11
- # Examples: user, account, country
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
21
- attr_reader :type
22
-
23
- attr_writer :data
24
-
25
- attr_reader :error
26
-
27
- # Create container for storing data/documents.
28
- #
29
- # Any container can be uniquely identified via it's
30
- # key, type, namespace and project_key attributes
31
- #
32
- # @param [Hash] **opts The options
33
- # @option opts [String|Symbol] name Name of the container
34
- # @option opts [String|Symbol] type Type of the container, defaults to KDoc:: FakeOpinion.new.default_model_type if not set
35
- def initialize(**opts)
36
- @key = opts[:key] || SecureRandom.alphanumeric(4)
37
- @type = opts[:type] || ''
38
- @data = opts[:data] || {}
7
+ include KLog::Logging
8
+ include KDoc::Guarded
9
+ include KDoc::Taggable
10
+ include KDoc::Datum
11
+ include KDoc::BlockProcessor
12
+
13
+ attr_reader :opts
14
+
15
+ # TODO: Owner/Owned need to be in a module and tested
16
+ attr_accessor :owner
17
+
18
+ def owned?
19
+ @owner != nil
20
+ end
21
+
22
+ def initialize(**opts, &block)
23
+ @opts = opts
24
+
25
+ initialize_tag(opts)
26
+ initialize_data(opts)
27
+ initialize_block(opts, &block)
39
28
  end
40
29
 
41
- def debug_header
42
- log.kv 'key' , key , 15
43
- log.kv 'type' , type , 15
30
+ def default_container_type
31
+ :container
44
32
  end
45
33
 
46
- def data
47
- @data.clone
34
+ def default_data_type
35
+ @default_data_type ||= Hash
36
+ end
37
+
38
+ def debug
39
+ debug_container
40
+ debug_errors
41
+ end
42
+
43
+ private
44
+
45
+ def debug_errors
46
+ log.block(errors, title: 'errors') unless valid?
48
47
  end
49
48
  end
50
49
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ module KDoc
6
+ # CsvDoc is a DSL for modeling CSV data objects
7
+ class CsvDoc < KDoc::Container
8
+ attr_reader :file
9
+
10
+ # Create CSV 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
+ rows = []
35
+
36
+ CSV.foreach(file, headers: true, header_converters: :symbol) do |row|
37
+ rows << row.to_h
38
+ end
39
+
40
+ set_data(rows, data_action: data_action)
41
+
42
+ @loaded = true
43
+ end
44
+
45
+ def loaded?
46
+ @loaded
47
+ end
48
+
49
+ private
50
+
51
+ def initialize_file
52
+ @file ||= opts.delete(:file) || ''
53
+ @loaded = false
54
+ end
55
+
56
+ def default_data_type
57
+ Array
58
+ end
59
+
60
+ def default_container_type
61
+ :csv
62
+ end
63
+ end
64
+ end
@@ -5,8 +5,13 @@ require 'json'
5
5
  module KDoc
6
6
  # This is called fake opinion because I have not figured out
7
7
  # how I want to implement this
8
+ # Need to look at the configuration patterns, this is really a configuration
8
9
  class FakeOpinion
10
+ attr_accessor :default_action_type
9
11
  attr_accessor :default_model_type
12
+ attr_accessor :default_csv_type
13
+ attr_accessor :default_json_type
14
+ attr_accessor :default_yaml_type
10
15
  attr_accessor :default_settings_key
11
16
  attr_accessor :default_table_key
12
17
 
@@ -15,7 +20,12 @@ module KDoc
15
20
  attr_accessor :table_class
16
21
 
17
22
  def initialize
18
- @default_model_type = :entity
23
+ # @default_model_type = :entity
24
+ @default_action_type = :action
25
+ @default_model_type = :kdoc
26
+ @default_csv_type = :csv
27
+ @default_json_type = :json
28
+ @default_yaml_type = :yaml
19
29
  @default_settings_key = :settings
20
30
  @default_table_key = :table
21
31
 
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDoc
4
+ # JsonDoc is a DSL for modeling JSON data objects
5
+ class JsonDoc < KDoc::Container
6
+ attr_reader :file
7
+
8
+ # Create JSON document
9
+ #
10
+ # @param [String|Symbol] name Name of the document
11
+ # @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new.default_csv_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
+
17
+ initialize_file
18
+ end
19
+
20
+ # Load data from file
21
+ #
22
+ # @param [Symbol] load_action The load_action to take if data has already been loaded
23
+ # @param [:once] load_action :once will load the data from content source on first try only
24
+ # @param [:reload] load_action :reload will reload from content source each time
25
+ # @param [Symbol] data_action The data_action to take when setting data, defaults to :replace
26
+ # @param [:replace] data_action :replace will replace the existing data instance with the incoming data value
27
+ # @param [:append] data_action :append will keep existing data and then new value data over the top
28
+ def load(load_action: :once, data_action: :replace)
29
+ return if load_action == :once && loaded?
30
+
31
+ content = File.read(file)
32
+ hash = JSON.parse(content)
33
+
34
+ set_data(hash, data_action: data_action)
35
+
36
+ @loaded = true
37
+ end
38
+
39
+ def loaded?
40
+ @loaded
41
+ end
42
+
43
+ private
44
+
45
+ def initialize_file
46
+ @file ||= opts.delete(:file) || ''
47
+ @loaded = false
48
+ end
49
+
50
+ def default_data_type
51
+ Hash
52
+ end
53
+
54
+ def default_container_type
55
+ :json
56
+ end
57
+ end
58
+ end