Module: CircuitSwitch

Defined in:
lib/circuit_switch.rb,
lib/circuit_switch/core.rb,
lib/circuit_switch/engine.rb,
lib/circuit_switch/builder.rb,
lib/circuit_switch/railtie.rb,
lib/circuit_switch/version.rb,
lib/circuit_switch/notification.rb,
lib/circuit_switch/configuration.rb,
lib/circuit_switch/workers/reporter.rb,
lib/circuit_switch/stacktrace_modifier.rb,
lib/circuit_switch/workers/due_date_notifier.rb,
lib/circuit_switch/workers/run_count_updater.rb,
lib/generators/circuit_switch/install_generator.rb,
lib/generators/circuit_switch/migration_generator.rb,
lib/circuit_switch/orm/active_record/circuit_switch.rb,
app/controllers/circuit_switch/application_controller.rb,
app/controllers/circuit_switch/circuit_switch_controller.rb

Defined Under Namespace

Classes: ApplicationController, Builder, CalledNotification, CircuitSwitch, CircuitSwitchController, CircuitSwitchError, CircuitSwitchNotification, Configuration, Core, DueDateNotifier, Engine, InstallGenerator, MigrationGenerator, Railtie, Reporter, RunCountUpdater, StacktraceModifier

Constant Summary collapse

VERSION =
'0.5.1'

Class Method Summary collapse

Class Method Details

.configObject



15
16
17
# File 'lib/circuit_switch.rb', line 15

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



11
12
13
# File 'lib/circuit_switch.rb', line 11

def configure
  yield config
end

.open?(key: nil, if: nil, close_if: nil, close_if_reach_limit: nil, limit_count: nil, initially_closed: nil) ⇒ Boolean

Syntax sugar for ‘CircuitSwitch.run`

Parameters:

  • key (String) (defaults to: nil)

    Named key to find switch instead of caller

  • if (Boolean, Proc) (defaults to: nil)

    ‘CircuitSwitch.run` is runnable when `if` is truthy (default: true)

  • close_if (Boolean, Proc) (defaults to: nil)

    ‘CircuitSwitch.run` is runnable when `close_if` is falsy (default: false)

  • close_if_reach_limit (Boolean) (defaults to: nil)

    ‘CircuitSwitch.run` is NOT runnable when run count reaches limit (default: true)

  • limit_count (Integer) (defaults to: nil)

    Limit count. Use ‘run_limit_count` default value if it’s nil. Can’t be set 0 (default: nil)

  • initially_closed (Boolean) (defaults to: nil)

    Create switch with terminated mode (default: false)

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/circuit_switch.rb', line 68

def open?(key: nil, if: nil, close_if: nil, close_if_reach_limit: nil, limit_count: nil, initially_closed: nil)
  if block_given?
    raise ArgumentError.new('CircuitSwitch.open doesn\'t receive block. Use CircuitSwitch.run if you want to pass block.')
  end

  arguments = {
    key: key,
    if: binding.local_variable_get(:if),
    close_if: close_if,
    close_if_reach_limit: close_if_reach_limit,
    limit_count: limit_count,
    initially_closed: initially_closed,
  }.reject { |_, v| v.nil? }
  Builder.new.run(**arguments) {}.run?
end

.report(key: nil, if: nil, stop_report_if: nil, stop_report_if_reach_limit: nil, limit_count: nil) ⇒ Object

Parameters:

  • key (String) (defaults to: nil)

    Named key to find switch instead of caller

  • if (Boolean, Proc) (defaults to: nil)

    Report when ‘if` is truthy (default: true)

  • stop_report_if (Boolean, Proc) (defaults to: nil)

    Report when ‘close_if` is falsy (default: false)

  • stop_report_if_reach_limit (Boolean) (defaults to: nil)

    Stop reporting when reported count reaches limit (default: true)

  • limit_count (Integer) (defaults to: nil)

    Limit count. Use ‘report_limit_count` default value if it’s nil Can’t be set 0 when ‘stop_report_if_reach_limit` is true (default: nil)



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/circuit_switch.rb', line 45

def report(key: nil, if: nil, stop_report_if: nil, stop_report_if_reach_limit: nil, limit_count: nil)
  if block_given?
    raise ArgumentError.new('CircuitSwitch.report doesn\'t receive block. Use CircuitSwitch.run if you want to pass block.')
  end

  arguments = {
    key: key,
    if: binding.local_variable_get(:if),
    stop_report_if: stop_report_if,
    stop_report_if_reach_limit: stop_report_if_reach_limit,
    limit_count: limit_count
  }.reject { |_, v| v.nil? }
  Builder.new.report(**arguments)
end

.run(key: nil, if: nil, close_if: nil, close_if_reach_limit: nil, limit_count: nil, initially_closed: nil, &block) ⇒ Object

Parameters:

  • key (String) (defaults to: nil)

    Named key to find switch instead of caller

  • if (Boolean, Proc) (defaults to: nil)

    Call proc when ‘if` is truthy (default: true)

  • close_if (Boolean, Proc) (defaults to: nil)

    Call proc when ‘close_if` is falsy (default: false)

  • close_if_reach_limit (Boolean) (defaults to: nil)

    Stop calling proc when run count reaches limit (default: false)

  • limit_count (Integer) (defaults to: nil)

    Limit count. Use ‘run_limit_count` default value if it’s nil Can’t be set 0 when ‘close_if_reach_limit` is true (default: nil)

  • initially_closed (Boolean) (defaults to: nil)

    Create switch with terminated mode (default: false)

  • block (Proc)


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/circuit_switch.rb', line 27

def run(key: nil, if: nil, close_if: nil, close_if_reach_limit: nil, limit_count: nil, initially_closed: nil, &block)
  arguments = {
    key: key,
    if: binding.local_variable_get(:if),
    close_if: close_if,
    close_if_reach_limit: close_if_reach_limit,
    limit_count: limit_count,
    initially_closed: initially_closed,
  }.reject { |_, v| v.nil? }
  Builder.new.run(**arguments, &block)
end

.table_name_prefixObject



2
3
4
# File 'lib/circuit_switch/engine.rb', line 2

def self.table_name_prefix
  ''
end