k_manager 0.0.13 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/Gemfile +18 -0
  4. data/Rakefile +2 -0
  5. data/docs/flow.drawio +16 -0
  6. data/exe/k_manager +20 -0
  7. data/k_manager.gemspec +6 -0
  8. data/lib/k_manager/area.rb +47 -0
  9. data/lib/k_manager/document_factory.rb +74 -0
  10. data/lib/k_manager/manager.rb +58 -0
  11. data/lib/k_manager/overview/dashboard.rb +187 -0
  12. data/lib/k_manager/overview/dump_json.rb +35 -0
  13. data/lib/k_manager/overview/models.rb +76 -0
  14. data/lib/k_manager/overview/queries.rb +53 -0
  15. data/lib/k_manager/resources/base_resource.rb +189 -52
  16. data/lib/k_manager/resources/file_resource.rb +80 -58
  17. data/lib/k_manager/resources/{ruby_file_resource.rb → file_resources/ruby_file_resource.rb} +0 -0
  18. data/lib/k_manager/resources/{unknown_file_resource.rb → file_resources/unknown_file_resource.rb} +0 -0
  19. data/lib/k_manager/resources/mem_resource.rb +17 -0
  20. data/lib/k_manager/resources/resource_document_factory.rb +119 -0
  21. data/lib/k_manager/resources/resource_factory.rb +28 -0
  22. data/lib/k_manager/resources/resource_manager.rb +216 -0
  23. data/lib/k_manager/resources/resource_set.rb +90 -0
  24. data/lib/k_manager/resources/web_resource.rb +113 -0
  25. data/lib/k_manager/version.rb +1 -1
  26. data/lib/k_manager/watcher.rb +75 -0
  27. data/lib/k_manager/{x_project.rb → x_resource_documents/x_project.rb} +0 -0
  28. data/lib/k_manager/{x_project_manager.rb → x_resource_documents/x_project_manager.rb} +0 -0
  29. data/lib/k_manager/{x_register.rb → x_resource_documents/x_register.rb} +0 -0
  30. data/lib/k_manager.rb +93 -20
  31. data/tasks/watch.rake +113 -0
  32. metadata +70 -24
  33. data/Assessment1.md +0 -127
  34. data/Assessment2.md +0 -88
  35. data/lib/k_manager/create_document.rb +0 -31
  36. data/lib/k_manager/documents/basic_document.rb +0 -21
  37. data/lib/k_manager/documents/builder_document.rb +0 -18
  38. data/lib/k_manager/documents/document_taggable.rb +0 -94
  39. data/lib/k_manager/documents/model_document.rb +0 -19
  40. data/lib/k_manager/project.rb +0 -50
  41. data/lib/k_manager/resources/csv_file_resource.rb +0 -27
  42. data/lib/k_manager/resources/factories/document_factory.rb +0 -52
  43. data/lib/k_manager/resources/json_file_resource.rb +0 -22
  44. data/lib/k_manager/resources/yaml_file_resource.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e1e2ee281f38810223b80d27b7ed6ba17f6d766c9bc3362925cb781faea6e6f
4
- data.tar.gz: cce3bcc06ce095f5f00c55bc60ac47b0ea493930db4ebed635fe106303cf5957
3
+ metadata.gz: 2024c747b3ae20e56a669bda4c2940274007a63545759cf1fc93adc0a9ae5b40
4
+ data.tar.gz: 12030613016449e807b986cc368330bf6d4667cd89833051511c48ff7dd21c0b
5
5
  SHA512:
6
- metadata.gz: 7c6154b2a689a193cc88415d89959ca564783b04ee256a74c9a845c3d94102c2ae69be11d47e6cf01cc8e75ca52784d2f4a5b4cb8f373be074112464e7a1da5c
7
- data.tar.gz: 70e7121af0c37a4458670b4668e4e8a9f0e4c798e317bca98ccdb27414529b4b7966373f0689a654991eefabdd9af783536aba33691c54b844cc51ade55071c5
6
+ metadata.gz: f8746ca5b44f389938b92f8a17ca9c7947e560fc65046c5b780cbca3bcbfc0180e9035002cb0a9cc00c9b0f0e70277f7b631523e5b9976bdeff9adac19389eab
7
+ data.tar.gz: dba116da1e201cd22c39a2fdc68805dd9e8d019bfbdb7b5eb6a0d7bd283fb99a07dded3762b8c7b484a3015e62fd98ed29b16ee05ac0d8b7192049b4dde17a25
data/.rubocop.yml CHANGED
@@ -7,6 +7,7 @@ AllCops:
7
7
  Exclude:
