k_doc 0.0.11 → 0.0.17
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.
- checksums.yaml +4 -4
- data/lib/k_doc.rb +8 -9
- data/lib/k_doc/container.rb +21 -21
- data/lib/k_doc/fake_opinion.rb +2 -2
- data/lib/k_doc/{data.rb → model.rb} +14 -13
- data/lib/k_doc/version.rb +1 -1
- metadata +3 -4
- data/lib/k_doc/util.rb +0 -20
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f5d1fec58551c4d2c72de3c9629c0b90847352c38b2d491a021dfce0d72afac6
         | 
| 4 | 
            +
              data.tar.gz: 7f38b815def0fdcabd801daf8e9e569c36213f306f28781d8956f8bfa12b0be7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d2ec5f47f7f5dd3cf295bb430615768149724233451b0aaa09aaecca56752292b167948714ea4f146f8050488a7019a2b90ab7d824c6e540dcfc0de0831af5bb
         | 
| 7 | 
            +
              data.tar.gz: bc816e70fc04faaf6109e4abe57528b48df868b48bee93eecbc152aa782d22c44a98304eef09f8cbd9bbbbd4ec6ab7dc7ab50b16f73f98b915dae24326928c40
         | 
    
        data/lib/k_doc.rb
    CHANGED
    
    | @@ -10,11 +10,11 @@ require 'k_decor' | |
| 10 10 |  | 
| 11 11 | 
             
            require 'k_doc/version'
         | 
| 12 12 | 
             
            require 'k_doc/container'
         | 
| 13 | 
            -
            require 'k_doc/data'
         | 
| 13 | 
            +
            # require 'k_doc/data'
         | 
| 14 | 
            +
            require 'k_doc/model'
         | 
| 14 15 | 
             
            require 'k_doc/fake_opinion'
         | 
| 15 16 | 
             
            require 'k_doc/settings'
         | 
| 16 17 | 
             
            require 'k_doc/table'
         | 
| 17 | 
            -
            require 'k_doc/util'
         | 
| 18 18 |  | 
| 19 19 | 
             
            require 'k_doc/decorators/settings_decorator'
         | 
| 20 20 | 
             
            require 'k_doc/decorators/table_decorator'
         | 
| @@ -24,20 +24,19 @@ module KDoc | |
| 24 24 | 
             
              class Error < StandardError; end
         | 
| 25 25 |  | 
| 26 26 | 
             
              class << self
         | 
| 27 | 
            -
                #  | 
| 28 | 
            -
                 | 
| 29 | 
            -
             | 
| 30 | 
            -
                   | 
| 31 | 
            -
                   | 
| 27 | 
            +
                # Is this needed
         | 
| 28 | 
            +
                # Factory method to create a new model
         | 
| 29 | 
            +
                def model(key = nil, **options, &block)
         | 
| 30 | 
            +
                  model = KDoc::Model.new(key, **options, &block)
         | 
| 31 | 
            +
                  model.execute_block
         | 
| 32 | 
            +
                  model
         | 
| 32 33 | 
             
                end
         | 
| 33 34 |  | 
| 34 35 | 
             
                attr_accessor :opinion
         | 
| 35 | 
            -
                attr_accessor :util
         | 
| 36 36 | 
             
                attr_accessor :log
         | 
| 37 37 | 
             
              end
         | 
| 38 38 |  | 
| 39 39 | 
             
              KDoc.opinion = KDoc::FakeOpinion.new
         | 
| 40 | 
            -
              KDoc.util = KDoc::Util.new
         | 
| 41 40 | 
             
            end
         | 
| 42 41 |  | 
| 43 42 | 
             
            if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
         | 
    
        data/lib/k_doc/container.rb
    CHANGED
    
    | @@ -1,15 +1,30 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            module KDoc
         | 
| 4 | 
            -
              # A  | 
| 4 | 
            +
              # A data acts a base data object for any data requires tagging such as
         | 
