Class: Dbwatcher::Services::Api::DiagramDataService

Inherits:
BaseApiService show all
Defined in:
lib/dbwatcher/services/api/diagram_data_service.rb

Overview

Service for handling diagram generation and data

Provides diagram data for the sessions diagrams view and API endpoints with caching, type validation, and comprehensive error handling.

Constant Summary collapse

DEFAULT_DIAGRAM_TYPE =
"database_tables"

Instance Attribute Summary collapse

Attributes inherited from BaseApiService

#params, #session

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

call

Methods included from Logging

#debug_enabled?, #log_debug, #log_error, #log_info, #log_warn

Constructor Details

#initialize(session, diagram_type = nil, params = {}) ⇒ DiagramDataService

Returns a new instance of DiagramDataService.



15
16
17
18
19
# File 'lib/dbwatcher/services/api/diagram_data_service.rb', line 15

def initialize(session, diagram_type = nil, params = {})
  super(session, params)
  @diagram_registry = Dbwatcher::Services::DiagramTypeRegistry.new
  @diagram_type = normalize_diagram_type(diagram_type)
end

Instance Attribute Details

#diagram_registryObject (readonly)

Returns the value of attribute diagram_registry.



13
14
15
# File 'lib/dbwatcher/services/api/diagram_data_service.rb', line 13

def diagram_registry
  @diagram_registry
end

#diagram_typeObject (readonly)

Returns the value of attribute diagram_type.



13
14
15
# File 'lib/dbwatcher/services/api/diagram_data_service.rb', line 13

def diagram_type
  @diagram_type
end

Class Method Details

.available_typesArray<String>

Get available diagram types

Returns:

  • (Array<String>)

    available diagram types



46
47
48
# File 'lib/dbwatcher/services/api/diagram_data_service.rb', line 46

def self.available_types
  Dbwatcher::Services::DiagramTypeRegistry.new.available_types
end

.available_types_with_metadataHash

Get available diagram types with metadata

Returns:

  • (Hash)

    available diagram types with metadata



53
54
55
# File 'lib/dbwatcher/services/api/diagram_data_service.rb', line 53

def self.
  Dbwatcher::Services::DiagramTypeRegistry.new.
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dbwatcher/services/api/diagram_data_service.rb', line 21

def call
  start_time = Time.now
  log_service_start("Generating #{diagram_type} diagram for session #{session.id}")

  validation_error = validate_session
  return validation_error if validation_error

  type_validation_error = validate_diagram_type
  return type_validation_error if type_validation_error

  begin
    result = with_cache(diagram_type, expires_in: cache_duration) do
      generate_diagram_data
    end

    log_service_completion(start_time, session_id: session.id, diagram_type: diagram_type)
    result
  rescue StandardError => e
    handle_error(e)
  end
end