8
8
  - "_/**/*"
9
9
  - "spec/samples/**/*"
10
+ - "spec/k_manager/scenarios/**/*"
10
11
 
11
12
  Metrics/BlockLength:
12
13
  Exclude:
data/Gemfile CHANGED
@@ -23,3 +23,21 @@ group :development, :test do
23
23
  gem 'rubocop-rake', require: false
24
24
  gem 'rubocop-rspec', require: false
25
25
  end
26
+
27
+ # If local dependency
28
+ if ENV['KLUE_LOCAL_GEMS']&.to_s&.downcase == 'true'
29
+ group :development, :test do
30
+ puts 'Using Local GEMs'
31
+ gem 'handlebars-helpers' , path: '../handlebars-helpers'
32
+ gem 'k_builder' , path: '../k_builder'
33
+ gem 'k_builder-dotnet' , path: '../k_builder-dotnet'
34
+ gem 'k_builder-package_json' , path: '../k_builder-package_json'
35
+ gem 'k_builder-webpack5' , path: '../k_builder-webpack5'
36
+ gem 'k_decor' , path: '../k_decor'
37
+ gem 'k_doc' , path: '../k_doc'
38
+ gem 'k_domain' , path: '../k_domain'
39
+ gem 'k_log' , path: '../k_log'
40
+ gem 'k_type' , path: '../k_type'
41
+ gem 'k_util' , path: '../k_util'
42
+ end
43
+ end
data/Rakefile CHANGED
@@ -8,6 +8,8 @@ require 'bundler/gem_tasks'
8
8
  require 'rspec/core/rake_task'
9
9
  require 'k_manager/version'
10
10
 
11
+ Dir.glob('tasks/*.rake').each { |r| import r }
12
+
11
13
  RSpec::Core::RakeTask.new(:spec)
12
14
 
13
15
  require 'rake/extensiontask'
data/docs/flow.drawio ADDED
@@ -0,0 +1,16 @@
1
+ <mxfile host="65bd71144e">
2
+ <diagram id="AE9tsI4e_FXgj975v7li" name="Page-1">
3
+ <mxGraphModel dx="1087" dy="583" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" background="#ffffff" math="0" shadow="0">
4
+ <root>
5
+ <mxCell id="0"/>
6
+ <mxCell id="1" parent="0"/>
7
+ <mxCell id="2" value="KManager" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
8
+ <mxGeometry x="200" y="70" width="120" height="60" as="geometry"/>
9
+ </mxCell>
10
+ <mxCell id="3" value="" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
11
+ <mxGeometry x="390" y="210" width="120" height="60" as="geometry"/>
12
+ </mxCell>
13
+ </root>
14
+ </mxGraphModel>
15
+ </diagram>
16
+ </mxfile>
data/exe/k_manager ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'pry'
6
+
7
+ lib_path = File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
8
+ gem_path = File.expand_path(File.join(File.dirname(__FILE__), '../Gemfile'))
9
+
10
+ $LOAD_PATH.unshift(lib_path)
11
+
12
+ ENV['BUNDLE_GEMFILE'] = gem_path
13
+
14
+ require 'bundler/setup'
15
+ require 'k_manager'
16
+
17
+ puts 'david'
18
+ # options = KBuilder::Watch::Cli.parse_options
19
+
20
+ # KBuilder::Watch::Execute.new(options).run
data/k_manager.gemspec CHANGED
@@ -38,10 +38,16 @@ Gem::Specification.new do |spec|
38
38
  spec.require_paths = ['lib']
39
39
  # spec.extensions = ['ext/k_manager/extconf.rb']
40
40
 
41
+ spec.add_dependency 'dry-struct', '~> 1'
42
+ spec.add_dependency 'filewatcher', '~> 2.0.0.beta5'
41
43
  spec.add_dependency 'k_builder', '~> 0.0.0'
42
44
  spec.add_dependency 'k_doc', '~> 0.0.0'
43
45
  spec.add_dependency 'k_ext-github', '~> 0.0.0'
46
+ spec.add_dependency 'k_fileset', '~> 0.0.0'
44
47
  spec.add_dependency 'k_log', '~> 0.0.0'
45
48
  # spec.add_dependency 'k_type' , '~> 0.0.0'
46
49
  # spec.add_dependency 'k_util' , '~> 0.0.0'
50
+ spec.metadata = {
51
+ 'rubygems_mfa_required' => 'true'
52
+ }
47
53
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KManager
4
+ class Area
5
+ include KLog::Logging
6
+ extend Forwardable
7
+
8
+ # TODO: I have not got a use for area name yet, it may be able to drive default config, but not sure.
9
+ attr_reader :name
10
+ attr_reader :namespace
11
+ attr_reader :config
12
+
13
+ def initialize(**opts)
14
+ @name = opts[:name]
15
+
16
+ raise 'Area name is required' unless @name
17
+
18
+ @namespace = opts[:namespace] || @name
19
+ @config = KBuilder.configuration(@name)
20
+ end
21
+
22
+ def resource_manager
23
+ @resource_manager ||= KManager::Resources::ResourceManager.new(self)
24
+ end
25
+
26
+ def_delegators :resource_manager, :resource_changed
27
+
28
+ def debug(*sections)
29
+ log.kv 'Area' , name
30
+ log.kv 'Namespace' , namespace
31
+
32
+ resource_manager.debug if sections.include?(:resource) || sections.include?(:resources)
33
+ config.debug if sections.include?(:config)
34
+ end
35
+
36
+ # rubocop:disable Metrics/AbcSize
37
+ def attribute_values(prefix = nil)
38
+ result = {}
39
+ result["#{prefix}name".to_sym] = name
40
+ result["#{prefix}namespace".to_sym] = namespace
41
+ result["#{prefix}resource_count".to_sym] = resource_manager.resources.length
42
+ result["#{prefix}document_count".to_sym] = resource_manager.resources.sum { |resource| resource.documents.length }
43
+ result
44
+ end
45
+ # rubocop:enable Metrics/AbcSize
46
+ end
47
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KManager
4
+ # Factories for creating common DSL documents quickly
5
+ #
6
+ # Example:
7
+ #
8
+ # KManager.csv(file: 'somepath/somefile.csv') do
9
+ # load
10
+ # end
11
+ class DocumentFactory
12
+ include KLog::Logging
13
+
14
+ # Create a KDoc::Model instance
15
+ def model(key = nil, **opts, &block)
16
+ document = new_document(KDoc::Model, key, **opts, &block)
17
+
18
+ attach_to_current_resource(document, change_content_type: :dsl)
19
+ end
20
+
21
+ # Create a KDoc::CsvDoc instance
22
+ def csv(key = nil, **opts, &block)
23
+ document = new_document(KDoc::CsvDoc, key, **opts, &block)
24
+
25
+ attach_to_current_resource(document, change_content_type: :dsl)
26
+ rescue StandardError => e
27
+ log.error(e)
28
+ end
29
+
30
+ # Create a KDoc::JsonDoc instance
31
+ def json(key = nil, **opts, &block)
32
+ document = new_document(KDoc::JsonDoc, key, **opts, &block)
33
+
34
+ attach_to_current_resource(document, change_content_type: :dsl)
35
+ rescue StandardError => e
36
+ log.error(e)
37
+ end
38
+
39
+ # Create a KDoc::YamlDoc instance
40
+ def yaml(key = nil, **opts, &block)
41
+ document = new_document(KDoc::YamlDoc, key, **opts, &block)
42
+
43
+ attach_to_current_resource(document, change_content_type: :dsl)
44
+ rescue StandardError => e
45
+ log.error(e)
46
+ end
47
+
48
+ private
49
+
50
+ # If document gets created dynamically due to class_eval then they
51
+ # can attach themselves to the currently focussed resource.
52
+ #
53
+ # It will throw an error if for_resource has not been called earlier
54
+ # in the thread lifecycle.
55
+ def attach_to_current_resource(document, change_content_type: nil)
56
+ return document unless KManager.current_resource
57
+
58
+ KManager.for_current_resource do |resource|
59
+ resource.attach_document(document, change_content_type: change_content_type)
60
+ end
61
+ end
62
+
63
+ # Create an instance of a document
64
+ #
65
+ # @param [Class<DocumentTaggable>] klass type of document to create
66
+ def new_document(klass, key = nil, **opts, &block)
67
+ # Should be able to infer
68
+ # key = KManager.current_resource.documents.length.zero? ? KManager.current_resource.infer_key : nil
69
+
70
+ # klass.new(key, **{ owner: KManager.current_resource }.merge(opts), &block)
71
+ klass.new(key, **opts, &block)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KManager
4
+ # KManager is designed to work with one or more areas of concern
5
+ #
6
+ # TODO: Write Tests
7
+ class Manager
8
+ def areas
9
+ @areas ||= []
10
+ end
11
+
12
+ def add_area(name, namespace: nil)
13
+ area = find_area(name)
14
+
15
+ return area if area
16
+
17
+ area = KManager::Area.new(name: name, namespace: namespace)
18
+ areas << area
19
+ area
20
+ end
21
+
22
+ def fire_actions(*actions)
23
+ areas.each do |area|
24
+ # delegate
25
+ area.resource_manager.fire_actions(*actions)
26
+ end
27
+ end
28
+
29
+ def find_area(name)
30
+ areas.find { |a| a.name == name }
31
+ end
32
+
33
+ def resource_changed(uri, state)
34
+ areas.each do |area|
35
+ area.resource_changed(uri, state)
36
+ end
37
+ end
38
+
39
+ def debug(*sections)
40
+ areas.each do |area|
41
+ area.debug(*sections)
42
+ end
43
+ end
44
+
45
+ # # May replace config with default channel name
46
+ # # Channels represent configurations that are independent of project or builder,
47
+ # # but a project may want to have a default channel that it supplies
48
+ # def initialize(name, config = nil, **opts)
49
+ # raise KType::Error, 'Provide a project name' unless name.is_a?(String) || name.is_a?(Symbol)
50
+
51
+ # @name = name
52
+ # @config = config || KManager::Configuration::ProjectConfig.new
53
+ # @resources = []
54
+
55
+ # initialize_opts(opts)
56
+ # end
57
+ end
58
+ end
@@ -0,0 +1,187 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KManager
4
+ module Overview
5
+ # Generate dashboard information on the console
6
+ #
7
+ # TODO: ConsoleDashboard and HtmlConsole
8
+ class Dashboard
9
+ include KLog::Logging
10
+
11
+ attr_reader :queries
12
+
13
+ def initialize(manager)
14
+ @queries = KManager::Overview::Queries.new(manager)
15
+ end
16
+
17
+ def areas
18
+ data = queries.areas.map { |hash| KManager::Overview::Area.new(hash) }
19
+ graph = {
20
+ areas: {
21
+ columns: [
22
+ :name,
23
+ :namespace,
24
+ { resource_count: { display_method: ->(row) { blank_zero(row.resource_count) } } },
25
+ { document_count: { display_method: ->(row) { blank_zero(row.document_count) } } }
26
+
27
+ ]
28
+ }
29
+ }
30
+ display(:areas, 'Areas', graph, data)
31
+ end
32
+
33
+ # rubocop:disable Metrics/AbcSize
34
+ def resources
35
+ # sort and remove repeating area
36
+ data = grouped_resources(queries.resources).map { |hash| KManager::Overview::Resource.new(hash) }
37
+ graph = {
38
+ resources: {
39
+ columns: [
40
+ { area: { display_method: ->(row) { row.area_name } } },
41
+ { area_ns: { display_method: ->(row) { row.area_namespace } } },
42
+ { resource_docs: { display_method: ->(row) { resource_document_count(row) } } },
43
+ { resource_id: { display_method: ->(row) { blank_zero(row.id) } } },
44
+ { key: { display_method: ->(row) { row.key } } },
45
+ { namespace: { display_method: ->(row) { row.namespace } } },
46
+ { status: { display_method: ->(row) { row.status } } },
47
+ { content_type: { display_method: ->(row) { row.content_type } } },
48
+ { content: { display_method: ->(row) { row.content } } },
49
+ { document_count: { display_method: ->(row) { blank_zero(row.document_count) } } },
50
+ { valid: { display_method: ->(row) { row.valid } } },
51
+ { error_count: { display_method: ->(row) { blank_zero(row.errors.length) } } },
52
+ { scheme: { display_method: ->(row) { row.scheme } } },
53
+ { root: { display_method: ->(row) { row.scheme == :file ? '' : row.host } } },
54
+ { relative_path: { display_method: ->(row) { right(50, row.relative_path) }, width: 50 } },
55
+ { exist: { display_method: ->(row) { row.exist } } }
56
+ ]
57
+ }
58
+ }
59
+
60
+ display(:resources, 'Resource List', graph, data)
61
+ end
62
+
63
+ def documents
64
+ data = grouped_documents(queries.documents).map { |hash| KManager::Overview::Document.new(hash) }
65
+
66
+ graph = {
67
+ resources: {
68
+ columns: [
69
+ { area: { display_method: ->(row) { row.area_name } } },
70
+ { area_ns: { display_method: ->(row) { row.area_namespace } } },
71
+ { resource_docs: { display_method: ->(row) { resource_document_count(row) } } },
72
+ { resource_id: { display_method: ->(row) { blank_zero(row.resource_id) } } },
73
+ # { key: { display_method: -> (row) { row.resource_key } } },
74
+ # { namespace: { display_method: -> (row) { row.resource_namespace } } },
75
+ # { status: { display_method: -> (row) { row.resource_status } } },
76
+ # { content_type: { display_method: -> (row) { row.resource_content_type } } },
77
+ # { content: { display_method: -> (row) { row.resource_content } } },
78
+ # { document_count: { display_method: -> (row) { blank_zero(row.resource_document_count) } } },
79
+ # { valid: { display_method: -> (row) { row.resource_valid } } },
80
+ # { error_count: { display_method: -> (row) { blank_zero(row.resource_errors.length) } } },
81
+ # { scheme: { display_method: -> (row) { row.resource_scheme } } },
82
+ # # { path: { display_method: -> (row) { row.resource_path } } },
83
+ # { exist: { display_method: -> (row) { row.resource_exist } } },
84
+ { document_id: { display_method: ->(row) { blank_zero(row.document_id) } } },
85
+ { data: { display_method: ->(row) { row.document_data } } },
86
+ { error_count: { display_method: ->(row) { blank_zero(row.document_errors.length) } } },
87
+ { key: { display_method: ->(row) { row.document_key } } },
88
+ { namespace: { display_method: ->(row) { row.document_namespace } } },
89
+ { tag: { display_method: ->(row) { row.document_tag } } },
90
+ { type: { display_method: ->(row) { row.document_type } } },
91
+ { relative_path: { display_method: ->(row) { right(50, resource_path_location(row.resource_relative_path, row.document_location)) }, width: 50 } }
92
+ ]
93
+ }
94
+ }
95
+
96
+ display(:resources, 'Document List', graph, data)
97
+ end
98
+ # rubocop:enable Metrics/AbcSize
99
+
100
+ private
101
+
102
+ def resource_path_location(path, location)
103
+ return path unless location
104
+
105
+ "#{path}:#{location}"
106
+ end
107
+
108
+ def display(section, title, graph, data)
109
+ data = {
110
+ section => data
111
+ }
112
+ opts = {
113
+ title: title,
114
+ title_type: :heading,
115
+ show_array_count: false,
116
+ graph: graph
117
+ }
118
+ log.structure(data, **opts)
119
+ end
120
+
121
+ def blank_zero(value)
122
+ return nil if value.nil? || (value.is_a?(Integer) && value.zero?)
123
+
124
+ value
125
+ end
126
+
127
+ def lpad(size, value)
128
+ value.to_s.rjust(size)
129
+ end
130
+
131
+ def right(size, value)
132
+ value.chars.last(size).join
133
+ end
134
+
135
+ def resource_document_count(row)
136
+ return nil if row.area_resource_count.nil? && row.area_document_count.nil?
137
+
138
+ resource = lpad(2, blank_zero(row.area_resource_count))
139
+ document = lpad(2, blank_zero(row.area_document_count))
140
+ [resource, document].join(' / ')
141
+ end
142
+
143
+ # rubocop:disable Metrics/AbcSize
144
+ def grouped_resources(resources)
145
+ return resources if resources.length < 2
146
+
147
+ grouped = resources.group_by { |resource| resource[:area_name] }
148
+ grouped.flat_map do |group|
149
+ group[1].map.with_index do |resource, index|
150
+ new_resource = resource.clone
151
+ if index.positive?
152
+ new_resource[:area_name] = nil
153
+ new_resource[:area_namespace] = nil
154
+ new_resource[:area_resource_count] = nil
155
+ new_resource[:area_document_count] = nil
156
+ end
157
+ new_resource
158
+ end
159
+ end
160
+ end
161
+
162
+ def grouped_documents(documents)
163
+ return documents if documents.length < 2
164
+
165
+ grouped = documents.group_by { |document| document[:area_name] }
166
+ grouped.flat_map do |group|
167
+ last_resource_id = 0
168
+ group[1].map.with_index do |document, index|
169
+ new_document = document.clone
170
+ if index.positive?
171
+ new_document[:area_name] = nil
172
+ new_document[:area_namespace] = nil
173
+ new_document[:area_resource_count] = nil
174
+ new_document[:area_document_count] = nil
175
+
176
+ new_document[:resource_id] = nil if last_resource_id == group[1][index][:resource_id]
177
+
178
+ end
179
+ last_resource_id = document[:resource_id]
180
+ new_document
181
+ end
182
+ end
183
+ end
184
+ # rubocop:enable Metrics/AbcSize
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KManager
4
+ module Overview
5
+ class DumpJson
6
+ attr_reader :path
7
+ attr_reader :queries
8
+
9
+ def initialize(path, manager)
10
+ @path = path
11
+ @queries = KManager::Overview::Queries.new(manager)
12
+ end
13
+
14
+ def areas(file_name)
15
+ dump(file_name, queries.areas)
16
+ end
17
+
18
+ def resources(file_name)
19
+ dump(file_name, queries.resources)
20
+ end
21
+
22
+ def documents(file_name)
23
+ dump(file_name, queries.documents)
24
+ end
25
+
26
+ private
27
+
28
+ def dump(file_name, data)
29
+ file = File.join(path, file_name)
30
+ json = JSON.pretty_generate(data)
31
+ File.write(file, json)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ # KDomain::Schemas::Domain::Column
4
+ # KDomain::Schemas::Domain::Model
5
+
6
+ module KManager
7
+ module Overview
8
+ module Types
9
+ include Dry.Types()
10
+ end
11
+
12
+ class Error < Dry::Struct
13
+ end
14
+
15
+ class Area < Dry::Struct
16
+ attribute :name , Types::Strict::String | Types::Strict::Symbol
17
+ attribute :namespace , Types::Strict::String.optional.default(nil) | Types::Strict::Symbol.optional.default(nil)
18
+ attribute :resource_count , Types::Strict::Integer
19
+ attribute :document_count , Types::Strict::Integer
20
+ end
21
+
22
+ class Resource < Dry::Struct
23
+ attribute :area_name , Types::Strict::String.optional.default(nil) | Types::Strict::Symbol.optional.default(nil)
24
+ attribute :area_namespace , Types::Strict::String.optional.default(nil) | Types::Strict::Symbol.optional.default(nil)
25
+ attribute :area_resource_count , Types::Strict::Integer.optional.default(nil)
26
+ attribute :area_document_count , Types::Strict::Integer.optional.default(nil)
27
+ attribute :id , Types::Strict::Integer
28
+ attribute :key , Types::Strict::String
29
+ attribute :namespace , Types::Strict::String | Types::Strict::Array.of(Types::Strict::String).optional.default(nil)
30
+ attribute :status , Types::Strict::String | Types::Strict::Symbol
31
+ attribute :source , Types::Strict::String
32
+ attribute :content_type , Types::Strict::String | Types::Strict::Symbol
33
+ attribute :content , Types::Strict::String.optional.default(nil)
34
+ attribute :document_count , Types::Strict::Integer
35
+ attribute :errors , Types::Strict::Array.of(KManager::Overview::Error).optional.default(nil)
36
+ attribute :valid? , Types::Strict::Bool
37
+ attribute :scheme , Types::Strict::String | Types::Strict::Symbol
38
+ attribute :host , Types::Strict::String
39
+ attribute :path , Types::Strict::String
40
+ attribute :relative_path , Types::Strict::String.optional.default(nil)
41
+ attribute :exist? , Types::Strict::Bool
42
+ end
43
+
44
+ class Document < Dry::Struct
45
+ attribute :area_name , Types::Strict::String.optional.default(nil) | Types::Strict::Symbol.optional.default(nil)
46
+ attribute :area_namespace , Types::Strict::String.optional.default(nil) | Types::Strict::Symbol.optional.default(nil)
47
+ attribute :area_resource_count , Types::Strict::Integer.optional.default(nil)
48
+ attribute :area_document_count , Types::Strict::Integer.optional.default(nil)
49
+ attribute :resource_id , Types::Strict::Integer.optional.default(nil)
50
+ attribute :resource_key , Types::Strict::String
51
+ attribute :resource_namespace , Types::Strict::Array.of(Types::Strict::String).optional.default(nil)
52
+ attribute :resource_status , Types::Strict::String | Types::Strict::Symbol
53
+ attribute :resource_source , Types::Strict::String
54
+ attribute :resource_content_type , Types::Strict::String | Types::Strict::Symbol
55
+ attribute :resource_content , Types::Strict::String.optional.default(nil)
56
+ attribute :resource_document_count , Types::Strict::Integer
57
+ attribute :resource_errors , Types::Strict::Array.of(KManager::Overview::Error).optional.default(nil)
58
+ attribute :resource_valid? , Types::Strict::Bool
59
+ attribute :resource_scheme , Types::Strict::String | Types::Strict::Symbol
60
+ attribute :resource_host , Types::Strict::String
61
+ attribute :resource_path , Types::Strict::String
62
+ attribute :resource_relative_path , Types::Strict::String.optional.default(nil)
63
+ attribute :resource_exist? , Types::Strict::Bool
64
+ attribute :document_id , Types::Strict::Integer
65
+ attribute :document_data , Types::Strict::Hash.optional.default(nil) | Types::Strict::Array.of(Types::Strict::Hash).optional.default(nil)
66
+ attribute :document_key , Types::Strict::String | Types::Strict::Symbol
67
+ attribute :document_namespace , Types::Strict::String | Types::Strict::Array.of(Types::Strict::String).optional.default(nil)
68
+ attribute :document_tag , Types::Strict::String | Types::Strict::Symbol
69
+ attribute :document_type , Types::Strict::String | Types::Strict::Symbol
70
+ # TODO: Write code to populate this with the resource line number
71
+ attribute :document_location , Types::Strict::Integer.optional.default(nil)
72
+ attribute :document_errors , Types::Strict::Array.of(KManager::Overview::Error).optional.default(nil)
73
+ attribute :document_valid? , Types::Strict::Bool
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KManager
4
+ module Overview
5
+ class Queries
6
+ attr_reader :manager
7
+
8
+ def initialize(manager)
9
+ @manager = manager
10
+ end
11
+
12
+ def areas
13
+ manager.areas.map(&:attribute_values)
14
+ end
15
+
16
+ def resources
17
+ manager.areas.flat_map do |area|
18
+ # TODO: Some of these properties are only available on FileResource
19
+ # This will need to be refactored when implementing Mem and Web Resource
20
+ area.resource_manager.resource_set.resources.map do |resource|
21
+ {
22
+ **area.attribute_values('area_'),
23
+ **resource.attribute_values('')
24
+ }
25
+ end
26
+ end
27
+ end
28
+
29
+ # rubocop:disable Metrics/AbcSize
30
+ def documents
31
+ manager.areas.flat_map do |area|
32
+ area.resource_manager.resource_set.resources.flat_map do |resource|
33
+ resource.documents.map do |document|
34
+ {
35
+ **area.attribute_values('area_'),
36
+ **resource.attribute_values('resource_'),
37
+ document_id: document.object_id,
38
+ document_data: document.data,
39
+ document_key: document.key,
40
+ document_namespace: document.namespace,
41
+ document_tag: document.tag,
42
+ document_type: document.type,
43
+ document_errors: document.error_hash,
44
+ document_valid: document.valid?
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ # rubocop:enable Metrics/AbcSize
51
+ end
52
+ end
53
+ end