k_manager 0.0.13 → 0.0.28

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/Gemfile +23 -0
  4. data/Rakefile +2 -0
  5. data/docs/flow.drawio +16 -0
  6. data/exe/k_manager +19 -0
  7. data/hooks/update-version +1 -1
  8. data/k_manager.gemspec +9 -0
  9. data/lib/k_manager/area.rb +49 -0
  10. data/lib/k_manager/cli/base_command.rb +23 -0
  11. data/lib/k_manager/cli/commands.rb +25 -0
  12. data/lib/k_manager/cli/info.rb +81 -0
  13. data/lib/k_manager/cli/new.rb +130 -0
  14. data/lib/k_manager/cli/version.rb +15 -0
  15. data/lib/k_manager/cli/watch.rb +65 -0
  16. data/lib/k_manager/document_factory.rb +81 -0
  17. data/lib/k_manager/manager.rb +158 -0
  18. data/lib/k_manager/overview/dashboard.rb +197 -0
  19. data/lib/k_manager/overview/dump_json.rb +35 -0
  20. data/lib/k_manager/overview/models.rb +76 -0
  21. data/lib/k_manager/overview/queries.rb +53 -0
  22. data/lib/k_manager/resources/base_resource.rb +203 -52
  23. data/lib/k_manager/resources/file_resource.rb +81 -58
  24. data/lib/k_manager/resources/{ruby_file_resource.rb → file_resources/ruby_file_resource.rb} +0 -0
  25. data/lib/k_manager/resources/{unknown_file_resource.rb → file_resources/unknown_file_resource.rb} +0 -0
  26. data/lib/k_manager/resources/mem_resource.rb +17 -0
  27. data/lib/k_manager/resources/resource_document_factory.rb +123 -0
  28. data/lib/k_manager/resources/resource_factory.rb +28 -0
  29. data/lib/k_manager/resources/resource_manager.rb +201 -0
  30. data/lib/k_manager/resources/resource_set.rb +90 -0
  31. data/lib/k_manager/resources/web_resource.rb +113 -0
  32. data/lib/k_manager/version.rb +1 -1
  33. data/lib/k_manager/watcher.rb +113 -0
  34. data/lib/k_manager/{x_project.rb → x_resource_documents/x_project.rb} +0 -0
  35. data/lib/k_manager/{x_project_manager.rb → x_resource_documents/x_project_manager.rb} +0 -0
  36. data/lib/k_manager/{x_register.rb → x_resource_documents/x_register.rb} +0 -0
  37. data/lib/k_manager.rb +111 -24
  38. data/tasks/watch.rake +18 -0
  39. metadata +118 -25
  40. data/Assessment1.md +0 -127
  41. data/Assessment2.md +0 -88
  42. data/lib/k_manager/configuration/project_config.rb +0 -14
  43. data/lib/k_manager/create_document.rb +0 -31
  44. data/lib/k_manager/documents/basic_document.rb +0 -21
  45. data/lib/k_manager/documents/builder_document.rb +0 -18
  46. data/lib/k_manager/documents/document_taggable.rb +0 -94
  47. data/lib/k_manager/documents/model_document.rb +0 -19
  48. data/lib/k_manager/project.rb +0 -50
  49. data/lib/k_manager/resources/csv_file_resource.rb +0 -27
  50. data/lib/k_manager/resources/factories/document_factory.rb +0 -52
  51. data/lib/k_manager/resources/json_file_resource.rb +0 -22
  52. data/lib/k_manager/resources/yaml_file_resource.rb +0 -21
