switchman 1.8.2 → 1.9.0
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 +4 -4
- data/lib/switchman/active_record/calculations.rb +3 -7
- data/lib/switchman/active_record/finder_methods.rb +2 -3
- data/lib/switchman/active_record/relation.rb +6 -12
- data/lib/switchman/call_super.rb +18 -0
- data/lib/switchman/engine.rb +3 -1
- data/lib/switchman/version.rb +1 -1
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d2e63c8b9d8a43c1cf8716f775593bc0e5c7296b
         | 
| 4 | 
            +
              data.tar.gz: c4cda98c0bbdf18d0c648adcf8d8465c90f2246e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f2e7e0889dce714d0d128eeca5b09434ba0cd313ebe9e09db2f1d58e7d706e6aa1353e03b54496d2f145fbd19467c74bd095870025eb6fca0321170c06ffd14a
         | 
| 7 | 
            +
              data.tar.gz: e0614890e323dcedd8b272e1ec571be80de1640d27601d9c905208e4fca69931676ec03e4ef038775aa634e43751909bdf0b18f261fe32b1c8a394764c830d24
         | 
| @@ -1,16 +1,13 @@ | |
| 1 1 | 
             
            module Switchman
         | 
| 2 2 | 
             
              module ActiveRecord
         | 
| 3 3 | 
             
                module Calculations
         | 
| 4 | 
            -
                  CALL_SUPER = Object.new.freeze
         | 
| 5 | 
            -
                  private_constant :CALL_SUPER
         | 
| 6 4 |  | 
| 7 5 | 
             
                  def pluck(*column_names)
         | 
| 8 | 
            -
                    return super(*column_names[1..-1]) if column_names.first.equal?(CALL_SUPER)
         | 
| 9 6 | 
             
                    target_shard = Shard.current(klass.shard_category)
         | 
| 10 7 | 
             
                    shard_count = 0
         | 
| 11 8 | 
             
                    result = self.activate do |relation, shard|
         | 
| 12 9 | 
             
                      shard_count += 1
         | 
| 13 | 
            -
                      results = relation.pluck | 
| 10 | 
            +
                      results = relation.call_super(:pluck, Calculations, *column_names)
         | 
| 14 11 | 
             
                      if column_names.length > 1
         | 
| 15 12 | 
             
                        column_names.each_with_index do |column_name, idx|
         | 
| 16 13 | 
             
                          if klass.sharded_column?(column_name)
         | 
| @@ -30,13 +27,12 @@ module Switchman | |
| 30 27 | 
             
                    result
         | 
| 31 28 | 
             
                  end
         | 
