fx-jets 0.6.3s

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.hound.yml +2 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +648 -0
  6. data/.travis.yml +60 -0
  7. data/.yardopts +4 -0
  8. data/Appraisals +45 -0
  9. data/CONTRIBUTING.md +15 -0
  10. data/Gemfile +4 -0
  11. data/LICENSE +18 -0
  12. data/README.md +1 -0
  13. data/Rakefile +23 -0
  14. data/bin/appraisal +17 -0
  15. data/bin/console +14 -0
  16. data/bin/rake +17 -0
  17. data/bin/rspec +17 -0
  18. data/bin/setup +13 -0
  19. data/bin/yard +17 -0
  20. data/fx.gemspec +39 -0
  21. data/gemfiles/rails42.gemfile +10 -0
  22. data/gemfiles/rails50.gemfile +8 -0
  23. data/gemfiles/rails51.gemfile +8 -0
  24. data/gemfiles/rails52.gemfile +8 -0
  25. data/gemfiles/rails60.gemfile +8 -0
  26. data/gemfiles/rails61.gemfile +8 -0
  27. data/gemfiles/rails_edge.gemfile +8 -0
  28. data/lib/fx/adapters/postgres/connection.rb +16 -0
  29. data/lib/fx/adapters/postgres/functions.rb +59 -0
  30. data/lib/fx/adapters/postgres/triggers.rb +57 -0
  31. data/lib/fx/adapters/postgres.rb +167 -0
  32. data/lib/fx/command_recorder/arguments.rb +43 -0
  33. data/lib/fx/command_recorder/function.rb +30 -0
  34. data/lib/fx/command_recorder/trigger.rb +30 -0
  35. data/lib/fx/command_recorder.rb +24 -0
  36. data/lib/fx/configuration.rb +48 -0
  37. data/lib/fx/definition.rb +46 -0
  38. data/lib/fx/function.rb +26 -0
  39. data/lib/fx/railtie.rb +15 -0
  40. data/lib/fx/schema_dumper/function.rb +38 -0
  41. data/lib/fx/schema_dumper/trigger.rb +29 -0
  42. data/lib/fx/schema_dumper.rb +10 -0
  43. data/lib/fx/statements/function.rb +115 -0
  44. data/lib/fx/statements/trigger.rb +146 -0
  45. data/lib/fx/statements.rb +11 -0
  46. data/lib/fx/trigger.rb +26 -0
  47. data/lib/fx/version.rb +4 -0
  48. data/lib/fx.rb +43 -0
  49. data/lib/generators/fx/function/USAGE +11 -0
  50. data/lib/generators/fx/function/function_generator.rb +120 -0
  51. data/lib/generators/fx/function/templates/db/migrate/create_function.erb +5 -0
  52. data/lib/generators/fx/function/templates/db/migrate/update_function.erb +5 -0
  53. data/lib/generators/fx/trigger/USAGE +20 -0
  54. data/lib/generators/fx/trigger/templates/db/migrate/create_trigger.erb +5 -0
  55. data/lib/generators/fx/trigger/templates/db/migrate/update_trigger.erb +5 -0
  56. data/lib/generators/fx/trigger/trigger_generator.rb +130 -0
  57. data/lib/generators.rb +11 -0
  58. data/spec/acceptance/user_manages_functions_spec.rb +57 -0
  59. data/spec/acceptance/user_manages_triggers_spec.rb +51 -0
  60. data/spec/acceptance_helper.rb +62 -0
  61. data/spec/dummy/.gitignore +16 -0
  62. data/spec/dummy/Rakefile +13 -0
  63. data/spec/dummy/bin/bundle +3 -0
  64. data/spec/dummy/bin/rails +4 -0
  65. data/spec/dummy/bin/rake +4 -0
  66. data/spec/dummy/config/application.rb +15 -0
  67. data/spec/dummy/config/boot.rb +5 -0
  68. data/spec/dummy/config/database.yml +9 -0
  69. data/spec/dummy/config/environment.rb +5 -0
  70. data/spec/dummy/config.ru +4 -0
  71. data/spec/dummy/db/migrate/.keep +0 -0
  72. data/spec/features/functions/migrations_spec.rb +65 -0
  73. data/spec/features/functions/revert_spec.rb +75 -0
  74. data/spec/features/triggers/migrations_spec.rb +56 -0
  75. data/spec/features/triggers/revert_spec.rb +95 -0
  76. data/spec/fx/adapters/postgres/functions_spec.rb +37 -0
  77. data/spec/fx/adapters/postgres/triggers_spec.rb +45 -0
  78. data/spec/fx/adapters/postgres_spec.rb +146 -0
  79. data/spec/fx/command_recorder/arguments_spec.rb +41 -0
  80. data/spec/fx/command_recorder_spec.rb +171 -0
  81. data/spec/fx/configuration_spec.rb +21 -0
  82. data/spec/fx/definition_spec.rb +134 -0
  83. data/spec/fx/function_spec.rb +68 -0
  84. data/spec/fx/schema_dumper/function_spec.rb +80 -0
  85. data/spec/fx/schema_dumper/trigger_spec.rb +40 -0
  86. data/spec/fx/statements/function_spec.rb +103 -0
  87. data/spec/fx/statements/trigger_spec.rb +132 -0
  88. data/spec/fx/trigger_spec.rb +55 -0
  89. data/spec/generators/fx/function/function_generator_spec.rb +46 -0
  90. data/spec/generators/fx/trigger/trigger_generator_spec.rb +59 -0
  91. data/spec/spec_helper.rb +21 -0
  92. data/spec/support/definition_helpers.rb +37 -0
  93. data/spec/support/generator_setup.rb +11 -0
  94. data/spec/support/migration_helpers.rb +25 -0
  95. metadata +357 -0