| 5 5 | 
             
              # unique key, type and namespace.
         | 
| 6 6 | 
             
              class Container
         | 
| 7 7 | 
             
                # include KLog::Logging
         | 
| 8 8 |  | 
| 9 | 
            +
                # Name of the document (required)
         | 
| 10 | 
            +
                #
         | 
| 11 | 
            +
                # Examples: user, account, country
         | 
| 9 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
         | 
| 10 21 | 
             
                attr_reader :type
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                 | 
| 22 | 
            +
             | 
| 23 | 
            +
                attr_writer :data
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                # Move this up to k_manager
         | 
| 26 | 
            +
                # attr_reader :namespace
         | 
| 27 | 
            +
                # attr_reader :project_key
         | 
| 13 28 | 
             
                attr_reader :error
         | 
| 14 29 |  | 
| 15 30 | 
             
                # Create container for storing data/documents.
         | 
| @@ -19,35 +34,20 @@ module KDoc | |
| 19 34 | 
             
                #
         | 
| 20 35 | 
             
                # @param [Hash] **opts The options
         | 
| 21 36 | 
             
                # @option opts [String|Symbol] name Name of the container
         | 
| 22 | 
            -
                # @option opts [String|Symbol] type Type of the container, defaults to KDoc:: FakeOpinion.new. | 
| 37 | 
            +
                # @option opts [String|Symbol] type Type of the container, defaults to KDoc:: FakeOpinion.new.default_model_type if not set
         | 
| 23 38 | 
             
                # @option opts [String|Symbol] namespace Namespace that the container belongs to
         | 
| 24 39 | 
             
                # @option opts [String|Symbol] project_key Project that the container belongs to
         | 
| 25 40 | 
             
                def initialize(**opts)
         | 
