Class: KManager::Area

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
KLog::Logging
Defined in:
lib/k_manager/area.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Area

Returns a new instance of Area.



14
15
16
17
18
19
20
21
22
# File 'lib/k_manager/area.rb', line 14

def initialize(**opts)
  @manager    = opts[:manager]
  @name       = opts[:name]

  raise 'Area name is required' unless @name

  @namespace  = opts[:namespace] || @name
  @config     = KConfig.configuration(@name)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/k_manager/area.rb', line 12

def config
  @config
end

#managerObject (readonly)

Returns the value of attribute manager.



8
9
10
# File 'lib/k_manager/area.rb', line 8

def manager
  @manager
end

#nameObject (readonly)

TODO: I have not got a use for area name yet, it may be able to drive default config, but not sure.



10
11
12
# File 'lib/k_manager/area.rb', line 10

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



11
12
13
# File 'lib/k_manager/area.rb', line 11

def namespace
  @namespace
end

Instance Method Details

#attribute_values(prefix = nil) ⇒ Object

rubocop:disable Metrics/AbcSize



39
40
41
42
43
44
45
46
# File 'lib/k_manager/area.rb', line 39

def attribute_values(prefix = nil)
  result = {}
  result["#{prefix}name".to_sym]                  = name
  result["#{prefix}namespace".to_sym]             = namespace
  result["#{prefix}resource_count".to_sym]        = resource_manager.resources.length
  result["#{prefix}document_count".to_sym]        = resource_manager.resources.sum { |resource| resource.documents.length }
  result
end

#debug(*sections) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/k_manager/area.rb', line 30

def debug(*sections)
  log.kv 'Area'           , name
  log.kv 'Namespace'      , namespace

  resource_manager.debug if sections.include?(:resource) || sections.include?(:resources)
  config.debug if sections.include?(:config)
end

#resource_managerObject



24
25
26
# File 'lib/k_manager/area.rb', line 24

def resource_manager
  @resource_manager ||= KManager::Resources::ResourceManager.new(self)
end