switchman 1.2.32 → 1.2.33

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: d8b6039fc60b8a5db9ef9281e88c08877f7e1d26
4
- data.tar.gz: 91f66cda658940618dcdb0da4629cbc8a7f17efc
3
+ metadata.gz: a349637588bb7ed6a77000f7e289c69f1a4631d8
4
+ data.tar.gz: 495616221bc75fcd1921a736fe7fd6fbba32a3ef
5
5
  SHA512:
6
- metadata.gz: 647c24616377cff9c9d3f5fcbc57186ae5886ce04d3a6297fbcd27990f1bba8211ba5acb0db20eaf9bfb3fa13a4f88837fea10eda4b985e4652c896d2ba90cbc
7
- data.tar.gz: 3a87e1c36cd2a001029ac5aae33a7dcd6cda63028c152e9191248d2517c2de888632f003286831cf2001b81a3daf8cebdfaea3f58333486baccbb4492a4974e4
6
+ metadata.gz: 2c5775a79605ae66621b26e907c90a99fb773134ad0248a4325000de2a7423e9cbff71c5f7272b9ee458495205752fa2c32bd584a9bfc93116b06d1ba3c85a8a
7
+ data.tar.gz: ae552414da6895cbc182124ce667f52a8b8652f1fce32b936b908a2186ab04858647ddbb0b7164fa4aa3483665ff7538a3414238cfb88c50ec024fa6cb9776d3
@@ -21,6 +21,8 @@ module Switchman
21
21
 
22
22
  after_save :clear_cache
23
23
 
24
+ scope :primary, -> { where(name: nil).order(:database_server_id, :id).distinct_on(:database_server_id) }
25
+
24
26
  class << self
25
27
  def categories
26
28
  CATEGORIES.keys
@@ -372,6 +374,10 @@ module Switchman
372
374
  end
373
375
  end
374
376
 
377
+ def primary?
378
+ self == database_server.primary_shard
379
+ end
380
+
375
381
  # takes an id-ish, and returns an integral id relative to
376
382
  # target_shard. returns any_id itself if it can't be interpreted
377
383
  def relative_id_for(any_id, source_shard, target_shard)
@@ -265,6 +265,13 @@ module Switchman
265
265
  end
266
266
  end
267
267
 
268
+ def primary_shard
269
+ unless instance_variable_defined?(:@primary_shard)
270
+ @primary_shard = shards.where(name: nil).first
271
+ end
272
+ @primary_shard
273
+ end
274
+
268
275
  private
269
276
  def reset_column_information
270
277
  ::ActiveRecord::Base.connection_handler.switchman_connection_pool_proxies.each { |pool| pool.schema_cache.clear! }
@@ -6,6 +6,7 @@ module Switchman
6
6
  def activate(*categories); yield; end
7
7
  def activate!(*categories); end
8
8
  def default?; true; end
9
+ def primary?; true; end
9
10
  def relative_id_for(local_id, target = nil); local_id; end
10
11
  def global_id_for(local_id); local_id; end
11
12
  def database_server_id; nil; end
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.2.32"
2
+ VERSION = "1.2.33"
3
3
  end
@@ -72,6 +72,10 @@ module Switchman
72
72
  shard_ids << Shard.default.id
73
73
  elsif id == '-default'
74
74
  negative_shard_ids << Shard.default.id
75
+ elsif id == 'primary'
76
+ shard_ids.concat(Shard.primary.pluck(:id))
77
+ elsif id == '-primary'
78
+ negative_shard_ids.concat(Shard.primary.pluck(:id))
75
79
  elsif id =~ /(-?)(\d+)?\.\.(\.)?(\d+)?/
76
80
  negative, start, open, finish = $1.present?, $2, $3.present?, $4
77
81
  raise "Invalid shard id or range: #{id}" unless start || finish
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.2.32
4
+ version: 1.2.33
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: 2015-05-04 00:00:00.000000000 Z
13
+ date: 2015-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -511,7 +511,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
511
511
  version: '0'
512
512
  requirements: []
513
513
  rubyforge_project:
514
- rubygems_version: 2.4.4
514
+ rubygems_version: 2.4.5
515
515
  signing_key:
516
516
  specification_version: 4
517
517
  summary: Rails 3 sharding magic