Class: KManager::Overview::Queries

Inherits:
Object
  • Object
show all
Defined in:
lib/k_manager/overview/queries.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manager) ⇒ Queries

Returns a new instance of Queries.



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

def initialize(manager)
  @manager = manager
end

Instance Attribute Details

#managerObject (readonly)

Returns the value of attribute manager.



6
7
8
# File 'lib/k_manager/overview/queries.rb', line 6

def manager
  @manager
end

Instance Method Details

#areasObject



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

def areas
  manager.areas.map(&:attribute_values)
end

#documentsObject

rubocop:disable Metrics/AbcSize



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/k_manager/overview/queries.rb', line 30

def documents
  manager.areas.flat_map do |area|
    area.resource_manager.resource_set.resources.flat_map do |resource|
      resource.documents.map do |document|
        {
          **area.attribute_values('area_'),
          **resource.attribute_values('resource_'),
          document_id: document.object_id,
          document_state: document.block_state,
          document_data: document.data,
          document_key: document.key,
          document_namespace: document.namespace,
          document_tag: document.tag,
          document_type: document.type,
          document_errors: document.error_hash,
          document_valid: document.valid?
        }
      end
    end
  end
end

#resourcesObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/k_manager/overview/queries.rb', line 16

def resources
  manager.areas.flat_map do |area|
    # TODO: Some of these properties are only available on FileResource
    #       This will need to be refactored when implementing Mem and Web Resource
    area.resource_manager.resource_set.resources.map do |resource|
      {
        **area.attribute_values('area_'),
        **resource.attribute_values('')
      }
    end
  end
end