strict_templates 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +18 -9
- data/lib/strict_templates/concern.rb +1 -1
- data/lib/strict_templates/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 330ac4e189172743eefe10ad36e7f339041625b6
|
4
|
+
data.tar.gz: d36000298f92b650d15d1d50c57c9fc242f01db3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5706e18d6df56217b877db175302a13379caf0bb1e6caafac19893db176441d7cb18e38f5e96a69c4e4e4a4afa90322cf2cf112cfb916b968fb5839ce0f4648
|
7
|
+
data.tar.gz: 54efbeb76df432aaed43e99732db46b65d9acb8880d71b276a35fe7071da2d82bf414e9d2f4b2d9a70cfb2b1d0d42f1f5b5349908236c7807715ff6fd8a93146
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
# StrictTemplates
|
1
|
+
# StrictTemplates [![Build Status](https://travis-ci.org/kellysutton/strict_templates.svg?branch=master)](https://travis-ci.org/kellysutton/strict_templates)
|
2
2
|
|
3
|
-
A gem for ensuring that database queries do not execute while
|
4
|
-
rendering templates in a Rails application.
|
3
|
+
A gem for ensuring that database queries do not execute while rendering templates in a Rails application.
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
With great power comes great responsibility. ERB is an extremely flexible templating language, but can also . Gems like [`bullet`](https://github.com/flyerhzm/bullet) are great for detecting N+1 queries within an application. But for those of us that want to go the extra mile and **prevent any database access from within a template**, this gem is for you.
|
6
|
+
|
7
|
+
Doing this helps keep all database access centralized to your controller layer.
|
8
|
+
|
9
|
+
Pull Requests welcome to enable other methods of generating responses (RABL, etc.)
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
@@ -16,14 +18,21 @@ group :development, :test do
|
|
16
18
|
end
|
17
19
|
```
|
18
20
|
|
19
|
-
And then
|
21
|
+
And then do your normal:
|
20
22
|
|
21
23
|
$ bundle
|
22
24
|
|
25
|
+
Next, include `StrictTemplates::Concern` in all controllers you wish to prevent database queries while rendering. If it's a new app, you should include it in your `ApplicationController`, e.g.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class ApplicationController < ActionController::Base
|
29
|
+
include StrictTemplates::Concern
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
23
33
|
## Usage
|
24
34
|
|
25
|
-
Errors will be raised whenever a request issues a SQL statement from
|
26
|
-
within a template.
|
35
|
+
Errors will be raised whenever a request issues a SQL statement from within a template.
|
27
36
|
|
28
37
|
## Development
|
29
38
|
|
@@ -33,7 +42,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
33
42
|
|
34
43
|
## Contributing
|
35
44
|
|
36
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kellysutton/strict_templates. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
46
|
|
38
47
|
|
39
48
|
## License
|
@@ -10,7 +10,7 @@ module StrictTemplates
|
|
10
10
|
def render(*args, &block)
|
11
11
|
callback = lambda do |name, start, finish, id, payload|
|
12
12
|
if !should_ignore_sql_statement?(payload[:name])
|
13
|
-
raise
|
13
|
+
raise SQLPerformedWithinTemplateError.new("A SQL request was issued within the template: \n #{payload[:sql]}")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|