module KManager::Documents::DocumentTaggable
Tag a document with attributes that can be used to uniquely identify a document within a project or namespace
Examples:
User DSL could be tagged user_entity Blue print DSL for building a data layer User could be tagged user_blueprint Users.csv file could be tagged data_files_users_csv Account DSL in the CRM project could be tagged crm_account_entity AccountController DSL in the CRM project could be tagged crm_controllers_account_controller
Attributes
Errors in documents can be stored against the document
This helps debugging invalid DSL's and data documents
Name of the document (required)
Examples: user, account, country
Namespace of the document (optional, '' if not set)
When using a data file, this should be based on the relative file path When using a DSL data file, this will be manually configured
Project
that this document belongs to (optional)
Project
key is inferred from the attached project ('' if project not set)
Resource that this document belongs to (optional)
Type of document (optional, but will set to :default_document_type if not provided)
Examples by data type
:csv, :yaml, :json, :xml
Examples by shape of the data in a DSL
:entity, :microapp, blueprint
Public Instance Methods
rubocop:disable Metrics/AbcSize
# File lib/k_manager/documents/document_taggable.rb, line 78 def debug log.section_heading(self.class.name) log.kv 'unique_key' , unique_key , 15 log.kv 'key' , key , 15 log.kv 'type' , type , 15 log.kv 'namespace' , namespace , 15 # log.kv 'resource' , resource , 15 # log.kv 'project' , project , 15 log.kv 'project_key' , project_key , 15 log.kv 'data' , data.nil? ? '' : data.to_s[0..100].gsub("\n", '\n'), 15 log.kv 'error' , error , 15 end
The unique key on resources provides a way to prevent conflicts between resource names, resource types, local namespaces and projects.
# File lib/k_manager/documents/document_taggable.rb, line 64 def unique_key return @unique_key if defined? @unique_key @unique_key = begin raise KDoc::Error, 'key is required when generating unique key' if key.nil? || key.empty? [project_key, namespace, key, type] .reject { |k| k.nil? || k == '' } .map { |k| k.to_s.gsub('_', '-') } .join('-') end end