data/.travis.yml ADDED
@@ -0,0 +1,60 @@
1
+ addons:
2
+ postgresql: "10"
3
+ apt:
4
+ packages:
5
+ - postgresql-10
6
+ - postgresql-client-10
7
+ before_install:
8
+ - "echo '--colour' > ~/.rspec"
9
+ - "echo 'gem: --no-document' > ~/.gemrc"
10
+ - git config --global user.name "Travis CI"
11
+ - git config --global user.email "travis-ci@example.com"
12
+ branches:
13
+ only:
14
+ - master
15
+ install:
16
+ - travis_retry bin/setup
17
+ language:
18
+ - ruby
19
+ notifications:
20
+ email: false
21
+ rvm:
22
+ - 3.0
23
+ - 2.7
24
+ - 2.6
25
+ - 2.5
26
+ - 2.4
27
+ gemfile:
28
+ - gemfiles/rails42.gemfile
29
+ - gemfiles/rails50.gemfile
30
+ - gemfiles/rails51.gemfile
31
+ - gemfiles/rails52.gemfile
32
+ - gemfiles/rails60.gemfile
33
+ - gemfiles/rails61.gemfile
34
+ - gemfiles/rails_edge.gemfile
35
+ matrix:
36
+ allow_failures:
37
+ - gemfile: gemfiles/rails_edge.gemfile
38
+ exclude:
39
+ - rvm: 2.4
40
+ gemfile: gemfiles/rails60.gemfile
41
+ - rvm: 2.4
42
+ gemfile: gemfiles/rails61.gemfile
43
+ - rvm: 2.4
44
+ gemfile: gemfiles/rails_edge.gemfile
45
+ - rvm: 2.5
46
+ gemfile: gemfiles/rails_edge.gemfile
47
+ - rvm: 2.6
48
+ gemfile: gemfiles/rails42.gemfile
49
+ - rvm: 2.6
50
+ gemfile: gemfiles/rails_edge.gemfile
51
+ - rvm: 2.7
52
+ gemfile: gemfiles/rails42.gemfile
53
+ - rvm: 3.0
54
+ gemfile: gemfiles/rails42.gemfile
55
+ - rvm: 3.0
56
+ gemfile: gemfiles/rails50.gemfile
57
+ - rvm: 3.0
58
+ gemfile: gemfiles/rails51.gemfile
59
+ - rvm: 3.0
60
+ gemfile: gemfiles/rails52.gemfile
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --hide-api private
2
+ --exclude templates
3
+ --markup markdown
4
+ --markup-provider redcarpet
data/Appraisals ADDED
@@ -0,0 +1,45 @@
1
+ if RUBY_VERSION < "2.6.0"
2
+ appraise "rails42" do
3
+ gem "activerecord", "~> 4.2.0"
4
+ gem "railties", "~> 4.2.0"
5
+ gem "pg", "~> 0.15.0"
6
+ gem "bigdecimal", "1.3.5"
7
+ end
8
+ end
9
+
10
+ if RUBY_VERSION >= "2.2.0" and RUBY_VERSION < "3.0.0"
11
+ appraise "rails50" do
12
+ gem "activerecord", "~> 5.0.0"
13
+ gem "railties", "~> 5.0.0"
14
+ end
15
+
16
+ appraise "rails51" do
17
+ gem "activerecord", "~> 5.1.0"
18
+ gem "railties", "~> 5.1.0"
19
+ end
20
+
21
+ appraise "rails52" do
22
+ gem "activerecord", "~> 5.2.0"
23
+ gem "railties", "~> 5.2.0"
24
+ end
25
+
26
+ end
27
+
28
+ if RUBY_VERSION >= "2.5.0"
29
+ appraise "rails60" do
30
+ gem "activerecord", "~> 6.0.0"
31
+ gem "railties", "~> 6.0.0"
32
+ end
33
+
34
+ appraise "rails61" do
35
+ gem "activerecord", "~> 6.1.0"
36
+ gem "railties", "~> 6.1.0"
37
+ end
38
+ end
39
+
40
+ if RUBY_VERSION >= "2.7.0"
41
+ appraise "rails-edge" do
42
+ gem "rails", github: "rails/rails", branch: "main"
43
+ gem "arel", :github => "rails/arel"
44
+ end
45
+ end
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,15 @@
1
+ # Contributing
2
+
3
+ 1. Fork the repository.
4
+ 2. Run `bin/setup`, which will install dependencies and create the dummy
5
+ application database.
6
+ 3. Run `bin/appraisal rake` to verify that the tests pass against all
7
+ supported versions of Rails.
8
+ 4. Make your change with new passing tests, following the existing style.
9
+ 5. Write a [good commit message], push your fork, and submit a pull request.
10
+
11
+ [good commit message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
12
+
13
+ Others will give constructive feedback. This is a time for discussion and
14
+ improvements, and making the necessary changes will be required before we can
15
+ merge the contribution.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fx.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright 2016 Teo Ljungberg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Version for Ruby on Jets
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ namespace :dummy do
5
+ require_relative "spec/dummy/config/application"
6
+ Dummy::Application.load_tasks
7
+ end
8
+
9
+ task(:spec).clear
10
+ desc "Run specs other than spec/acceptance"
11
+ RSpec::Core::RakeTask.new("spec") do |task|
12
+ task.exclude_pattern = "spec/acceptance/**/*_spec.rb"
13
+ task.verbose = false
14
+ end
15
+
16
+ desc "Run acceptance specs in spec/acceptance"
17
+ RSpec::Core::RakeTask.new("spec:acceptance") do |task|
18
+ task.pattern = "spec/acceptance/**/*_spec.rb"
19
+ task.verbose = false
20
+ end
21
+
22
+ desc "Run the specs and acceptance tests"
23
+ task default: %w(spec spec:acceptance)
data/bin/appraisal ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'appraisal' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("appraisal", "appraisal")
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fx"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/rake ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ gem install bundler --conservative
6
+ bundle check || bundle install
7
+
8
+ if [ -z "$CI" ]; then
9
+ bundle exec appraisal install
10
+ fi
11
+
12
+ bundle exec rake dummy:db:drop
13
+ bundle exec rake dummy:db:create
data/bin/yard ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'yard' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("yard", "yard")
data/fx.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fx/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fx-jets"
8
+ spec.version = Fx::VERSION
9
+ spec.authors = ["Ivan Snisarenko"]
10
+ spec.email = ["ivan"]
11
+ spec.summary = %q{Support for database functions and triggers in Rails migrations}
12
+ spec.description = <<-DESCRIPTION
13
+ Adds methods to ActiveRecord::Migration to create and manage database functions
14
+ and triggers in Rails
15
+ DESCRIPTION
16
+ spec.homepage = "https://github.com/teoljungberg/fx"
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.test_files = spec.files.grep(%r{^spec/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency "appraisal", '~> 2.3.0'
24
+ spec.add_development_dependency "bundler", '>= 1.5'
25
+ spec.add_development_dependency "database_cleaner"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec", '>= 3.3'
28
+ spec.add_development_dependency "pg"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "ammeter", '>= 1.1.3'
31
+ spec.add_development_dependency "yard"
32
+ spec.add_development_dependency "redcarpet"
33
+
34
+ spec.add_dependency "jets", '>= 2.0.0'
35
+ spec.add_dependency "activerecord", '>= 4.0.0'
36
+ spec.add_dependency "railties", '>= 4.0.0'
37
+
38
+ spec.required_ruby_version = ">= 2.1"
39
+ end
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.0"
6
+ gem "railties", "~> 4.2.0"
7
+ gem "pg", "~> 0.15.0"
8
+ gem "bigdecimal", "1.3.5"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.0.0"
6
+ gem "railties", "~> 5.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.1.0"
6
+ gem "railties", "~> 5.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.2.0"
6
+ gem "railties", "~> 5.2.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0"
6
+ gem "railties", "~> 6.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+ gem "railties", "~> 6.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", github: "rails/rails", branch: "main"
6
+ gem "arel", github: "rails/arel"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,16 @@
1
+ module Fx
2
+ module Adapters
3
+ class Postgres
4
+ # Decorates an ActiveRecord connection with methods that help determine
5
+ # the connections capabilities.
6
+ #
7
+ # Every attempt is made to use the versions of these methods defined by
8
+ # Rails where they are available and public before falling back to our own
9
+ # implementations for older Rails versions.
10
+ #
11
+ # @api private
12
+ class Connection < SimpleDelegator
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,59 @@
1
+ require "fx/function"
2
+
3
+ module Fx
4
+ module Adapters
5
+ class Postgres
6
+ # Fetches defined functions from the postgres connection.
7
+ # @api private
8
+ class Functions
9
+ # The SQL query used by F(x) to retrieve the functions considered
10
+ # dumpable into `db/schema.rb`.
11
+ FUNCTIONS_WITH_DEFINITIONS_QUERY = <<-EOS.freeze
12
+ SELECT
13
+ pp.proname AS name,
14
+ pg_get_functiondef(pp.oid) AS definition
15
+ FROM pg_proc pp
16
+ JOIN pg_namespace pn
17
+ ON pn.oid = pp.pronamespace
18
+ LEFT JOIN pg_depend pd
19
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
20
+ LEFT JOIN pg_aggregate pa
21
+ ON pa.aggfnoid = pp.oid
22
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
23
+ AND pa.aggfnoid IS NULL
24
+ ORDER BY pp.oid;
25
+ EOS
26
+
27
+ # Wraps #all as a static facade.
28
+ #
29
+ # @return [Array<Fx::Function>]
30
+ def self.all(*args)
31
+ new(*args).all
32
+ end
33
+
34
+ def initialize(connection)
35
+ @connection = connection
36
+ end
37
+
38
+ # All of the functions that this connection has defined.
39
+ #
40
+ # @return [Array<Fx::Function>]
41
+ def all
42
+ functions_from_postgres.map { |function| to_fx_function(function) }
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :connection
48
+
49
+ def functions_from_postgres
50
+ connection.execute(FUNCTIONS_WITH_DEFINITIONS_QUERY)
51
+ end
52
+
53
+ def to_fx_function(result)
54
+ Fx::Function.new(result)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,57 @@
1
+ require "fx/trigger"
2
+
3
+ module Fx
4
+ module Adapters
5
+ class Postgres
6
+ # Fetches defined triggers from the postgres connection.
7
+ # @api private
8
+ class Triggers
9
+ # The SQL query used by F(x) to retrieve the triggers considered
10
+ # dumpable into `db/schema.rb`.
11
+ TRIGGERS_WITH_DEFINITIONS_QUERY = <<-EOS.freeze
12
+ SELECT
13
+ pt.tgname AS name,
14
+ pg_get_triggerdef(pt.oid) AS definition
15
+ FROM pg_trigger pt
16
+ JOIN pg_class pc
17
+ ON (pc.oid = pt.tgrelid)
18
+ JOIN pg_proc pp
19
+ ON (pp.oid = pt.tgfoid)
20
+ WHERE pt.tgname
21
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
22
+ ORDER BY pc.oid;
23
+ EOS
24
+
25
+ # Wraps #all as a static facade.
26
+ #
27
+ # @return [Array<Fx::Trigger>]
28
+ def self.all(*args)
29
+ new(*args).all
30
+ end
31
+
32
+ def initialize(connection)
33
+ @connection = connection
34
+ end
35
+
36
+ # All of the triggers that this connection has defined.
37
+ #
38
+ # @return [Array<Fx::Trigger>]
39
+ def all
40
+ triggers_from_postgres.map { |trigger| to_fx_trigger(trigger) }
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :connection
46
+
47
+ def triggers_from_postgres
48
+ connection.execute(TRIGGERS_WITH_DEFINITIONS_QUERY)
49
+ end
50
+
51
+ def to_fx_trigger(result)
52
+ Fx::Trigger.new(result)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end