switchman 1.5.13 → 1.5.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c25757a3ecb19cfba0a82adbe3fa0e881d58c302
4
- data.tar.gz: 13b9c2b34b8f9f562b84a19bb43865436e4bdff5
3
+ metadata.gz: 991a3392b5b0202a9bcaf8029a7bb7c103ec1643
4
+ data.tar.gz: 3687768e39078beaf8fff5e1cdf2aae1cc4b2c31
5
5
  SHA512:
6
- metadata.gz: 0382c38297c9ef9cb15622fbaf342870942b660d1be4131ad085f2d891f6d38e79f5c584aba8866306f18a813703beaeafe675685f483fa75aae9de1cb1d35db
7
- data.tar.gz: 03a4c27d1596eac4ced134b60abe9a2d05970a74d89c0040b8fdb3bacd4999e785c4f3d6ee14e9aa55943dfe6574d3c725b5a3b0be2c9f8d98080133de3fc2f7
6
+ metadata.gz: 36845dd017c674600b9d7ec1d66ba5a8fe9732dcb7597d5c0490a6bbfbcceeb8def4a413941895f48a8b541f5487a33fd850b475a03c1f38a7b2b7012be0cc05
7
+ data.tar.gz: 9b6774b94a699618901e82f020f3ce61b0e54dff581e947f9e738472db2637d81c65f0afc2ef5abdb709a0e1cd238a7fac677d805a25bd602144ebe9733061c9
@@ -272,7 +272,9 @@ module Switchman
272
272
 
273
273
  def primary_shard
274
274
  unless instance_variable_defined?(:@primary_shard)
275
- @primary_shard = shards.where(name: nil).first
275
+ # if sharding isn't fully set up yet, we may not be able to query the shards table
276
+ @primary_shard = Shard.default if Shard.default.database_server == self
277
+ @primary_shard ||= shards.where(name: nil).first
276
278
  end
277
279
  @primary_shard
278
280
  end
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.5.13"
2
+ VERSION = "1.5.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.13
4
+ version: 1.5.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-06-29 00:00:00.000000000 Z
13
+ date: 2016-08-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: rspec-rails
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: '3.0'
117
+ version: 3.1.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: '3.0'
124
+ version: 3.1.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: sqlite3
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -193,7 +193,6 @@ files:
193
193
  - lib/switchman/database_server.rb
194
194
  - lib/switchman/default_shard.rb
195
195
  - lib/switchman/engine.rb
196
- - lib/switchman/engine.rb~
197
196
  - lib/switchman/environment.rb
198
197
  - lib/switchman/errors.rb
199
198
  - lib/switchman/r_spec_helper.rb