| 32 29 |  | 
| 33 | 
            -
                  def execute_simple_calculation(operation, column_name, distinct | 
| 34 | 
            -
                    return super(operation, column_name, distinct) if super_method
         | 
| 30 | 
            +
                  def execute_simple_calculation(operation, column_name, distinct)
         | 
| 35 31 | 
             
                    operation = operation.to_s.downcase
         | 
| 36 32 | 
             
                    if operation == "average"
         | 
| 37 33 | 
             
                      result = calculate_simple_average(column_name, distinct)
         | 
| 38 34 | 
             
                    else
         | 
| 39 | 
            -
                      result = self.activate{ |relation| relation. | 
| 35 | 
            +
                      result = self.activate{ |relation| relation.call_super(:execute_simple_calculation, Calculations, operation, column_name, distinct) }
         | 
| 40 36 | 
             
                      if result.is_a?(Array)
         | 
| 41 37 | 
             
                        case operation
         | 
| 42 38 | 
             
                        when "count", "sum"
         | 
| @@ -1,9 +1,8 @@ | |
| 1 1 | 
             
            module Switchman
         | 
| 2 2 | 
             
              module ActiveRecord
         | 
| 3 3 | 
             
                module FinderMethods
         | 
| 4 | 
            -
                  def find_one(id | 
| 4 | 
            +
                  def find_one(id)
         | 
| 5 5 | 
             
                    return super(id) unless klass.integral_id?
         | 
| 6 | 
            -
                    return super(id) if call_super
         | 
| 7 6 |  | 
| 8 7 | 
             
                    if shard_source_value != :implicit
         | 
| 9 8 | 
             
                      current_shard = Shard.current(klass.shard_category)
         | 
| @@ -14,7 +13,7 @@ module Switchman | |
| 14 13 | 
             
                        # skip the shard if the object can't be on it. unless we're only looking at one shard;
         | 
| 15 14 | 
             
                        # we might be expecting a shadow object
         | 
| 16 15 | 
             
                        next if current_id > Shard::IDS_PER_SHARD && self.all_shards.length > 1
         | 
| 17 | 
            -
                        relation. | 
| 16 | 
            +
                        relation.call_super(:find_one, FinderMethods, current_id)
         | 
| 18 17 | 
             
                      end
         | 
| 19 18 | 
             
                      if result.is_a?(Array)
         | 
| 20 19 | 
             
                        result = result.first
         | 
| @@ -42,17 +42,15 @@ module Switchman | |
| 42 42 | 
             
                    primary_shard.activate(klass.shard_category) { super }
         | 
| 43 43 | 
             
                  end
         | 
| 44 44 |  | 
| 45 | 
            -
                  def explain | 
| 46 | 
            -
                     | 
| 47 | 
            -
                    self.activate { |relation| relation.explain(super_method: true) }
         | 
| 45 | 
            +
                  def explain
         | 
| 46 | 
            +
                    self.activate { |relation| relation.call_super(:explain, Relation) }
         | 
| 48 47 | 
             
                  end
         | 
| 49 48 |  | 
| 50 49 | 
             
                  to_a_method = ::Rails.version >= '5' ? :records : :to_a
         | 
| 51 50 | 
             
                  class_eval <<-RUBY, __FILE__, __LINE__ + 1
         | 
| 52 | 
            -
                    def #{to_a_method} | 
| 53 | 
            -
                      return super() if super_method
         | 
| 51 | 
            +
                    def #{to_a_method}
         | 
| 54 52 | 
             
                      return @records if loaded?
         | 
| 55 | 
            -
                      results = self.activate { |relation| relation | 
| 53 | 
            +
                      results = self.activate { |relation| relation.call_super(#{to_a_method.inspect}, Relation) }
         | 
| 56 54 | 
             
                      case shard_value
         | 
| 57 55 | 
             
                      when Array, ::ActiveRecord::Relation, ::ActiveRecord::Base
         | 
| 58 56 | 
             
                        @records = results
         | 
| @@ -62,14 +60,10 @@ module Switchman | |
| 62 60 | 
             
                    end
         | 
| 63 61 | 
             
                  RUBY
         | 
| 64 62 |  | 
| 65 | 
            -
                   | 
| 66 | 
            -
                  private_constant :CALL_SUPER
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                  %w{update_all delete_all}.each do |method|
         | 
| 63 | 
            +
                  %I{update_all delete_all}.each do |method|
         | 
| 69 64 | 
             
                    class_eval <<-RUBY, __FILE__, __LINE__ + 1
         | 
| 70 65 | 
             
                      def #{method}(*args)
         | 
| 71 | 
            -
                         | 
| 72 | 
            -
                        result = self.activate { |relation| relation.#{method}(CALL_SUPER, *args) }
         | 
| 66 | 
            +
                        result = self.activate { |relation| relation.call_super(#{method.inspect}, Relation, *args) }
         | 
| 73 67 | 
             
                        result = result.sum if result.is_a?(Array)
         | 
| 74 68 | 
             
                        result
         | 
| 75 69 | 
             
                      end
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            module Switchman
         | 
| 2 | 
            +
              module CallSuper
         | 
| 3 | 
            +
                def super_method_above(method_name, above_module)
         | 
| 4 | 
            +
                  @super_methods ||= {}
         | 
| 5 | 
            +
                  @super_methods[[method_name, above_module]] ||= begin
         | 
| 6 | 
            +
                    method = method(method_name)
         | 
| 7 | 
            +
                    while method.owner != above_module
         | 
| 8 | 
            +
                      method = method.super_method
         | 
| 9 | 
            +
                    end
         | 
| 10 | 
            +
                    method.super_method
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def call_super(method, above_module, *args, &block)
         | 
| 15 | 
            +
                  super_method_above(method, above_module).call(*args, &block)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
    
        data/lib/switchman/engine.rb
    CHANGED
    
    | @@ -84,6 +84,7 @@ module Switchman | |
| 84 84 | 
             
                    require "switchman/active_record/type_caster"
         | 
| 85 85 | 
             
                    require "switchman/active_record/where_clause_factory"
         | 
| 86 86 | 
             
                    require "switchman/arel"
         | 
| 87 | 
            +
                    require "switchman/call_super"
         | 
| 87 88 | 
             
                    require "switchman/rails"
         | 
| 88 89 | 
             
                    require "switchman/shackles/relation"
         | 
| 89 90 | 
             
                    require "switchman/shard_internal"
         | 
| @@ -134,9 +135,10 @@ module Switchman | |
| 134 135 | 
             
                    ::ActiveRecord::Relation.prepend(ActiveRecord::Calculations)
         | 
| 135 136 | 
             
                    ::ActiveRecord::Relation.include(ActiveRecord::FinderMethods)
         | 
| 136 137 | 
             
                    ::ActiveRecord::Relation.include(ActiveRecord::QueryMethods)
         | 
| 138 | 
            +
                    ::ActiveRecord::Relation.prepend(Shackles::Relation)
         | 
| 137 139 | 
             
                    ::ActiveRecord::Relation.prepend(ActiveRecord::Relation)
         | 
| 138 140 | 
             
                    ::ActiveRecord::Relation.include(ActiveRecord::SpawnMethods)
         | 
| 139 | 
            -
                    ::ActiveRecord::Relation. | 
| 141 | 
            +
                    ::ActiveRecord::Relation.include(CallSuper)
         | 
| 140 142 |  | 
| 141 143 | 
             
                    if ::Rails.version >= '5'
         | 
| 142 144 | 
             
                      ::ActiveRecord::Relation::WhereClauseFactory.prepend(ActiveRecord::WhereClauseFactory)
         | 
    
        data/lib/switchman/version.rb
    CHANGED
    
    
    
        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. | 
| 4 | 
            +
              version: 1.9.0
         | 
| 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-12- | 
| 13 | 
            +
            date: 2016-12-08 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: railties
         | 
| @@ -218,6 +218,7 @@ files: | |
| 218 218 | 
             
            - lib/switchman/active_record/where_clause_factory.rb
         | 
| 219 219 | 
             
            - lib/switchman/active_support/cache.rb
         | 
| 220 220 | 
             
            - lib/switchman/arel.rb
         | 
| 221 | 
            +
            - lib/switchman/call_super.rb
         | 
| 221 222 | 
             
            - lib/switchman/connection_pool_proxy.rb
         | 
| 222 223 | 
             
            - lib/switchman/database_server.rb
         | 
| 223 224 | 
             
            - lib/switchman/default_shard.rb
         | 
| @@ -247,7 +248,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 247 248 | 
             
              requirements:
         | 
| 248 249 | 
             
              - - ">="
         | 
| 249 250 | 
             
                - !ruby/object:Gem::Version
         | 
| 250 | 
            -
                  version: '2. | 
| 251 | 
            +
                  version: '2.3'
         | 
| 251 252 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 252 253 | 
             
              requirements:
         | 
| 253 254 | 
             
              - - ">="
         | 
| @@ -255,9 +256,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 255 256 | 
             
                  version: '0'
         | 
| 256 257 | 
             
            requirements: []
         | 
| 257 258 | 
             
            rubyforge_project: 
         | 
| 258 | 
            -
            rubygems_version: 2. | 
| 259 | 
            +
            rubygems_version: 2.5.2
         | 
| 259 260 | 
             
            signing_key: 
         | 
| 260 261 | 
             
            specification_version: 4
         | 
| 261 262 | 
             
            summary: Rails 4 sharding magic
         | 
| 262 263 | 
             
            test_files: []
         | 
| 263 | 
            -
            has_rdoc: 
         |