Module: DbCharmer::ActionController::ForceSlaveReads::ClassMethods

Defined in:
lib/db_charmer/action_controller/force_slave_reads.rb

Constant Summary collapse

@@db_charmer_force_slave_reads_actions =
{}

Instance Method Summary collapse

Instance Method Details

#force_slave_reads(params = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/db_charmer/action_controller/force_slave_reads.rb', line 7

def force_slave_reads(params = {})
  @@db_charmer_force_slave_reads_actions[self.name] = {
    :except => params[:except] ? [*params[:except]].map(&:to_s) : [],
    :only => params[:only] ? [*params[:only]].map(&:to_s) : []
  }
end

#force_slave_reads_action?(name = nil) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/db_charmer/action_controller/force_slave_reads.rb', line 18

def force_slave_reads_action?(name = nil)
  name = name.to_s

  options = force_slave_reads_options
  # If no options were defined for this controller, all actions are not forced to use slaves
  return false unless options

  # Actions where force_slave_reads mode was turned off
  return false if options[:except].include?(name)

  # Only for these actions force_slave_reads was turned on
  return options[:only].include?(name) if options[:only].any?

  # If :except is not empty, we're done with the checks and rest of the actions are should force slave reads
  # Otherwise, all the actions are not in force_slave_reads mode
  options[:except].any?
end

#force_slave_reads_optionsObject



14
15
16
# File 'lib/db_charmer/action_controller/force_slave_reads.rb', line 14

def force_slave_reads_options
  @@db_charmer_force_slave_reads_actions[self.name]
end