strict_templates 0.1.1 → 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
  SHA1:
3
- metadata.gz: 330ac4e189172743eefe10ad36e7f339041625b6
4
- data.tar.gz: d36000298f92b650d15d1d50c57c9fc242f01db3
3
+ metadata.gz: b9c1f18b685f0f9975dcf921d774f192b16f71c2
4
+ data.tar.gz: b910943adeaa424de58c108e8c2e7bd2cb66b0c6
5
5
  SHA512:
6
- metadata.gz: a5706e18d6df56217b877db175302a13379caf0bb1e6caafac19893db176441d7cb18e38f5e96a69c4e4e4a4afa90322cf2cf112cfb916b968fb5839ce0f4648
7
- data.tar.gz: 54efbeb76df432aaed43e99732db46b65d9acb8880d71b276a35fe7071da2d82bf414e9d2f4b2d9a70cfb2b1d0d42f1f5b5349908236c7807715ff6fd8a93146
6
+ metadata.gz: 80fa519dffc4e4e109b867a0bd0c30c4d405bfe442f6bc381cdf299a2722b353963b60f349cd1f392021c28e6c51c85be15abfad05baf580e28767904623b4e6
7
+ data.tar.gz: c34498088245e2d7ea649c7e95d5aa9500207b8503e39628efcbd71bdcadd441b7ed3a596adb95af0be27ee7a683a31eba1b98b6e6dd9c19128ed29d61f90539
data/README.md CHANGED
@@ -34,6 +34,22 @@ end
34
34
 
35
35
  Errors will be raised whenever a request issues a SQL statement from within a template.
36
36
 
37
+ It's recommended that you do not raise exceptions within your production or production-like environments. Exceptions can be disabled wholesale with the following Rails config flag:
38
+
39
+ ```ruby
40
+ Rails.application.configure do
41
+ config.strict_templates.raise_on_queries = false
42
+ end
43
+ ```
44
+
45
+ Alternatively, you can specify a custom error handler to log the errors or do something else interesting with them:
46
+
47
+ ```ruby
48
+ Rails.application.configure do
49
+ config.strict_templates.error_handler = ->(error) { Bugsnag.report(error) }
50
+ end
51
+ ```
52
+
37
53
  ## Development
38
54
 
39
55
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -8,9 +8,17 @@ module StrictTemplates
8
8
 
9
9
  included do
10
10
  def render(*args, &block)
11
+ if !should_raise_on_queries?
12
+ return super
13
+ end
14
+
11
15
  callback = lambda do |name, start, finish, id, payload|
12
16
  if !should_ignore_sql_statement?(payload[:name])
13
- raise SQLPerformedWithinTemplateError.new("A SQL request was issued within the template: \n #{payload[:sql]}")
17
+ if has_custom_error_handler?
18
+ config.strict_templates.error_handler.call(payload)
19
+ else
20
+ raise SQLPerformedWithinTemplateError.new("A SQL request was issued within the template: \n #{payload[:sql]}")
21
+ end
14
22
  end
15
23
  end
16
24
 
@@ -24,6 +32,18 @@ module StrictTemplates
24
32
  def should_ignore_sql_statement?(name)
25
33
  name == 'SCHEMA' || name == 'ActiveRecord::SchemaMigration Load'
26
34
  end
35
+
36
+ def config
37
+ Rails.configuration if defined?(Rails)
38
+ end
39
+
40
+ def should_raise_on_queries?
41
+ config&.strict_templates&.raise_on_queries != false
42
+ end
43
+
44
+ def has_custom_error_handler?
45
+ config&.strict_templates&.error_handler
46
+ end
27
47
  end
28
48
  end
29
49
  end
@@ -1,3 +1,3 @@
1
1
  module StrictTemplates
2
- VERSION = '0.1.1'
3
- end
2
+ VERSION = '0.2.0'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strict_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Sutton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-31 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport