Class: PgInsights::InsightQueryService

Inherits:
Object
  • Object
show all
Defined in:
app/services/pg_insights/insight_query_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



3
4
5
# File 'app/services/pg_insights/insight_query_service.rb', line 3

def self.all
  @all_queries ||= new.load_queries
end

.find(id) ⇒ Object



7
8
9
# File 'app/services/pg_insights/insight_query_service.rb', line 7

def self.find(id)
  all.find { |q| q[:id] == id }
end

Instance Method Details

#load_queriesObject



11
12
13
14
15
16
17
18
19
# File 'app/services/pg_insights/insight_query_service.rb', line 11

def load_queries
  file_path = PgInsights::Engine.root.join("config", "default_queries.yml")
  return [] unless File.exist?(file_path)

  YAML.safe_load(File.read(file_path), symbolize_names: true)
rescue Psych::SyntaxError => e
  Rails.logger.error "[PgInsights] Failed to load default_queries.yml: #{e.message}"
  []
end