rails_cve 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: 1c029756d626fb174a6de2f71dfdaff1f81d25bd
4
- data.tar.gz: 4f5f4919e99684fdeb384d65db5717c74f686319
3
+ metadata.gz: 2a1bf677ded00c3e9e88026fc83feb366249765e
4
+ data.tar.gz: b345a9512442777e11ac6a9acec5d113c08b5d21
5
5
  SHA512:
6
- metadata.gz: 5d4f17f1c5c038c3f2a04cb161febdb7b15fff2f9429d334a0d04e93c6f297c1f9ee9bb10bd5f653a8f3b1287e4c30bb9edc60f8cfda4454df46cba2ad08670a
7
- data.tar.gz: 43a59a3228c7c6bd8c57f121900b6d2f8c06f4c338da2402971bbafa6ff922872024d508761334997276f2c9766ede125dd934d869630b434cc4fd436517b2b1
6
+ metadata.gz: 7fdbfeaedd6579193406dbe0df27f01cc5c932de77ecbdfb01d3f25b2ef6a9fa6f307ca5374b00c0efcd855f10159d6376d91665dd9bc3cb6965a34a23df3341
7
+ data.tar.gz: 2f0672ff5993e98276fb4466cc49bca8bb95fac5b1449ca13c52c44fce9b4101bf3224514506ee2f135ab8c68aacc64217e7be06a78ee5677facb0eacde17933
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.0.4 (2014-04-28)
2
+
3
+ * enhancements
4
+ * refactoring of search scopes (perform a build disjoint query if multiple
5
+ search fragments given)
6
+ * import task is less noisy when printing progress (format only)
7
+
1
8
  ### 0.0.3 (2014-04-28)
2
9
 
3
10
  * enhancements
data/README.md CHANGED
@@ -80,14 +80,24 @@ RailsCVE::Entry.search_ranked('ruby rails').search_ranked('windows')
80
80
  RailsCVE::Entry.search_ranked('ruby rails & windows')
81
81
  ```
82
82
 
83
+ Both `search_ranked` and `search_plain` accept an array of search fragments,
84
+ which will result in a disjoint query:
85
+
86
+ ```ruby
87
+ RailsCVE::Entry.search_plain('ruby', 'rails').to_sql
88
+ #=> SELECT "rails_cve_entries".*
89
+ # FROM "rails_cve_entries"
90
+ # WHERE to_tsvector('simple', description) @@ (to_tsquery('simple', 'ruby | rails'))
91
+ ```
92
+
83
93
  ## Installation
84
94
 
85
95
  **This engine requires a PostgreSQL database!**
86
96
 
87
- Add `rails-cve` to your Gemfile and run `bundle install`:
97
+ Add `rails_cve` to your Gemfile and run `bundle install`:
88
98
 
89
99
  ```ruby
90
- gem 'rails-cve'
100
+ gem 'rails_cve'
91
101
  ```
92
102
 
93
103
  Then install and run the migrations via
@@ -1,21 +1,27 @@
1
1
  module RailsCVE::Entry::Search
2
2
  extend ActiveSupport::Concern
3
3
 
4
- TS_QUERY = "to_tsvector('simple', description) @@ plainto_tsquery(%{q})"
5
- TS_RANK = "ts_rank(to_tsvector('simple', description), plainto_tsquery(%{q}))"
4
+ TS_QUERY = "to_tsvector('simple', description) @@ (%{q})"
5
+ TS_RANK = "ts_rank(to_tsvector('simple', description), (%{q}))"
6
6
 
7
7
  included do
8
- scope :search_ranked, ->(query){
9
- q = sanitize(query)
10
- rank = "#{TS_RANK} AS rank" % { q: q }
8
+ scope :search_ranked, ->(*query){
9
+ rank = "#{TS_RANK} AS rank" % { q: plainto_tsquery(query) }
11
10
 
12
11
  select("*, #{rank}")
13
12
  .search_plain(query)
14
13
  .order("rank DESC")
15
14
  }
16
15
 
17
- scope :search_plain, ->(query){
18
- where(TS_QUERY % { q: sanitize(query) })
16
+ scope :search_plain, ->(*query){
17
+ where(TS_QUERY % { q: plainto_tsquery(query) })
19
18
  }
20
19
  end
20
+
21
+ module ClassMethods
22
+ def plainto_tsquery(*fragments)
23
+ plain = sanitize fragments.flatten.map(&:strip).join(' | ')
24
+ "to_tsquery('simple', #{plain})"
25
+ end
26
+ end
21
27
  end
@@ -1,3 +1,3 @@
1
1
  module RailsCVE
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -3,10 +3,17 @@ namespace :rails_cve do
3
3
  desc "Seed the database"
4
4
  task seed: :environment do
5
5
  puts '(Re-) Importing CVE list. This could take a while...'
6
+
7
+ last = nil
6
8
  n = RailsCVE::Entry.rebuild_entries! do |entry|
7
- puts "\t#{entry.name} imported"
9
+ if last != entry.year
10
+ last = entry.year
11
+ puts "Imports for #{last}:"
12
+ end
13
+ print "\t#{entry.name.split('-').last}"
8
14
  end
9
- puts "Done! Imported #{n} CVE entries."
15
+
16
+ puts '', "Done! Imported #{n} CVE entries."
10
17
  end
11
18
 
12
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_cve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Menke