Class: ActivePgLog::ActiveTrigger

Inherits:
Object
  • Object
show all
Defined in:
lib/active_pg_log/active_trigger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ ActiveTrigger

Returns a new instance of ActiveTrigger.



4
5
6
# File 'lib/active_pg_log/active_trigger.rb', line 4

def initialize(connection)
  @dados = connection.select_all(query)
end

Instance Attribute Details

#dadosObject

Returns the value of attribute dados.



2
3
4
# File 'lib/active_pg_log/active_trigger.rb', line 2

def dados
  @dados
end

Instance Method Details

#include?(trigger_name, table_name) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/active_pg_log/active_trigger.rb', line 8

def include?(trigger_name, table_name)
  return false if !defined?(@dados.rows) || @dados.rows.size.zero?

  @dados.select { |e| e['table_name'] == table_name && e['trigger_name'] == trigger_name }.size.positive?
end

#queryObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_pg_log/active_trigger.rb', line 14

def query
  %(select event_object_schema as table_schema,
          event_object_table as table_name,
          trigger_schema,
          trigger_name,
          string_agg(event_manipulation, ',') as event,
          action_timing as activation,
          action_condition as condition,
          action_statement as definition
            from information_schema.triggers
            group by 1,2,3,4,6,7,8
            order by table_schema,
                    table_name;
      )
end