safer_initialize 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d1a0a1379fa5b8961957236e9d8874628778b5f0efcb0797dacd212f1f945f3
4
- data.tar.gz: '08ebcf3e47c5094f658de8b8f410fbae7703a4b0de277dbbff348bf9759731e1'
3
+ metadata.gz: 31eb1c05500e2d20207203e3d4d65a29507920d6f0da6b0cadaef0d87df81b12
4
+ data.tar.gz: 9d8f0360e41cb13a56314c79c3bb64e46ba892ffcc40351d1ec241ab96f53b0e
5
5
  SHA512:
6
- metadata.gz: 011f7d7ca6628edf1bf8adb0f7eead6cbeb92e6d66f764c7552a10bbef6e05cbda521d5b8d5e9be9a23271ec71153d5c1d131c7b32bbee1943f00456cb13efc8
7
- data.tar.gz: cc5b68986507e190b4162c258a3fc107265e78b29f205d08ca18e97161d518b403129fbe40396f59376a7ee544291101a5cd2ab5eb7de5c4292f3c51917dacf8
6
+ metadata.gz: f1cb3bbc1654debbf28f5e336bd46bc7f03ad9ed3e65d1e651f41e3a83bff1591a3e5e4418f41027cc557e78796e299c40537a590cbb5ebc34b762e14df0a8c0
7
+ data.tar.gz: 5dd462b38e4b9058de7eccf5853aa788133d2374282f3af2297b02cdacef1b20e22a77600f7546e0cb6ca4c9785f17d92e0ffea4c171dbd46710c31e30a38482
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.0
2
+
3
+ - Add `error_handle` config
4
+
1
5
  ## 0.1.0
2
6
 
3
7
  - First Release
data/README.md CHANGED
@@ -24,6 +24,10 @@ In `config/initializers/safer_initialize.rb`:
24
24
 
25
25
  ```ruby
26
26
  SaferInitialize::Globals.attribute :tenant
27
+
28
+ SaferInitialize.configure do |config|
29
+ config.error_handle = -> (e) { Rails.env.production? ? Bugsnag.notify(e) : raise e } # default: -> (e) { raise e }
30
+ end
27
31
  ```
28
32
 
29
33
  In `app/models/project.rb`:
@@ -70,7 +74,7 @@ In `app/views/projects/index.html.haml`:
70
74
  = project.name
71
75
 
72
76
  - SaferInitialize.with_safe do
73
- - current_tenant.projecst.each do |project|
77
+ - current_tenant.projects.each do |project|
74
78
  = project.name
75
79
  ```
76
80
 
@@ -1,10 +1,21 @@
1
1
  require 'safer_initialize/version'
2
2
  require 'safer_initialize/globals'
3
+ require 'safer_initialize/configuration'
3
4
  require 'safer_initialize/railtie'
4
5
 
5
6
  module SaferInitialize
6
7
  class Error < StandardError; end
7
8
 
9
+ class << self
10
+ def configure
11
+ yield(configuration)
12
+ end
13
+
14
+ def configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+ end
18
+
8
19
  module_function
9
20
 
10
21
  def with_safe(&block)
@@ -8,7 +8,9 @@ module SaferInitialize
8
8
  after_initialize do |object|
9
9
  unless SaferInitialize::Globals.safe?
10
10
  result = filter ? object.send(filter) : object.instance_exec(object, &block)
11
- raise SaferInitialize::Error, message unless result
11
+ unless result
12
+ SaferInitialize.configuration.error_handle.call(SaferInitialize::Error.new(message))
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -0,0 +1,9 @@
1
+ module SaferInitialize
2
+ class Configuration
3
+ attr_accessor :error_handle
4
+
5
+ def initialize
6
+ self.error_handle = -> (e) { raise e }
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module SaferInitialize
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safer_initialize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-16 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,6 +44,7 @@ files:
44
44
  - bin/setup
45
45
  - lib/safer_initialize.rb
46
46
  - lib/safer_initialize/active_record/extensions.rb
47
+ - lib/safer_initialize/configuration.rb
47
48
  - lib/safer_initialize/globals.rb
48
49
  - lib/safer_initialize/railtie.rb
49
50
  - lib/safer_initialize/version.rb