sequel-asterisk-hunter 1.0.1 → 1.1.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: 6807749242bc3d6940d7dc0b90bab947edcd38b0c57970425e4a4344315a08ac
4
- data.tar.gz: 5c1e25f1d3cfd7ec84fa63e3539dd012f5a2d11d23481a42033a1869ebd08a0f
3
+ metadata.gz: 184314bd889776102faf9c036f3bf27971a6c223eb58149a81d4c059dba9abb7
4
+ data.tar.gz: f983c5d3722513396327fcb19881a2a3cbb7b155e5c51670ec2a5f359d9dddec
5
5
  SHA512:
6
- metadata.gz: f328246f6744a3131e9a1e1e004ba2ad3313df9aba5af3569fa6a4956e23720c2b744b60ff89b185f9e8ae13fcfdaf4cbd9c04cd18960d96c9e1fabe2c835bc1
7
- data.tar.gz: 74485357975f0c0ceb8df9ab40027b555bd81923835b534e6d150c5d5a4db61528ec053d046900465374b29329a992fa73dca5d227321af00984a259f13ebd30
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 adds the `Sequel::Dataset#hunt` method, which...
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
- The plugin needs to be initialized by the Sequel extension interface. The simplest way to configure plugin globally is adding this line to the initializer:
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
- But anyway I recommend reading more about [Sequel extensions system](https://github.com/jeremyevans/sequel/blob/master/doc/extensions.rdoc#sequel-extensions).
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
- ## Usage
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
- dataset.hunt
43
+ DB[:my_table].all
44
+ #=> "Find 'SELECT *' in query!"
45
+ #=> [<All your objects and its attributes/columns>]
35
46
  ```
36
47
 
37
- ## Usage examples
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
- ### Hunting 'SELECT * ...'
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
- DB[:my_table].hunt
42
- #=> #<Sequel::YourAdapter::Dataset: "SELECT * FROM \"my_table\"">
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SequelAsteriskHunter
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -5,8 +5,22 @@ require "sequel"
5
5
  module Sequel
6
6
  module Extensions
7
7
  module AsteriskHunter
8
- def hunt(action: :log)
9
- return 'Find it!' if self.inspect.include?('SELECT *')
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.1
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-21 00:00:00.000000000 Z
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: 3.48.0
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: 3.48.0
27
- description: The Sequel extension which allow you to find all your 'SELECT * FROM
28
- ...' queries.
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: '0'
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: The Sequel extension which allow you to find all your 'SELECT * FROM ...'
64
- queries.
63
+ summary: Sequel extension which allow you to do some action when find any 'SELECT
64
+ *' queries.
65
65
  test_files: []