Module: KDoc::Taggable

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

Overview

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.



9
10
11
# File 'lib/k_doc/mixins/taggable.rb', line 9

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



20
21
22
23
# File 'lib/k_doc/mixins/taggable.rb', line 20

def initialize_tag(opts)
  @tag_options = opts
  build_tag
end

#keyObject

Name of the document (required)

Examples: user, account, country



32
33
34
# File 'lib/k_doc/mixins/taggable.rb', line 32

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]


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

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


52
53
54
# File 'lib/k_doc/mixins/taggable.rb', line 52

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

#tagObject



25
26
27
# File 'lib/k_doc/mixins/taggable.rb', line 25

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


43
44
45
# File 'lib/k_doc/mixins/taggable.rb', line 43

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