data/tasks/watch.rake ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry'
4
+ require 'k_manager'
5
+ # require 'filewatcher'
6
+ # require 'io/console'
7
+
8
+ namespace :k_manager do
9
+ desc 'Watch '
10
+ task :watch do
11
+ target_folder = 'spec/k_manager/scenarios'
12
+ watch_folder = File.join(Dir.pwd, target_folder)
13
+ boot_file = File.join(watch_folder, 'simple/boot.rb')
14
+
15
+ watcher = Watcher.new(watch_folder, boot_file)
16
+ watcher.start
17
+ end
18
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.28
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-27 00:00:00.000000000 Z
11
+ date: 2022-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-struct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: filewatcher
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0.beta5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0.beta5
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: k_builder
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +52,20 @@ dependencies:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: 0.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: k_director
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: k_doc
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +80,20 @@ dependencies:
38
80
  - - "~>"
39
81
  - !ruby/object:Gem::Version
40
82
  version: 0.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: k_domain
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.0.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.0.0
41
97
  - !ruby/object:Gem::Dependency
42
98
  name: k_ext-github
43
99
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +108,20 @@ dependencies:
52
108
  - - "~>"
53
109
  - !ruby/object:Gem::Version
54
110
  version: 0.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: k_fileset
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.0.0
55
125
  - !ruby/object:Gem::Dependency
56
126
  name: k_log
57
127
  requirement: !ruby/object:Gem::Requirement
@@ -66,11 +136,26 @@ dependencies:
66
136
  - - "~>"
67
137
  - !ruby/object:Gem::Version
68
138
  version: 0.0.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: dry-cli
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.7.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.7.0
69
153
  description: " K Manager provides a managed host for documents, resources and code
70
154
  generator execution\n"
71
155
  email:
72
156
  - david@ideasmen.com.au
73
- executables: []
157
+ executables:
158
+ - k_manager
74
159
  extensions: []
75
160
  extra_rdoc_files: []
76
161
  files:
@@ -78,8 +163,6 @@ files:
78
163
  - ".gitignore"
79
164
  - ".rspec"
80
165
  - ".rubocop.yml"
81
- - Assessment1.md
82
- - Assessment2.md
83
166
  - CODE_OF_CONDUCT.md
84
167
  - Gemfile
85
168
  - Guardfile
@@ -94,39 +177,49 @@ files:
94
177
  - bin/kgitsync
95
178
  - bin/khotfix
96
179
  - bin/setup
180
+ - docs/flow.drawio
181
+ - exe/k_manager
97
182
  - hooks/pre-commit
98
183
  - hooks/update-version
99
184
  - k_manager.gemspec
100
185
  - lib/k_manager.rb
101
- - lib/k_manager/configuration/project_config.rb
102
- - lib/k_manager/create_document.rb
103
- - lib/k_manager/documents/basic_document.rb
104
- - lib/k_manager/documents/builder_document.rb
105
- - lib/k_manager/documents/document_taggable.rb
106
- - lib/k_manager/documents/model_document.rb
107
- - lib/k_manager/project.rb
186
+ - lib/k_manager/area.rb
187
+ - lib/k_manager/cli/base_command.rb
188
+ - lib/k_manager/cli/commands.rb
189
+ - lib/k_manager/cli/info.rb
190
+ - lib/k_manager/cli/new.rb
191
+ - lib/k_manager/cli/version.rb
192
+ - lib/k_manager/cli/watch.rb
193
+ - lib/k_manager/document_factory.rb
194
+ - lib/k_manager/manager.rb
195
+ - lib/k_manager/overview/dashboard.rb
196
+ - lib/k_manager/overview/dump_json.rb
197
+ - lib/k_manager/overview/models.rb
198
+ - lib/k_manager/overview/queries.rb
108
199
  - lib/k_manager/resources/base_resource.rb
109
- - lib/k_manager/resources/csv_file_resource.rb
110
- - lib/k_manager/resources/factories/document_factory.rb
111
200
  - lib/k_manager/resources/factories/ruby_document_factory.rb
112
201
  - lib/k_manager/resources/file_resource.rb