| 26 | 
            -
                  @key = opts[:key] || SecureRandom.alphanumeric( | 
| 27 | 
            -
                  @type = opts[:type] ||  | 
| 28 | 
            -
                  @namespace = opts[:namespace] || ''
         | 
| 29 | 
            -
                  @project_key = opts[:project_key] || ''
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  # Old name is default_data, wonder if I still need that idea?
         | 
| 32 | 
            -
                  # Most documents live within a hash, some tabular documents such as CSV will use an []
         | 
| 33 | 
            -
                  # @data       = slice_option(:default_data) || {}
         | 
| 41 | 
            +
                  @key = opts[:key] || SecureRandom.alphanumeric(4)
         | 
| 42 | 
            +
                  @type = opts[:type] || ''
         | 
| 34 43 | 
             
                  @data = opts[:data] || {}
         | 
| 35 44 | 
             
                end
         | 
| 36 45 |  | 
| 37 | 
            -
                def unique_key
         | 
| 38 | 
            -
                  @unique_key ||= KDoc.util.build_unique_key(key, type, namespace, project_key)
         | 
| 39 | 
            -
                end
         | 
| 40 | 
            -
             | 
| 41 46 | 
             
                def debug_header
         | 
| 42 47 | 
             
                  log.kv 'key', key
         | 
| 43 48 | 
             
                  log.kv 'type', type
         | 
| 44 | 
            -
                  log.kv 'namespace', namespace
         | 
| 45 | 
            -
                  log.kv 'project_key', namespace
         | 
| 46 | 
            -
                  log.kv 'error', error
         | 
| 47 49 | 
             
                end
         | 
| 48 50 |  | 
| 49 | 
            -
                attr_writer :data
         | 
| 50 | 
            -
             | 
| 51 51 | 
             
                def data
         | 
| 52 52 | 
             
                  @data.clone
         | 
| 53 53 | 
             
                end
         | 
    
        data/lib/k_doc/fake_opinion.rb
    CHANGED
    
    | @@ -6,7 +6,7 @@ module KDoc | |
| 6 6 | 
             
              # This is called fake opinion because I have not figured out
         | 
| 7 7 | 
             
              # how I want to implement this
         | 
| 8 8 | 
             
              class FakeOpinion
         | 
| 9 | 
            -
                attr_accessor : | 
| 9 | 
            +
                attr_accessor :default_model_type
         | 
| 10 10 | 
             
                attr_accessor :default_settings_key
         | 
| 11 11 | 
             
                attr_accessor :default_table_key
         | 
| 12 12 |  | 
| @@ -15,7 +15,7 @@ module KDoc | |
| 15 15 | 
             
                attr_accessor :table_class
         | 
| 16 16 |  | 
| 17 17 | 
             
                def initialize
         | 
| 18 | 
            -
                  @ | 
| 18 | 
            +
                  @default_model_type = :entity
         | 
| 19 19 | 
             
                  @default_settings_key = :settings
         | 
| 20 20 | 
             
                  @default_table_key = :table
         | 
| 21 21 |  | 
| @@ -1,10 +1,15 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            module KDoc
         | 
| 4 | 
            -
              #  | 
| 4 | 
            +
              # Model is a DSL for modeling general purpose data objects
         | 
| 5 5 | 
             
              #
         | 
| 6 | 
            -
              #  | 
| 7 | 
            -
               | 
| 6 | 
            +
              # A mode can have
         | 
| 7 | 
            +
              #  - 0 or more named setting groups each with their key/value pairs
         | 
| 8 | 
            +
              #  - 0 or more named table groups each with their own columns and rows
         | 
| 9 | 
            +
              #
         | 
| 10 | 
            +
              # A settings group without a name will default to name: :settings
         | 
| 11 | 
            +
              # A table group without a name will default to name: :table
         | 
| 12 | 
            +
              class Model < KDoc::Container
         | 
| 8 13 | 
             
                include KLog::Logging
         | 
| 9 14 |  | 
| 10 15 | 
             
                # include KType::Error
         | 
| @@ -17,15 +22,16 @@ module KDoc | |
| 17 22 | 
             
                # Create document
         | 
| 18 23 | 
             
                #
         | 
| 19 24 | 
             
                # @param [String|Symbol] name Name of the document
         | 
| 20 | 
            -
                # @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new. | 
| 25 | 
            +
                # @param args[0] Type of the document, defaults to KDoc:: FakeOpinion.new.default_model_type if not set
         | 
| 21 26 | 
             
                # @param default: Default value (using named params), as above
         | 
| 22 27 | 
             
                def initialize(key = nil, **options, &block)
         | 
| 23 | 
            -
                  super(key: key, type: options[:type], namespace: options[:namespace], project_key: options[:project_key])
         | 
| 28 | 
            +
                  super(key: key, type: options[:type] || KDoc.opinion.default_model_type) # , namespace: options[:namespace], project_key: options[:project_key])
         | 
| 24 29 | 
             
                  initialize_attributes(**options)
         | 
| 25 30 |  | 
| 26 31 | 
             
                  @block = block if block_given?
         | 
| 27 32 | 
             
                end
         | 
| 28 33 |  | 
| 34 | 
            +
                # NOTE: Can this be moved out of the is object?
         | 
| 29 35 | 
             
                def execute_block(run_actions: nil)
         | 
| 30 36 | 
             
                  return if @block.nil?
         | 
| 31 37 |  | 
| @@ -44,7 +50,7 @@ module KDoc | |
| 44 50 | 
             
                #   raise
         | 
| 45 51 | 
             
                rescue StandardError => e
         | 
| 46 52 | 
             
                  log.error('Standard error in document')
         | 
| 47 | 
            -
                  puts "key #{unique_key}"
         | 
| 53 | 
            +
                  # puts "key #{unique_key}"
         | 
| 48 54 | 
             
                  # puts "file #{KUtil.data.console_file_hyperlink(resource.file, resource.file)}"
         | 
| 49 55 | 
             
                  log.error(e.message)
         | 
| 50 56 | 
             
                  @error = e
         | 
| @@ -54,10 +60,6 @@ module KDoc | |
| 54 60 | 
             
                  @run_actions = nil
         | 
| 55 61 | 
             
                end
         | 
| 56 62 |  | 
| 57 | 
            -
                def unique_key
         | 
| 58 | 
            -
                  @unique_key ||= KDoc.util.build_unique_key(key, type, namespace)
         | 
| 59 | 
            -
                end
         | 
| 60 | 
            -
             | 
| 61 63 | 
             
                def settings(key = nil, **options, &block)
         | 
| 62 64 | 
             
                  options ||= {}
         | 
| 63 65 |  | 
| @@ -135,19 +137,17 @@ module KDoc | |
| 135 137 | 
             
                  log.o(raw_data_struct)
         | 
| 136 138 | 
             
                end
         | 
| 137 139 |  | 
| 138 | 
            -
                # rubocop:disable Metrics/AbcSize
         | 
| 139 140 | 
             
                def debug_header
         | 
| 140 141 | 
             
                  log.heading self.class.name
         | 
| 141 142 | 
             
                  log.kv 'key', key
         | 
| 142 143 | 
             
                  log.kv 'type', type
         | 
| 143 | 
            -
                  log.kv 'namespace', namespace
         | 
| 144 | 
            +
                  # log.kv 'namespace', namespace
         | 
| 144 145 | 
             
                  log.kv 'error', error
         | 
| 145 146 |  | 
| 146 147 | 
             
                  debug_header_keys
         | 
| 147 148 |  | 
| 148 149 | 
             
                  log.line
         | 
| 149 150 | 
             
                end
         | 
| 150 | 
            -
                # rubocop:enable Metrics/AbcSize
         | 
| 151 151 |  | 
| 152 152 | 
             
                def debug_header_keys
         | 
| 153 153 | 
             
                  options&.keys&.reject { |k| k == :namespace }&.each do |key|
         | 
| @@ -159,6 +159,7 @@ module KDoc | |
| 159 159 |  | 
| 160 160 | 
             
                def initialize_attributes(**options)
         | 
| 161 161 | 
             
                  @options    = options || {}
         | 
| 162 | 
            +
                  # Is parent a part of model, or is it part of k_manager::document_taggable
         | 
| 162 163 | 
             
                  @parent     = slice_option(:parent)
         | 
| 163 164 |  | 
| 164 165 | 
             
                  # Most documents live within a hash, some tabular documents such as CSV will use an []
         | 
    
        data/lib/k_doc/version.rb
    CHANGED
    
    
    
        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. | 
| 4 | 
            +
              version: 0.0.17
         | 
| 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- | 
| 11 | 
            +
            date: 2021-04-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -111,13 +111,12 @@ files: | |
| 111 111 | 
             
            - k_doc.gemspec
         | 
| 112 112 | 
             
            - lib/k_doc.rb
         | 
| 113 113 | 
             
            - lib/k_doc/container.rb
         | 
| 114 | 
            -
            - lib/k_doc/data.rb
         | 
| 115 114 | 
             
            - lib/k_doc/decorators/settings_decorator.rb
         | 
| 116 115 | 
             
            - lib/k_doc/decorators/table_decorator.rb
         | 
| 117 116 | 
             
            - lib/k_doc/fake_opinion.rb
         | 
| 117 | 
            +
            - lib/k_doc/model.rb
         | 
| 118 118 | 
             
            - lib/k_doc/settings.rb
         | 
| 119 119 | 
             
            - lib/k_doc/table.rb
         | 
| 120 | 
            -
            - lib/k_doc/util.rb
         | 
| 121 120 | 
             
            - lib/k_doc/version.rb
         | 
| 122 121 | 
             
            homepage: http://appydave.com/gems/k-doc
         | 
| 123 122 | 
             
            licenses:
         | 
    
        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_document_type
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                  keys = [project_key, namespace, key, type].reject { |k| k.nil? || k == '' }
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  keys.join('_')
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
              end
         | 
| 20 | 
            -
            end
         |