fly-ruby 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea1ca64bcd11ed8a60774f0d8ec255ffb49bc6b8e21a8bd32e7410068bec35c0
4
- data.tar.gz: fb55ad6c98cb631bf202aea206c53a9b2e9a7c738cd9835095dd647011cfc7f6
3
+ metadata.gz: bc19c3c6ff9a2dd0cfdc09640fa1bfd3a4eeeb60ff9be84774cdda50b8956faf
4
+ data.tar.gz: 44646945289997faed2261594766a55ae2c343f272c7aa85bedb116cb869037a
5
5
  SHA512:
6
- metadata.gz: 7c3df04f8bb9f97bfb87903b0fffc14ef2b320802e1183752c07f8b769b629f6c66af21ae0e4bb5a23a2608cfdfdda2f3b1c387e3edcd1f64b5d2474a79f7a6f
7
- data.tar.gz: ff4ca7c18d4b18ec237c8e1c59bce88dce849198934ed1d42c28ab2a081b577f8fa2cc38930d0478ec94a5bee580e2f12649b38d3ad46d176a774edaba60446c
6
+ metadata.gz: 17454e355c0f56c595fc3f01548b9bad679545d6d4da74ae20f813a441c878db6234ddee67cb67e2327449d18de6339accd9e14277103b036d1a7e9a767196ef
7
+ data.tar.gz: 065b6d3473c02437a1123751524a4812c8bc7bb5b1da0736f095abdf5c9b4437a13709b5e5a63b0fd8d241c52160cbe20a99e8117fc3e0a164f4cf665d3978d1
@@ -7,8 +7,6 @@ jobs:
7
7
  strategy:
8
8
  matrix:
9
9
  include:
10
- - { os: ubuntu-latest, ruby_version: 2.5 }
11
- - { os: ubuntu-latest, ruby_version: 2.6 }
12
10
  - { os: ubuntu-latest, ruby_version: 2.7 }
13
11
  - { os: ubuntu-latest, ruby_version: '3.0' }
14
12
  services:
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ gem 'rack-test'
6
6
  gem 'minitest'
7
7
  gem "rails"
8
8
  gem "pg"
9
+ gem "sqlite3"
9
10
  gem "climate_control"
10
11
  gem "minitest-around"
11
12
  gem "m"
@@ -62,12 +62,12 @@ module Fly
62
62
 
63
63
  def database_uri
64
64
  @database_uri ||= URI.parse(database_url)
65
- @database_uri
66
65
  end
67
66
 
68
67
  def regional_database_url
69
68
  uri = database_uri.dup
70
69
  uri.host = regional_database_host
70
+ uri.port = regional_database_port
71
71
  uri.to_s
72
72
  end
73
73
 
@@ -75,13 +75,15 @@ module Fly
75
75
  "#{current_region}.#{database_uri.hostname}"
76
76
  end
77
77
 
78
- # Rails-compatible database configuration
79
- def regional_database_config
80
- {
81
- :host => regional_database_host,
82
- :port => 5433,
83
- :adapter => "postgresql"
84
- }
78
+ def regional_database_port
79
+ port = if in_secondary_region?
80
+ case database_uri.scheme
81
+ when "postgres"
82
+ 5433
83
+ end
84
+ end
85
+
86
+ port || database_uri.port
85
87
  end
86
88
 
87
89
  def redis_uri
@@ -103,6 +105,10 @@ module Fly
103
105
  database_url && primary_region && current_region && web?
104
106
  end
105
107
 
108
+ def hijack_database_connection?
109
+ in_secondary_region? && !database_uri.scheme.start_with?("sqlite")
110
+ end
111
+
106
112
  def in_secondary_region?
107
113
  primary_region && primary_region != current_region
108
114
  end
@@ -1,19 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Fly::Railtie < Rails::Railtie
4
- def hijack_database_connection
5
- ActiveSupport::Reloader.to_prepare do
6
- # If we already have a database connection when this initializer runs,
7
- # we should reconnect to the region-local database. This may need some additional
8
- # hooks for forking servers to work correctly.
9
- if defined?(ActiveRecord)
10
- config = ActiveRecord::Base.connection_db_config.configuration_hash
11
- ActiveRecord::Base.establish_connection(config.symbolize_keys.merge(Fly.configuration.regional_database_config))
12
- end
13
- end
14
- end
15
-
16
- initializer("fly.regional_database") do |app|
4
+ initializer("fly.regional_database", before: "active_record.initialize_database") do |app|
17
5
  # Insert the request middleware high in the stack, but after static file delivery
18
6
  app.config.middleware.insert_after ActionDispatch::Executor, Fly::Headers if Fly.configuration.web?
19
7
 
@@ -22,8 +10,8 @@ class Fly::Railtie < Rails::Railtie
22
10
  # Insert the database exception handler at the bottom of the stack to take priority over other exception handlers
23
11
  app.config.middleware.use Fly::RegionalDatabase::DbExceptionHandlerMiddleware
24
12
 
25
- if Fly.configuration.in_secondary_region?
26
- hijack_database_connection
13
+ if Fly.configuration.hijack_database_connection?
14
+ ENV["DATABASE_URL"] = Fly.configuration.regional_database_url
27
15
  end
28
16
  elsif Fly.configuration.web?
29
17
  puts "Warning: DATABASE_URL, PRIMARY_REGION and FLY_REGION must be set to activate the fly-ruby middleware. Middleware not loaded."
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fly
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/fly-ruby.rb CHANGED
@@ -22,16 +22,14 @@ module Fly
22
22
  end
23
23
 
24
24
  class Instance
25
- attr_accessor :configuration
25
+ attr_writer :configuration
26
26
 
27
- def initialize
28
- self.configuration = Fly::Configuration.new
27
+ def configuration
28
+ @configuration ||= Fly::Configuration.new
29
29
  end
30
30
 
31
- def configure
32
- configuration = Fly::Configuration.new
33
- yield(configuration) if block_given?
34
- self.configuration = configuration
31
+ def configure(&block)
32
+ configuration.tap(&block)
35
33
  end
36
34
  end
37
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fly-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Sierles