113
- - lib/k_manager/resources/json_file_resource.rb
114
- - lib/k_manager/resources/ruby_file_resource.rb
115
- - lib/k_manager/resources/unknown_file_resource.rb
202
+ - lib/k_manager/resources/file_resources/ruby_file_resource.rb
203
+ - lib/k_manager/resources/file_resources/unknown_file_resource.rb
204
+ - lib/k_manager/resources/mem_resource.rb
205
+ - lib/k_manager/resources/resource_document_factory.rb
206
+ - lib/k_manager/resources/resource_factory.rb
207
+ - lib/k_manager/resources/resource_manager.rb
208
+ - lib/k_manager/resources/resource_set.rb
209
+ - lib/k_manager/resources/web_resource.rb
116
210
  - lib/k_manager/resources/x_resource.rb
117
- - lib/k_manager/resources/yaml_file_resource.rb
118
211
  - lib/k_manager/version.rb
119
- - lib/k_manager/x_project.rb
120
- - lib/k_manager/x_project_manager.rb
121
- - lib/k_manager/x_register.rb
212
+ - lib/k_manager/watcher.rb
122
213
  - lib/k_manager/x_resource_documents/resource_document.rb
214
+ - lib/k_manager/x_resource_documents/x_project.rb
215
+ - lib/k_manager/x_resource_documents/x_project_manager.rb
216
+ - lib/k_manager/x_resource_documents/x_register.rb
217
+ - tasks/watch.rake
123
218
  homepage: http://appydave.com/gems/k-manager
124
219
  licenses:
125
220
  - MIT
126
221
  metadata:
127
- homepage_uri: http://appydave.com/gems/k-manager
128
- source_code_uri: https://github.com/klueless-io/k_manager
129
- changelog_uri: https://github.com/klueless-io/k_manager/commits/master
222
+ rubygems_mfa_required: 'true'
130
223
  post_install_message:
131
224
  rdoc_options: []
132
225
  require_paths:
@@ -142,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
235
  - !ruby/object:Gem::Version
143
236
  version: '0'
144
237
  requirements: []
145
- rubygems_version: 3.2.7
238
+ rubygems_version: 3.2.33
146
239
  signing_key:
147
240
  specification_version: 4
148
241
  summary: K Manager provides a managed host for documents, resources and code generator
