Module: KDoc::Taggable

Includes:
KLog::Logging
Included in:
Container
Defined in:
lib/k_doc/mixins/taggable.rb

Overview

Provide tagging functionality to the underlying model

A container acts a base data object for any data that requires tagging such as unique key, type and namespace.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tag_optionsObject (readonly)

Returns the value of attribute tag_options.



11
12
13
# File 'lib/k_doc/mixins/taggable.rb', line 11

def tag_options
  @tag_options
end

Instance Method Details

#initialize_tag(opts) ⇒ Object

Tags are provided via an options hash, these tags are remove from the hash as they are read

Any container can be uniquely identified via it’s key, type, namespace and project_key tags

Parameters:

  • opts (Hash)

    The options

Options Hash (opts):

  • project (String|Symbol)

    Project Name

  • namespace (String|Symbol|Array)

    Namespace or array if namespace is deep nested

  • name (String|Symbol)

    Container Name

  • type (String|Symbol)

    Type of the container, uses default_container_type if not set



22
23
24
25
# File 'lib/k_doc/mixins/taggable.rb', line 22

def initialize_tag(opts)
  @tag_options = opts
  build_tag
end

#keyObject

Name of the document (required)

Examples: user, account, country



34
35
36
# File 'lib/k_doc/mixins/taggable.rb', line 34

def key
  @key ||= @tag_options.delete(:key) || SecureRandom.alphanumeric(4)
end

#namespaceObject

Namespace(s) what namespace is this document under

Example for single path

:controllers, :models

Example for deep path

[:app, :controllers, :admin]


65
66
67
68
69
70
# File 'lib/k_doc/mixins/taggable.rb', line 65

def namespace
  return @namespace if defined? @namespace

  ns = @tag_options.delete(:namespace) || []
  @namespace = ns.is_a?(Array) ? ns : [ns]
end

#projectObject

TODO: rename to area (or area root namespace) Project name

Examples

:app_name1, :app_name2, :library_name1


54
55
56
# File 'lib/k_doc/mixins/taggable.rb', line 54

def project
  @project ||= @tag_options.delete(:project) || ''
end

#tagObject



27
28
29
# File 'lib/k_doc/mixins/taggable.rb', line 27

def tag
  return @tag if defined? @tag
end

#typeObject

Type of data

Examples by data type

:csv, :yaml, :json, :xml

Examples by shape of the data in a DSL

:entity, :microapp, blueprint


45
46
47
# File 'lib/k_doc/mixins/taggable.rb', line 45

def type
  @type ||= @tag_options.delete(:type) || default_container_type
end