Skip to content

Commit

Permalink
Set/read @Sharded class ivar with attr_accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
bquorning committed Mar 29, 2017
1 parent 574690c commit e5525bb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/active_record_shards/model.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# frozen_string_literal: true

module ActiveRecordShards
module Model
def not_sharded
if self != ActiveRecord::Base && self != base_class
raise "You should only call not_sharded on direct descendants of ActiveRecord::Base"
end
@sharded = false
self.sharded = false
end

def is_sharded? # rubocop:disable Style/PredicateName
sharded_ivar = defined?(@sharded) ? @sharded : nil
if self == ActiveRecord::Base
sharded_ivar != false && supports_sharding?
sharded != false && supports_sharding?
elsif self == base_class
if sharded_ivar.nil?
if sharded.nil?
ActiveRecord::Base.is_sharded?
else
sharded_ivar != false
sharded != false
end
else
base_class.is_sharded?
Expand Down Expand Up @@ -58,5 +58,6 @@ def self.extended(base)
private

attr_reader :on_slave_by_default
attr_accessor :sharded
end
end

0 comments on commit e5525bb

Please sign in to comment.