lib/mixed_gauge/model.rb in mixed_gauge-1.2.0.beta2 vs lib/mixed_gauge/model.rb in mixed_gauge-1.2.0

- old
+ new

@@ -25,10 +25,11 @@ class_attribute :distkey, instance_writer: false class_attribute :replication_mapping, instance_writer: false class_attribute :service, instance_writer: false end + # ClassMethods module ClassMethods # The cluster config must be defined before `use_cluster`. # @param [Symbol] name A cluster name which is set by MixedGauge.configure def use_cluster(name, thread_pool_size_base: 3) config = MixedGauge.config.fetch_cluster_config(name) @@ -38,11 +39,11 @@ self.service = Expeditor::Service.new( executor: Concurrent::ThreadPoolExecutor.new( min_threads: thread_size, max_threads: thread_size, max_queue: shard_repository.all.size, - fallback_policy: :abort, + fallback_policy: :abort ) ) self.abstract_class = true end @@ -67,11 +68,11 @@ # @raise [MixedGauge::MissingDistkeyAttribute] def put!(attributes) raise '`distkey` is not defined. Use `def_distkey`.' unless distkey @before_put_callback.call(attributes) if @before_put_callback - if key = attributes[distkey] || attributes[distkey.to_s] + if (key = attributes[distkey]) || attributes[distkey.to_s] shard_for(key).create!(attributes) else raise MixedGauge::MissingDistkeyAttribute end end @@ -89,11 +90,11 @@ # as AR's RecordNotFound. # @param [String] key # @return [ActiveRecord::Base] A shard model instance # @raise [MixedGauge::RecordNotFound] def get!(key) - get(key) or raise MixedGauge::RecordNotFound + get(key) || raise(MixedGauge::RecordNotFound) end # Register hook to assign auto-generated distkey or something. # Sometimes you want to generates distkey value before validation. Since # mixed_gauge generates sub class of your models, AR's callback is not @@ -132,10 +133,10 @@ # @example # User.all_shards_in_parallel.map {|m| m.where.find_by(name: 'Alice') }.compact def all_shards_in_parallel AllShardsInParallel.new(all_shards, service: service) end - alias_method :parallel, :all_shards_in_parallel + alias parallel all_shards_in_parallel # See example definitions in `spec/models.rb`. # @param [Symbol] A role name of target cluster. # @return [Class, Object] if block given then yielded result else # target shard model.