data/Assessment1.md DELETED
@@ -1,127 +0,0 @@
1
- 1. Business modelling tools and Technical modelling tools
2
-
3
- Technical modelling tools 
4
- ERD
5
-  
6
- - Entity Relationship Diagram used for Databases
7
-
8
- Tools: Gliffy, Lucid Charts,   
9
-
10
- 2. Software development methodologies 
11
- - Agile/ 
12
- - Waterflow 
13
- - RAD 
14
- - Extreme XP 
15
- - Feature Driven 
16
- - Scrum
17
-
18
- 3. Application architecture diagram
19
- - N-Tier (Layered) vs - Microservices
20
- - Application Architecture Diagram
21
- - Integration Architecture Diagram
22
- - Deployment Architecture Diagram
23
- - DevOps Architecture Diagram
24
- - Data Architecture Diagram
25
-
26
- 4. Software risk analysis
27
- - Estimates, Scope Creep, Stake holder expectations, Low Stake holder engagement, 
28
- - Requirements / Use Cases
29
- -  Abuse or security analysis 
30
- - Unproven Technology 
31
- - Choice of Infrustruction
32
-  
33
- - Cloud, Server/On-Premise/Integrations
34
- - UX Design
35
-  
36
- - Framwork, Accesibility
37
- - Risk analysis
38
-  
39
- - Code Quality
40
-  
41
- - Anti Patterns,
42
-  
43
- - Poor Architecture
44
- - Test Design
45
-  
46
- - Data edge cases
47
- - Static Analysis tools
48
-  
49
- - Linters
50
- - Pen Testing
51
-  
52
- 5. Database diagram processes and steps
53
- - ERD
54
- - Conceptual model  
55
- - Purpose of database     
56
-    - Monolith vs Microservice     
57
- - Relational, Object/JSON/NoSql Store, Key/Value Store, Event Sourced
58
- 6. Design database process and steps 
59
- - Normalized tables     
60
- - Entities     
61
- - Attributes 
62
- - Relationships, (1-1, 1-m, m-m)     
63
-  - Define cardinality, maximum number of values
64
-  - Define ordinality, minimum number of values     
65
-  - Lhs can be zero or one or many     
66
-  - Rhs can be zero, one or many      
67
-  - Referential integrity, constraints, indexes
68
- 7. Implement database database processes and steps 
69
- - DDL 
70
- - create database 
71
- - create table     
72
- - primary key     
73
- - attributes 
74
- - create index and constraints 
75
- - create foreign key references 
76
- - create views   
77
- 8. Principles of database-management systems. 
78
-
79
- - Shared collection of related data 
80
- - Data Modeling 
81
- - Data Storage   
82
- - Structured Data   
83
- - Unstructured Data 
84
- - Transactions (Local or Distributed) 
85
- - Referential Integrity 
86
- - Cardinatlity/Ordinality 
87
- - Distributed Data 
88
- - Data Warehouses / Big Data 
89
- - Relational, Object/JSON Store, Key/Value Stores, Event Sourced
90
-
91
- 9. Object-oriented programming concepts 
92
- - Encapsulation, Inheritance, Abstraction, Polymorphism
93
-
94
- 10. Characteristics of a programming language (C#) 
95
- - Object Oriented 
96
- - Memory Management 
97
- - Garbage Collection 
98
- - Type Safe 
99
- - Compiled to Byte Code 
100
- - Cross Platform  
101
- 11. Open-source development tools and platforms 
102
- - Git Hub 
103
- - VSCode 
104
- - Bootstrap, Material, Tailwind CSS 
105
- - Angular, React, Vue   
106
- 12. Input and output requirements & examples 
107
- - Input   
108
- - Console, Terminal, Browser, Ports, Devices -
109
- Output   - Console, Screen, Printer, Devices (3D Printer, Robot), Ports (Database, Message Queue)
110
- 13. Testing techniques 
111
- - Unit Testing 
112
- - Integration Test 
113
- - Regression Testing 
114
- - Penn Testing 
115
- - User Acceptance Testing  
116
- 14. Computer hardware & why it is important in soft dev
117
-  
118
- - PC, Mac, Embedded Device, IOT, Mobile (Android, IOS, Tablets) 
119
- - Operating systems, Kernals, VM's and Dockerization 
120
- - Provides both a physical devices  and virtual environments on which to run applications  
121
- 15. Computer networking components & why it is important in soft dev 
122
- - Allows for distributed computing 
123
- - Scalable databases 
124
- - Scalable services 
125
- - Provides redundancy and resilience. 
126
- - Provides external backup stores
127
-
data/Assessment2.md DELETED
@@ -1,88 +0,0 @@
1
- # Assessment
2
-
3
- Validate Software
4
-
5
- ICPTPRG520 Validate an application design against specifications
6
-
7
- ## PART 1
8
-
9
- 1. Develop a proof of concept
10
- 2. Present the prototype system
11
- 3. Perform design and code validation
12
- 4. Document and report validation results
13
-
14
- A. Determine the procedures and tools required to perform
15
-
16
- * Software requirements validation
17
- * Database validation
18
- * Software design validation
19
- * Source code validation
20
- * User Interface (UI) validation
21
- * Test validation
22
-
23
- B. Now it is time to design and build a prototype.
24
- 1. Identify a prototyping tool to develop proof of concept
25
- 2. Identify the use cases from the software requirements.
26
- 3. Develop a prototype using the selected tool.
27
-
28
- C. Save your word-processed document as VDP_Part1
29
-
30
- ## PART 2
31
-
32
- 10-15 minutes to present your prototype
33
-
34
- Role Play Participants:
35
- Client and Developer.
36
-
37
- 1. Identify each use case requirements that you need to fulfil
38
- 2. Confirm the completeness and correctness of the requirements using appropriate questioning and listening techniques.
39
- 3. Demonstrate the prototype (from Part 1) to the client and determine whether any further refinements need to be made.
40
- 4. Record the outcome of the presentation and any changes required in a document.
41
-
42
- ## PART 3
43
-
44
- Now you have implement selected use cases, its time for you to validate it.
45
-
46
- Record your validation details
47
- - Date
48
- - Name
49
- - Procedures
50
- - Results (including screen shots)
51
-
52
- 1. Validate the software design to ensure the design is complete, accurate and feasible.
53
- 1. Include diagrams, class, erd, activity, seq, flow etc...
54
- 2. Validate the database structure and elements, inluding screenshots
55
- 3. Validate the UI design
56
- 4. Validate the software code for consistency and analysis of the code using 2 static analysis tools (c# and web). Include screen shots
57
-
58
- ## PART 4
59
-
60
- Document and report validation results
61
- See: Original document for this.
62
-
63
- ### Application Requirements
64
-
65
- Sydney club needs a simple membership system.
66
-
67
- System should allow club employees to enter member details.
68
-
69
- Future: Guests can sign-up and manage their membership online via the clubs website and via mobile app.
70
-
71
- ## Database
72
-
73
- ### Users
74
-
75
- The users table will hold a list of employees who can add new members to the system.
76
-
77
- * email - Valid email that acts as a unique user name
78
- * password - hashed value that holds the users password
79
-
80
- ### Members
81
-
82
- Members table will store member details
83
-
84
- * First name
85
- * Last name
86
- * Phone number
87
- * Date of Birth
88
-
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KManager
4
- module Configuration
5
- # Project configuration class for KManager
6
- #
7
- # This configuration contains template and target folders as used
8
- # by all k_builders, it also has additional configuration that makes
9
- # sense for a project, such as the GitHub repository configuration
10
- class ProjectConfig < KBuilder::Configuration
11
- attach_to(KExt::Github::Configuration, self, :github)
12
- end
13
- end
14
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KManager
4
- module CreateDocument
5
- def model(key = nil, **opts)
6
- opts = { key: key }.merge(opts) unless key.nil?
7
- document = new_document(KManager::Documents::ModelDocument, **opts)
8
-
9
- attach_to_resource(document, change_resource_type: :dsl)
10
- end
11
-
12
- def attach_to_resource(document, change_resource_type: :dsl)
13
- KManager.target_resource&.attach_document(document, change_resource_type: :dsl)
14
- document
15
- end
16
-
17
- # Create an instance of a document
18
- #
19
- # @param [Class<DocumentTaggable>] klass type of document to create
20
- def new_document(klass, **opts)
21
- key = KManager.target_resource.documents.length.zero? ? KManager.target_resource.infer_key : nil
22
-
23
- opts = {
24
- resource: KManager.target_resource,
25
- key: key
26
- }.merge(opts)
27
-
28
- klass.new(**opts)
29
- end
30
- end
31
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KManager
4
- module Documents
5
- # A basic document stores a simple data object with tags for
6
- # unique key, type, namespace and project.
7
- class BasicDocument < KDoc::Container
8
- include KLog::Logging
9
- include KManager::Documents::DocumentTaggable
10
-
11
- def initialize(**opts)
12
- super(**opts)
13
- initialize_document_tags(**opts)
14
- end
15
-
16
- def default_document_type
17
- :basic
18
- end
19
- end
20
- end
21
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KManager
4
- module Documents
5
- class BuilderDocument
6
- include KLog::Logging
7
- include KManager::Documents::DocumentTaggable
8
-
9
- def initialize(**opts)
10
- initialize_document_tags(**opts)
11
- end
12
-
13
- # def default_document_type
14
- # nil
15
- # end
16
- end
17
- end
18
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KManager
4
- module Documents
5
- # Tag a document with attributes that can be used to uniquely identify
6
- # a document within a project or namespace
7
- #
8
- # Examples:
9
- # User DSL could be tagged user_entity
10
- # Blue print DSL for building a data layer User could be tagged user_blueprint
11
- # Users.csv file could be tagged data_files_users_csv
12
- # Account DSL in the CRM project could be tagged crm_account_entity
13
- # AccountController DSL in the CRM project could be tagged crm_controllers_account_controller
14
- module DocumentTaggable
15
- # Name of the document (required)
16
- #
17
- # Examples: user, account, country
18
- attr_reader :key
19
-
20
- # Type of document (optional, but will set to :default_document_type if not provided)
21
- #
22
- # Examples by data type
23
- # :csv, :yaml, :json, :xml
24
- #
25
- # Examples by shape of the data in a DSL
26
- # :entity, :microapp, blueprint
27
- attr_reader :type
28
-
29
- # Namespace of the document (optional, '' if not set)
30
- #
31
- # When using a data file, this should be based on the relative file path
32
- # When using a DSL data file, this will be manually configured
33
- attr_reader :namespace
34
-
35
- # Resource that this document belongs to (optional)
36
- attr_accessor :resource
37
-
38
- # Project that this document belongs to (optional)
39
- attr_reader :project
40
-
41
- # Project key is inferred from the attached project ('' if project not set)
42
- attr_reader :project_key
43
-
44
- # Errors in documents can be stored against the document
45
- #
46
- # This helps debugging invalid DSL's and data documents
47
- attr_reader :error
48
-
49
- def initialize_document_tags(**opts)
50
- @key = opts[:key] || SecureRandom.alphanumeric(4)
51
- @type = opts[:type] || default_document_type
52
- @namespace = opts[:namespace] || ''
53
- @resource = opts[:resource]
54
- @project = @resource&.project
55
- @project_key = project&.infer_key
56
- end
57
-
58
- # This method should be implemented on the document class
59
- # generally it will return a :symbol
60
- # def default_document_type; end;
61
-
62
- # The unique key on resources provides a way to prevent conflicts
63
- # between resource names, resource types, local namespaces and projects.
64
- def unique_key
65
- return @unique_key if defined? @unique_key
66
-
67
- @unique_key = begin
68
- raise KDoc::Error, 'key is required when generating unique key' if key.nil? || key.empty?
69
-
70
- [project_key, namespace, key, type]
71
- .reject { |k| k.nil? || k == '' }
72
- .map { |k| k.to_s.gsub('_', '-') }
73
- .join('-')
74
- end
75
- end
76
-
77
- # rubocop:disable Metrics/AbcSize
78
- def debug
79
- log.section_heading(self.class.name)
80
-
81
- log.kv 'unique_key' , unique_key , 15
82
- log.kv 'key' , key , 15
83
- log.kv 'type' , type , 15
84
- log.kv 'namespace' , namespace , 15
85
- # log.kv 'resource' , resource , 15
86
- # log.kv 'project' , project , 15
87
- log.kv 'project_key' , project_key , 15
88
- log.kv 'data' , data.nil? ? '' : data.to_s[0..100].gsub("\n", '\n'), 15
89
- log.kv 'error' , error , 15
90
- end
91
- # rubocop:enable Metrics/AbcSize
92
- end
93
- end
94
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KManager
4
- module Documents
5
- class ModelDocument < KDoc::Model
6
- include KLog::Logging
7
- include KManager::Documents::DocumentTaggable
8
-
9
- def initialize(**opts)
10
- super(**opts)
11
- initialize_document_tags(**opts)
12
- end
13
-
14
- def default_document_type
15
- KDoc.opinion.default_model_type
16
- end
17
- end
18
- end
19
- end