sequel-asterisk-hunter 1.0.1 → 1.1.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 +4 -4
- data/README.md +33 -9
- data/lib/sequel-asterisk-hunter/version.rb +1 -1
- data/lib/sequel/extensions/asterisk_hunter.rb +16 -2
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 184314bd889776102faf9c036f3bf27971a6c223eb58149a81d4c059dba9abb7
|
4
|
+
data.tar.gz: f983c5d3722513396327fcb19881a2a3cbb7b155e5c51670ec2a5f359d9dddec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad5a7cf4369c55267de29faf95b522fb0b7c337d57c38a1d166dab94898a8660606b151b66c2823e8692c45b8a7f3276ba21509ef7efe46fcd52935d2582acf8
|
7
|
+
data.tar.gz: 56a829e908a4ae83021d79499af11281ef7b18b6b194d48b36197bb95f321e3ce29bd0de6ce97f4ab51de8862d9a379f62d3bab5859171a715ec4d00aef867ad
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SequelAsteriskHunter
|
2
2
|
|
3
|
-
This extension
|
3
|
+
This extension hooks into `Sequel::Dataset#all` method, doing some predefined action when an `SELECT *` statement is found.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,7 +16,9 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install sequel-asterisk-hunter
|
18
18
|
|
19
|
-
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The extension needs to be initialized by the Sequel extension interface. The simplest way to configure it globally is adding this line to the initializer:
|
20
22
|
|
21
23
|
```ruby
|
22
24
|
Sequel.extension :asterisk_hunter
|
@@ -26,20 +28,42 @@ or
|
|
26
28
|
Sequel::Database.extension :asterisk_hunter
|
27
29
|
```
|
28
30
|
|
29
|
-
|
31
|
+
However, if you are using any framework (like Rails) where your Sequel::Database instance already exists, you should use `DB.extension :asterisk_hunter`, where `DB` is a reference to your Sequel::Database, like this:
|
30
32
|
|
31
|
-
|
33
|
+
```ruby
|
34
|
+
Sequel::Model.db.extension :asterisk_hunter
|
35
|
+
```
|
36
|
+
|
37
|
+
You could define an action to be executed when any `SELECT *` statement is found. It must be any callable object.
|
32
38
|
|
39
|
+
### Examples
|
40
|
+
|
41
|
+
With the default action:
|
33
42
|
```ruby
|
34
|
-
|
43
|
+
DB[:my_table].all
|
44
|
+
#=> "Find 'SELECT *' in query!"
|
45
|
+
#=> [<All your objects and its attributes/columns>]
|
35
46
|
```
|
36
47
|
|
37
|
-
|
48
|
+
With some custom actions defined:
|
49
|
+
- Raising an error:
|
50
|
+
```ruby
|
51
|
+
action = -> { raise StandardError, "Find 'SELECT *' in query!" }
|
52
|
+
Sequel::Extensions::AsteriskHunter.define_action(action)
|
38
53
|
|
39
|
-
|
54
|
+
DB[:my_table].all
|
55
|
+
#=> StandardError("Find 'SELECT *' in query!")
|
56
|
+
# (Your query is not executed...)
|
57
|
+
```
|
58
|
+
|
59
|
+
- Logging:
|
40
60
|
```ruby
|
41
|
-
|
42
|
-
|
61
|
+
action = -> { Rails.logger.warn("Find 'SELECT *' in query!") }
|
62
|
+
Sequel::Extensions::AsteriskHunter.define_action(action)
|
63
|
+
|
64
|
+
DB[:my_table].all
|
65
|
+
#=> "Find 'SELECT *' in query!"
|
66
|
+
#=> [<All your objects and its attributes/columns>]
|
43
67
|
```
|
44
68
|
|
45
69
|
## Contributing
|
@@ -5,8 +5,22 @@ require "sequel"
|
|
5
5
|
module Sequel
|
6
6
|
module Extensions
|
7
7
|
module AsteriskHunter
|
8
|
-
|
9
|
-
|
8
|
+
@@action = -> { puts "Find 'SELECT *' in query!" }
|
9
|
+
|
10
|
+
def all
|
11
|
+
hunt
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.define_action(action)
|
16
|
+
raise TypeError, 'Action parameter must be a callable object!' unless action.respond_to?(:call)
|
17
|
+
@@action = action
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def hunt
|
23
|
+
@@action.call if self.inspect.include?('SELECT *')
|
10
24
|
self
|
11
25
|
end
|
12
26
|
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-asterisk-hunter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danilo Barion Nogueira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '5.10'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
description:
|
28
|
-
|
26
|
+
version: '5.10'
|
27
|
+
description: This extension hooks into `Sequel::Dataset#all` method, doing some predefined
|
28
|
+
action when an `SELECT *` statement is found.
|
29
29
|
email: danilo.barion@gmail.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
@@ -47,9 +47,9 @@ require_paths:
|
|
47
47
|
- lib
|
48
48
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
|
-
- - "
|
50
|
+
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '2.5'
|
53
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
@@ -60,6 +60,6 @@ rubyforge_project:
|
|
60
60
|
rubygems_version: 2.7.6
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
|
-
summary:
|
64
|
-
queries.
|
63
|
+
summary: Sequel extension which allow you to do some action when find any 'SELECT
|
64
|
+
*' queries.
|
65
65
|
test_files: []
|