@@ -1,203 +0,0 @@
1
- module Switchman
2
- class Engine < ::Rails::Engine
3
- require 'byebug'
4
- debugger
5
- isolate_namespace Switchman
6
-
7
- config.autoload_once_paths << File.expand_path(File.join(__FILE__, "../../../app/models"))
8
-
9
- def self.lookup_stores(cache_store_config)
10
- result = {}
11
- cache_store_config.each do |key, value|
12
- next if value.is_a?(String)
13
- result[key] = ::ActiveSupport::Cache.lookup_store(value)
14
- end
15
-
16
- cache_store_config.each do |key, value|
17
- next unless value.is_a?(String)
18
- result[key] = result[value]
19
- end
20
- result
21
- end
22
-
23
- initializer 'switchman.initialize_cache', :before => 'initialize_cache' do
24
- require "switchman/active_support/cache"
25
- ::ActiveSupport::Cache.singleton_class.prepend(ActiveSupport::Cache::ClassMethods)
26
-
27
- # if we haven't already setup our cache map out-of-band, set it up from
28
- # config.cache_store now. behaves similarly to Rails' default
29
- # initialize_cache initializer, but for each value in the map, rather
30
- # than just Rails.cache. if config.cache_store is a flat value, uses it
31
- # to fill just the Rails.env entry in the cache map.
32
- unless Switchman.config[:cache_map].present?
33
- cache_store_config = ::Rails.configuration.cache_store
34
- unless cache_store_config.is_a?(Hash)
35
- cache_store_config = {::Rails.env => cache_store_config}
36
- end
37
-
38
- Switchman.config[:cache_map] = Engine.lookup_stores(cache_store_config)
39
- end
40
-
41
- # if the configured cache map (either from before, or as populated from
42
- # config.cache_store) didn't have an entry for Rails.env, add one using
43
- # lookup_store(nil); matches the behavior of Rails' default
44
- # initialize_cache initializer when config.cache_store is nil.
45
- unless Switchman.config[:cache_map].has_key?(::Rails.env)
46
- value = ::ActiveSupport::Cache.lookup_store(nil)
47
- Switchman.config[:cache_map][::Rails.env] = value
48
- end
49
-
50
- middlewares = Switchman.config[:cache_map].values.map do |store|
51
- store.middleware if store.respond_to?(:middleware)
52
- end.compact.uniq
53
- middlewares.each do |middleware|
54
- config.middleware.insert_before("Rack::Runtime", middleware)
55
- end
56
-
57
- # prevent :initialize_cache from trying to (or needing to) set
58
- # Rails.cache. once our switchman.extend_ar initializer (below) runs
59
- # Rails.cache will be overridden to pull appropriate values from the
60
- # cache map, but between now and then, Rails.cache should return the
61
- # Rails.env entry in the cache map.
62
- ::Rails.cache = Switchman.config[:cache_map][::Rails.env]
63
-
64
- require "switchman/rails"
65
- ::Rails.singleton_class.prepend(Rails::ClassMethods)
66
- end
67
-
68
- initializer 'switchman.asplode', :after => "active_record.initialize_database" do
69
- ::Rails.cache
70
- end
71
-
72
- initializer 'switchman.extend_ar', :before => "active_record.initialize_database" do
73
- ::ActiveSupport.on_load(:active_record) do
74
- require 'byebug'
75
- debugger
76
- require "switchman/active_record/abstract_adapter"
77
- require "switchman/active_record/association"
78
- require "switchman/active_record/attribute_methods"
79
- require "switchman/active_record/base"
80
- require "switchman/active_record/calculations"
81
- require "switchman/active_record/connection_handler"
82
- require "switchman/active_record/connection_pool"
83
- require "switchman/active_record/finder_methods"
84
- require "switchman/active_record/log_subscriber"
85
- require "switchman/active_record/model_schema"
86
- require "switchman/active_record/persistence"
87
- require "switchman/active_record/predicate_builder"
88
- require "switchman/active_record/query_cache"
89
- require "switchman/active_record/query_methods"
90
- require "switchman/active_record/reflection"
91
- require "switchman/active_record/relation"
92
- require "switchman/active_record/spawn_methods"
93
- require "switchman/active_record/where_clause_factory"
94
- require "switchman/active_record/type_caster"
95
- require "switchman/arel"
96
- require "switchman/shackles/relation"
97
-
98
- include ActiveRecord::Base
99
- include ActiveRecord::AttributeMethods
100
- include ActiveRecord::Persistence
101
- singleton_class.prepend ActiveRecord::ModelSchema::ClassMethods
102
-
103
- if ::Rails.version > '4.2'
104
- require "switchman/active_record/statement_cache"
105
- ::ActiveRecord::StatementCache.prepend(ActiveRecord::StatementCache)
106
- ::ActiveRecord::StatementCache::BindMap.prepend(ActiveRecord::StatementCache::BindMap)
107
- ::ActiveRecord::StatementCache::Substitute.send(:attr_accessor, :primary, :sharded)
108
-
109
- ::ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecord::CollectionAssociation)
110
- ::ActiveRecord::PredicateBuilder.singleton_class.prepend(ActiveRecord::PredicateBuilder)
111
- end
112
-
113
- if ::Rails.version > '4.1'
114
- prepend(ActiveRecord::AutosaveAssociation)
115
- end
116
-
117
- ::ActiveRecord::Associations::Association.prepend(ActiveRecord::Association)
118
- ::ActiveRecord::Associations::BelongsToAssociation.prepend(ActiveRecord::BelongsToAssociation)
119
- ::ActiveRecord::Associations::CollectionProxy.include(ActiveRecord::CollectionProxy)
120
- if ::Rails.version < '5'
121
- ::ActiveRecord::Associations::Builder::CollectionAssociation.include(ActiveRecord::Builder::CollectionAssociation)
122
- end
123
-
124
- ::ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecord::Preloader::Association)
125
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecord::AbstractAdapter)
126
- ::ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ActiveRecord::ConnectionHandler)
127
- ::ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ActiveRecord::ConnectionPool)
128
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecord::QueryCache)
129
- # when we call super in Switchman::ActiveRecord::QueryCache#select_all,
130
- # we want it to find the definition from
131
- # ActiveRecord::ConnectionAdapters::DatabaseStatements, not
132
- # ActiveRecord::ConnectionAdapters::QueryCache
133
- ::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all)
134
-
135
- ::ActiveRecord::LogSubscriber.prepend(ActiveRecord::LogSubscriber)
136
- ::ActiveRecord::Reflection::AssociationReflection.prepend(ActiveRecord::Reflection::AssociationReflection)
137
- ::ActiveRecord::Relation.prepend(ActiveRecord::Calculations)
138
- ::ActiveRecord::Relation.include(ActiveRecord::FinderMethods)
139
- ::ActiveRecord::Relation.include(ActiveRecord::QueryMethods)
140
- ::ActiveRecord::Relation.prepend(ActiveRecord::Relation)
141
- ::ActiveRecord::Relation.include(ActiveRecord::SpawnMethods)
142
- ::ActiveRecord::Relation.prepend(Shackles::Relation)
143
-
144
- if ::Rails.version >= '5'
145
- ::ActiveRecord::Relation::WhereClauseFactory.prepend(ActiveRecord::WhereClauseFactory)
146
- ::ActiveRecord::PredicateBuilder::AssociationQueryValue.prepend(ActiveRecord::PredicateBuilder::AssociationQueryValue)
147
- ::ActiveRecord::TypeCaster::Map.include(ActiveRecord::TypeCaster::Map)
148
- ::ActiveRecord::TypeCaster::Connection.include(ActiveRecord::TypeCaster::Connection)
149
- end
150
-
151
- ::Arel::Table.prepend(Arel::Table)
152
- ::Arel::Visitors::ToSql.prepend(Arel::Visitors::ToSql)
153
- ::Arel::Visitors::PostgreSQL.include(Arel::Visitors::PostgreSQL) if ::Rails.version < '4.2'
154
- end
155
- end
156
-
157
- def self.foreign_key_check(name, type, options)
158
- if name.to_s =~ /_id\z/ && type.to_s == 'integer' && options[:limit].to_i < 8
159
- puts "WARNING: All foreign keys need to be 8-byte integers. #{name} looks like a foreign key. If so, please add the option: `:limit => 8`"
160
- end
161
- end
162
-
163
- initializer 'switchman.extend_connection_adapters', :after => "active_record.initialize_database" do
164
- ::ActiveSupport.on_load(:active_record) do
165
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.descendants.each do |klass|
166
- klass.prepend(ActiveRecord::AbstractAdapter::ForeignKeyCheck)
167
- end
168
-
169
- require 'switchman/active_record/table_definition'
170
- ::ActiveRecord::ConnectionAdapters::TableDefinition.prepend(ActiveRecord::TableDefinition)
171
-
172
- if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
173
- require "switchman/active_record/postgresql_adapter"
174
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(ActiveRecord::PostgreSQLAdapter)
175
- end
176
- end
177
- end
178
-
179
- initializer 'switchman.eager_load' do
180
- ::ActiveSupport.on_load(:before_eager_load) do
181
- # This needs to be loaded before Switchman::Shard, otherwise it won't autoload it correctly
182
- require 'active_record/base'
183
- end
184
- end
185
-
186
- initializer 'switchman.extend_shackles', :before => "switchman.extend_ar" do
187
- ::ActiveSupport.on_load(:active_record) do
188
- require "switchman/shackles"
189
-
190
- ::Shackles.singleton_class.prepend(Shackles::ClassMethods)
191
- end
192
- end
193
-
194
- initializer 'switchman.extend_controller', :after => "shackles.extend_ar" do
195
- ::ActiveSupport.on_load(:action_controller) do
196
- require "switchman/action_controller/caching"
197
-
198
- ::ActionController::Base.include(ActionController::Caching)
199
- end
200
- end
201
-
202
- end
203
- end