circuit_switch 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4cdb8d820d7ecce566ca391ad90990a2df09007d23ab3c223dbac66a3fcaa93
4
- data.tar.gz: adb2a3ab38f303dd610f10a964014cbe75f0c752f5f6cd24ebf3c03319329c96
3
+ metadata.gz: d036ceb2748b3432749f5a03d83d324b59d1acb340bb7d64cbe3ef86f5531c4f
4
+ data.tar.gz: 32b8e3dbe02c1eaf8e25b40ab26f97036ecf33402bf974e6b71cb989db8c3178
5
5
  SHA512:
6
- metadata.gz: 25f3265010930a67234ab82ad2aac34915460c12fd2f85789961c93f32e459ef8af0516bac47160b390564056aad9d51f3d75dbf36103294eae72962944f3b77
7
- data.tar.gz: bd0195acf137e1aba67081a1c0bef74a58cb8594cc4e2960eb899c88c5dfad84f0759761fce7aaab45a4b0ea860fc86057dbbda6c6490b03f5581f5a28219284
6
+ metadata.gz: fa10c7a2196b37619dc94605efca82c8b3ce5b3182063004911f8aa28bef44f711e945adc73f38857e85a40a6f005b1139a7fac990e76e39a45080e481a93c3f
7
+ data.tar.gz: 3619df1cd293ba93f271ca536bcb55f4152a20810e52fb7aba16cd44e11b6bd081645bc1804f4f01c47a49c056a1793e840de5715f4c54126b4bdda8887f1d0c
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ os: [ubuntu-latest, windows-latest, macos-latest]
11
+ ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, head, truffleruby]
12
+ exclude:
13
+ - os: windows-latest
14
+ ruby: head
15
+ - os: windows-latest
16
+ ruby: truffleruby
17
+ runs-on: ${{ matrix.os }}
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - name: Run the default task
26
+ run: |
27
+ bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0
2
+
3
+ ### Breaking Changes
4
+
5
+ * Modify default value of `CircuitSwitch.run` argument `close_if_reach_limit` from true to false.
6
+
1
7
  ## 0.1.2
2
8
 
3
9
  * Modify `CircuitSwitch.open?` recieves same arguments as `CircuitSwtich.run`
data/README.md CHANGED
@@ -57,12 +57,13 @@ end
57
57
  ```
58
58
 
59
59
  `run` calls received proc, and when conditions are met, closes it's circuit.
60
- To switch circuit opening and closing, some conditions can be set. By default, the circuit is closed when reached the specified count. The default count is 10. To change this default value, modify `circuit_switches.run_limit_count` default value in the migration file.
60
+ To switch circuit opening and closing, some conditions can be set. By default, the circuit is always opened.
61
+ You can also set `limit_count` to close circuit when reached the specified count. Default limit_count is 10. To change this default value, modify `circuit_switches.run_limit_count` default value in the migration file.
61
62
  `run` receives optional arguments.
62
63
 
63
64
  - `if`: [Boolean, Proc] Call proc when `if` is truthy (default: true)
64
65
  - `close_if`: [Boolean, Proc] Call proc when `close_if` is falsy (default: false)
65
- - `close_if_reach_limit`: [Boolean] Stop calling proc when run count reaches limit (default: true)
66
+ - `close_if_reach_limit`: [Boolean] Stop calling proc when run count reaches limit (default: false)
66
67
  - `limit_count`: [Integer] Limit count. Use `run_limit_count` default value if it's nil (default: nil)
67
68
  Can't be set 0 when `close_if_reach_limit` is true
68
69
 
@@ -83,7 +84,7 @@ unless circuit_open
83
84
  end
84
85
  ```
85
86
 
86
- `CircuitSwitch.run.run?` has syntax sugar. `open` doesn't receive proc.
87
+ `CircuitSwitch.run.run?` has syntax sugar. `open?` doesn't receive proc.
87
88
 
88
89
  ```ruby
89
90
  if CircuitSwitch.open?
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
- task :default => :spec
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -5,13 +5,17 @@ module CircuitSwitch
5
5
  def run(
6
6
  if: true,
7
7
  close_if: false,
8
- close_if_reach_limit: true,
8
+ close_if_reach_limit: nil,
9
9
  limit_count: nil,
10
10
  &block
11
11
  )
12
12
  if close_if_reach_limit && limit_count == 0
13
13
  raise CircuitSwitchError.new('Can\'t set limit_count to 0 when close_if_reach_limit is true')
14
14
  end
15
+ if close_if_reach_limit.nil?
16
+ Logger.new($stdout).warn('Default value for close_if_reach_limit is modified from true to false at ver 0.2.0.')
17
+ close_if_reach_limit = false
18
+ end
15
19
  return self if evaluate(close_if) || !evaluate(binding.local_variable_get(:if))
16
20
  return self if close_if_reach_limit && switch.reached_run_limit?(limit_count)
17
21
  return self if switch.run_is_terminated?
@@ -70,8 +74,8 @@ module CircuitSwitch
70
74
 
71
75
  def called_path
72
76
  @called_path ||= caller
73
- .reject { |path| path.match?(/(#{config.silent_paths.join('|')})/) }
74
- .detect { |path| path.match?(/(#{config.report_paths.join('|')})/) }
77
+ .reject { |path| /(#{config.silent_paths.join('|')})/.match?(path) }
78
+ .detect { |path| /(#{config.report_paths.join('|')})/.match?(path) }
75
79
  &.sub(/(#{config.strip_paths.join('|')})/, '')
76
80
  &.gsub(/[`']/, '') ||
77
81
  "/somewhere/in/library:in #{Date.today}"
@@ -7,7 +7,7 @@ module CircuitSwitch
7
7
 
8
8
  def call(backtrace:)
9
9
  backtrace
10
- .select { |path| path.match?(/(#{config.allowed_backtrace_paths.join('|')})/) }
10
+ .select { |path| /(#{config.allowed_backtrace_paths.join('|')})/.match?(path) }
11
11
  .map { |path| path.sub(/(#{config.strip_paths.join('|')})/, '') }
12
12
  .join("\n")
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module CircuitSwitch
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -20,14 +20,14 @@ module CircuitSwitch
20
20
 
21
21
  # @param if [Boolean, Proc] Call proc when `if` is truthy (default: true)
22
22
  # @param close_if [Boolean, Proc] Call proc when `close_if` is falsy (default: false)
23
- # @param close_if_reach_limit [Boolean] Stop calling proc when run count reaches limit (default: true)
23
+ # @param close_if_reach_limit [Boolean] Stop calling proc when run count reaches limit (default: false)
24
24
  # @param limit_count [Integer] Limit count. Use `run_limit_count` default value if it's nil
25
25
  # Can't be set 0 when `close_if_reach_limit` is true (default: nil)
26
26
  # @param [Proc] block
27
27
  def run(
28
28
  if: true,
29
29
  close_if: false,
30
- close_if_reach_limit: true,
30
+ close_if_reach_limit: nil,
31
31
  limit_count: nil,
32
32
  &block
33
33
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuit_switch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - makicamel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-10 00:00:00.000000000 Z
11
+ date: 2021-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -102,6 +102,7 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".github/workflows/main.yml"
105
106
  - ".gitignore"
106
107
  - CHANGELOG.md
107
108
  - CODE_OF_CONDUCT.md