mincer 0.1.2 → 0.2.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/Gemfile +2 -1
  4. data/README.md +111 -64
  5. data/lib/mincer/action_view/sort_helper.rb +7 -7
  6. data/lib/mincer/base.rb +1 -1
  7. data/lib/mincer/config.rb +29 -0
  8. data/lib/mincer/core_ext/string.rb +5 -0
  9. data/lib/mincer/processors/cache_digest/processor.rb +54 -0
  10. data/lib/mincer/processors/helpers.rb +15 -0
  11. data/lib/mincer/processors/pagination/processor.rb +63 -0
  12. data/lib/mincer/processors/pg_json_dumper/processor.rb +69 -0
  13. data/lib/mincer/processors/pg_search/processor.rb +148 -0
  14. data/lib/mincer/processors/pg_search/sanitizer.rb +61 -0
  15. data/lib/mincer/processors/pg_search/search_engines/array.rb +41 -0
  16. data/lib/mincer/processors/pg_search/search_engines/base.rb +56 -0
  17. data/lib/mincer/processors/pg_search/search_engines/fulltext.rb +58 -0
  18. data/lib/mincer/processors/pg_search/search_engines/trigram.rb +41 -0
  19. data/lib/mincer/processors/pg_search/search_statement.rb +31 -0
  20. data/lib/mincer/processors/sorting/processor.rb +113 -0
  21. data/lib/mincer/version.rb +1 -1
  22. data/lib/mincer.rb +31 -31
  23. data/mincer.gemspec +0 -2
  24. data/spec/lib/mincer/action_view/sort_helper_spec.rb +11 -0
  25. data/spec/lib/mincer/base_spec.rb +15 -0
  26. data/spec/lib/mincer/config_spec.rb +7 -0
  27. data/spec/lib/{processors/cache_digest_spec.rb → mincer/processors/cache_digest/processor_spec.rb} +2 -9
  28. data/spec/lib/{processors/paginate_spec.rb → mincer/processors/pagination/processor_spec.rb} +43 -17
  29. data/spec/lib/{processors/pg_json_dumper_spec.rb → mincer/processors/pg_json_dumper/processor_spec.rb} +2 -6
  30. data/spec/lib/mincer/processors/pg_search/processor_spec.rb +268 -0
  31. data/spec/lib/mincer/processors/pg_search/sanitizer_spec.rb +38 -0
  32. data/spec/lib/mincer/processors/pg_search/search_engines/array_spec.rb +83 -0
  33. data/spec/lib/mincer/processors/pg_search/search_engines/fulltext_spec.rb +101 -0
  34. data/spec/lib/mincer/processors/pg_search/search_engines/trigram_spec.rb +91 -0
  35. data/spec/lib/mincer/processors/sorting/processor_spec.rb +181 -0
  36. data/spec/mincer_config.rb +38 -0
  37. data/spec/spec_helper.rb +40 -4
  38. data/spec/support/postgres_adapter.rb +12 -3
  39. data/spec/support/sqlite3_adapter.rb +3 -0
  40. metadata +42 -45
  41. data/lib/mincer/processors/cache_digest.rb +0 -50
  42. data/lib/mincer/processors/paginate.rb +0 -41
  43. data/lib/mincer/processors/pg_json_dumper.rb +0 -51
  44. data/lib/mincer/processors/search.rb +0 -34
  45. data/lib/mincer/processors/sort.rb +0 -59
  46. data/spec/lib/processors/search_spec.rb +0 -77
  47. data/spec/lib/processors/sort_spec.rb +0 -77
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::Mincer::PgSearch::SearchEngines::Trigram do
4
+ before do
5
+ setup_postgres_table
6
+ end
7
+ subject(:search_engine_class) { ::Mincer::PgSearch::SearchEngines::Trigram }
8
+ let(:search_statement_class) { ::Mincer::Processors::PgSearch::SearchStatement }
9
+
10
+ describe '.search_engine_statements' do
11
+ context 'when 2 columns' do
12
+ it 'stores them in instance variable hash under :or key' do
13
+ search_statement1 = search_statement_class.new(['"records"."text"'], engines: [:trigram])
14
+ search_statement2 = search_statement_class.new(['"records"."text2"'], engines: [:trigram])
15
+ search_engine = search_engine_class.new('search', [search_statement1, search_statement2])
16
+ search_engine.send(:search_engine_statements).should include(search_statement1)
17
+ search_engine.send(:search_engine_statements).should include(search_statement2)
18
+ end
19
+ end
20
+
21
+ it 'ignores other engines' do
22
+ search_statement1 = search_statement_class.new(['"records"."text"'])
23
+ search_statement2 = search_statement_class.new(['"records"."text2"'], engines: [:array])
24
+ search_engine = search_engine_class.new('search', [search_statement1, search_statement2])
25
+ search_engine.send(:search_engine_statements).should == []
26
+ search_engine.send(:search_engine_statements).should == []
27
+ end
28
+ end
29
+
30
+ describe '.conditions' do
31
+ it 'generates search condition with one column, one term and no options' do
32
+ search_statement1 = search_statement_class.new(['"records"."text"'], engines: [:trigram])
33
+ search_engine = search_engine_class.new({ pattern: 'search' }, [search_statement1])
34
+ search_engine.conditions.to_sql.should == %{((similarity("records"."text", 'search') >= 0.3))}
35
+ end
36
+
37
+ it 'generates search condition with one column, one term and "threshold" option set to 0.5' do
38
+ search_statement1 = search_statement_class.new(['"records"."text"'], engines: [:trigram], threshold: 0.5)
39
+ search_engine = search_engine_class.new({ pattern: 'search' }, [search_statement1])
40
+ search_engine.conditions.to_sql.should == %{((similarity("records"."text", 'search') >= 0.5))}
41
+ end
42
+
43
+ it 'generates search condition with two columns, one term and no options' do
44
+ search_statement1 = search_statement_class.new(['"records"."text"', '"records"."text2"'], engines: [:trigram])
45
+ search_engine = search_engine_class.new({ pattern: 'search' }, [search_statement1])
46
+ search_engine.conditions.to_sql.should == %{((similarity("records"."text", 'search') >= 0.3) OR (similarity("records"."text2", 'search') >= 0.3))}
47
+ end
48
+
49
+ it 'generates search condition with two columns, two terms and no options' do
50
+ search_statement1 = search_statement_class.new(['"records"."text"', '"records"."text2"'], engines: [:trigram])
51
+ search_engine = search_engine_class.new({ pattern: 'search word' }, [search_statement1])
52
+ search_engine.conditions.to_sql.should == %{((similarity("records"."text", 'search word') >= 0.3) OR (similarity("records"."text2", 'search word') >= 0.3))}
53
+ end
54
+
55
+ it 'generates search condition with two columns, two terms and option "ignore_accent" set to true ' do
56
+ search_statement1 = search_statement_class.new(['"records"."text"', '"records"."text2"'], engines: [:trigram], ignore_accent: true)
57
+ search_engine = search_engine_class.new({ pattern: 'search word' }, [search_statement1])
58
+ search_engine.conditions.to_sql.should == %{((similarity(unaccent("records"."text"), unaccent('search word')) >= 0.3) OR (similarity(unaccent("records"."text2"), unaccent('search word')) >= 0.3))}
59
+ end
60
+
61
+ it 'generates search condition with one column, one term, two statements and no options' do
62
+ search_statement1 = search_statement_class.new(['"records"."text"'], engines: [:trigram])
63
+ search_statement2 = search_statement_class.new(['"records"."text2"'], engines: [:trigram])
64
+ search_engine = search_engine_class.new({ pattern: 'search' }, [search_statement1, search_statement2])
65
+ search_engine.conditions.to_sql.should == %{((similarity("records"."text", 'search') >= 0.3) OR (similarity("records"."text2", 'search') >= 0.3))}
66
+ end
67
+
68
+ it 'generates search condition with one column, one term, two statements and "param_name" option set to "s"' do
69
+ search_statement1 = search_statement_class.new(['"records"."text"'], engines: [:trigram])
70
+ search_statement2 = search_statement_class.new(['"records"."text2"'], engines: [:trigram], param_name: 's')
71
+ search_engine = search_engine_class.new({ pattern: 'search', s: 'word' }, [search_statement1, search_statement2])
72
+ search_engine.conditions.to_sql.should == %{((similarity("records"."text", 'search') >= 0.3) OR (similarity("records"."text2", 'word') >= 0.3))}
73
+ end
74
+
75
+ end
76
+
77
+ describe '.rank' do
78
+ it 'generates rank with one column, one term and no options' do
79
+ search_statement1 = search_statement_class.new(['"records"."text"'], engines: [:trigram])
80
+ search_engine = search_engine_class.new({ pattern: 'search' }, [search_statement1])
81
+ search_engine.rank.to_sql.should == %{(similarity("records"."text", 'search'))}
82
+ end
83
+
84
+ it 'generates rank with two columns, one term and no options' do
85
+ search_statement1 = search_statement_class.new(['"records"."text"', '"records"."text2"'], engines: [:trigram])
86
+ search_engine = search_engine_class.new({ pattern: 'search' }, [search_statement1])
87
+ search_engine.rank.to_sql.should == %{(similarity("records"."text", 'search') + similarity("records"."text2", 'search'))}
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,181 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::Mincer::Processors::Sorting::Processor do
4
+ before do
5
+ setup_basic_sqlite3_table
6
+ %w{a c b}.each { |i| ActiveRecordModel.create(text: i) }
7
+ end
8
+
9
+ describe 'config' do
10
+ it 'defines method with pg_options' do
11
+ subject = Class.new(Mincer::Base) do
12
+ pg_search [{ columns: %w{"active_record_models"."tags" }, engines: [:array] }]
13
+ end
14
+ query = subject.new(ActiveRecordModel)
15
+ query.send(:pg_search_params).should == [{ columns: %w{"active_record_models"."tags" }, engines: [:array] }]
16
+ end
17
+ end
18
+
19
+ describe 'sorting with basic model without any Mincer::Base configuration' do
20
+ subject(:model) do
21
+ Class.new(Mincer::Base)
22
+ end
23
+
24
+ it 'sorts by valid attribute and order when they are passed in args' do
25
+ query = subject.new(ActiveRecordModel, { 'sort' => 'text', 'order' => 'DESC' })
26
+ query.to_a.map(&:text).should == %w{c b a}
27
+ end
28
+
29
+ it 'sorts by default attributes(id) abd order(ASC) when nothing passed to args' do
30
+ query = subject.new(ActiveRecordModel)
31
+ query.to_a.map(&:text).should == %w{a c b}
32
+ end
33
+
34
+ it 'ignores sort attribute that is not allowed and use default(id)' do
35
+ query = subject.new(ActiveRecordModel, { 'sort' => 'text2', 'order' => 'DESC' })
36
+ query.to_a.map(&:text).should == %w{b c a}
37
+ end
38
+
39
+ it 'ignores order that is not allowed and use default(ASC)' do
40
+ query = subject.new(ActiveRecordModel, { 'sort' => 'text', 'order' => 'DESCA' })
41
+ query.to_a.map(&:text).should == %w{a b c}
42
+ end
43
+ end
44
+
45
+
46
+ describe 'sorting with basic model with defaults changed' do
47
+ it 'sorts by default attributes(id) abd order(ASC) when nothing passed to args' do
48
+ subject = Class.new(Mincer::Base) do
49
+ def default_sort_attribute
50
+ 'text'
51
+ end
52
+ def default_sort_order
53
+ 'DESC'
54
+ end
55
+ end
56
+ query = subject.new(ActiveRecordModel)
57
+ query.to_a.map(&:text).should == %w{c b a}
58
+ end
59
+ end
60
+
61
+ describe 'sorting with basic model with defaults changed' do
62
+ it 'sorts by default attributes(id) abd order(ASC) when nothing passed to args' do
63
+ subject = Class.new(Mincer::Base) do
64
+ def allowed_sort_attributes
65
+ ['id']
66
+ end
67
+ end
68
+ query = subject.new(ActiveRecordModel, { 'sort' => 'text' })
69
+ query.to_a.map(&:text).should == %w{a c b}
70
+ end
71
+ end
72
+
73
+
74
+ describe 'sorting when basic model has disabled sorting' do
75
+ it 'sorts by default attributes(id) abd order(ASC) when nothing passed to args' do
76
+ subject = Class.new(Mincer::Base) do
77
+ skip_sorting!
78
+ end
79
+ query = subject.new(ActiveRecordModel, { 'sort' => 'text' })
80
+ query.to_a.map(&:text).should == %w{a c b}
81
+ end
82
+ end
83
+
84
+
85
+ describe 'configuration of sorting' do
86
+ before do
87
+ Mincer.config.instance_variable_set('@sorting', nil)
88
+ end
89
+
90
+ describe 'sort_param_name' do
91
+ it 'uses "sort" as default value for sort_param_name' do
92
+ Mincer.config.sorting.sort_param_name.should == :sort
93
+ end
94
+
95
+ it 'sets sort_param_name string' do
96
+ Mincer.configure do |config|
97
+ config.sorting do |search|
98
+ search.sort_param_name = 's'
99
+ end
100
+ end
101
+ Mincer.config.sorting.sort_param_name.should == 's'
102
+ end
103
+ end
104
+
105
+ describe 'sort_attribute' do
106
+ it 'uses :per_page as default value for sort_attribute' do
107
+ Mincer.config.sorting.sort_attribute.should == :id
108
+ end
109
+
110
+ it 'sets sort_attribute string' do
111
+ Mincer.configure do |config|
112
+ config.sorting do |search|
113
+ search.sort_attribute = 's'
114
+ end
115
+ end
116
+ Mincer.config.sorting.sort_attribute.should == 's'
117
+ end
118
+ end
119
+
120
+ describe 'order_param_name' do
121
+ it 'uses "order" as default value for order_param_name' do
122
+ Mincer.config.sorting.order_param_name.should == :order
123
+ end
124
+
125
+ it 'sets order_param_name string' do
126
+ Mincer.configure do |config|
127
+ config.sorting do |search|
128
+ search.order_param_name = 's'
129
+ end
130
+ end
131
+ Mincer.config.sorting.order_param_name.should == 's'
132
+ end
133
+ end
134
+
135
+ describe 'order_attribute' do
136
+ it 'uses :asc as default value for order_attribute' do
137
+ Mincer.config.sorting.order_attribute.should == :asc
138
+ end
139
+
140
+ it 'sets order_attribute string' do
141
+ Mincer.configure do |config|
142
+ config.sorting do |search|
143
+ search.order_attribute = 's'
144
+ end
145
+ end
146
+ Mincer.config.sorting.order_attribute.should == 's'
147
+ end
148
+ end
149
+
150
+ describe 'asc_class' do
151
+ it 'uses "sorted order_down" as default value for asc_class' do
152
+ Mincer.config.sorting.asc_class.should == 'sorted order_down'
153
+ end
154
+
155
+ it 'sets asc_class string' do
156
+ Mincer.configure do |config|
157
+ config.sorting do |search|
158
+ search.asc_class = 's'
159
+ end
160
+ end
161
+ Mincer.config.sorting.asc_class.should == 's'
162
+ end
163
+ end
164
+
165
+ describe 'desc_class' do
166
+ it 'uses "sorted order_up" as default value for desc_class' do
167
+ Mincer.config.sorting.desc_class.should == 'sorted order_up'
168
+ end
169
+
170
+ it 'sets desc_class string' do
171
+ Mincer.configure do |config|
172
+ config.sorting do |search|
173
+ search.desc_class = 's'
174
+ end
175
+ end
176
+ Mincer.config.sorting.desc_class.should == 's'
177
+ end
178
+ end
179
+ end
180
+
181
+ end
@@ -0,0 +1,38 @@
1
+ Mincer.configure do |config|
2
+ config.pg_search do |search|
3
+ #
4
+ search.param_name = 'pattern'
5
+
6
+ # Fulltext search engine defaults. http://www.postgresql.org/docs/9.3/static/textsearch.html
7
+ # Available options:
8
+ # ignore_accent - If set to true will ignore accents. Ex.: "Cüåñtô" == "Cuanto". More information: http://www.postgresql.org/docs/current/static/unaccent.html
9
+ # any_word - If set to true, search will return return all items containing any word in the search terms.
10
+ # dictionary - For more information http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html
11
+ search.fulltext_engine = { ignore_accent: true, any_word: false, dictionary: :simple, ignore_case: false }
12
+
13
+ # Trigram search engine defaults. http://www.postgresql.org/docs/current/static/pgtrgm.html
14
+ # Available options:
15
+ # ignore_accent - If set to true will ignore accents. Ex.: "Cüåñtô" == "Cuanto". More information: http://www.postgresql.org/docs/current/static/unaccent.html
16
+ # threshold - # http://www.postgresql.org/docs/current/static/pgtrgm.html
17
+ search.trigram_engine = { ignore_accent: true, treshhold: 0.3 }
18
+
19
+ # Array search engine defaults. http://www.postgresql.org/docs/current/static/functions-array.html
20
+ # Available options:
21
+ # ignore_accent - If set to true will ignore accents. Ex.: "Cüåñtô" == "Cuanto". More information: http://www.postgresql.org/docs/current/static/unaccent.html
22
+ # any_word - If set to true, search will return return all items containing any word in the search terms.
23
+ search.array_engine = { ignore_accent: true, any_word: true }
24
+
25
+ search.engines = [Mincer::PgSearch::SearchEngines::Fulltext, Mincer::PgSearch::SearchEngines::Array, Mincer::PgSearch::SearchEngines::Trigram]
26
+ end
27
+
28
+ config.pagination do |pagination|
29
+ pagination.page_param_name = 'page'
30
+ pagination.per_page_param_name = 'per_page'
31
+ end
32
+
33
+ config.sorting do |sorting|
34
+ sorting.attribute_param_name = 'sort'
35
+ sorting.order_param_name = 'order'
36
+ end
37
+
38
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,21 +4,34 @@
4
4
  # loaded once.
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
- require 'codeclimate-test-reporter'
8
- CodeClimate::TestReporter.start
7
+
8
+ # Disabling logging
9
+ #$stderr = StringIO.new
10
+
9
11
  require 'simplecov'
10
12
  SimpleCov.start do
11
13
  add_filter 'spec'
12
14
  add_group 'Processors', '/lib/mincer/processors'
13
15
  add_group 'ActionView', '/lib/mincer/action_view'
14
16
  end
17
+
18
+ if ENV['TRAVIS']
19
+ require 'coveralls'
20
+ Coveralls.wear!
21
+ end
22
+
15
23
  require 'rubygems'
16
24
  require 'bundler/setup'
25
+ require 'action_view'
17
26
  require 'active_record'
27
+ require 'active_support'
28
+
29
+ require 'will_paginate'
30
+ #require 'will_paginate/active_record'
31
+
18
32
  require 'kaminari'
19
33
  Kaminari::Hooks.init
20
- require 'textacular'
21
- ActiveRecord::Base.extend(Textacular)
34
+
22
35
  require 'mincer'
23
36
 
24
37
  require 'support/postgres_adapter'
@@ -33,6 +46,29 @@ RSpec.configure do |config|
33
46
  ActiveRecord::Base.clear_active_connections!
34
47
  end
35
48
 
49
+ config.before do
50
+ # Restoring defaults
51
+ Mincer.configure do |config|
52
+ config.pg_search do |search|
53
+ search.param_name = 'pattern'
54
+ search.fulltext_engine = { ignore_accent: true, any_word: false, dictionary: :simple, ignore_case: false }
55
+ search.trigram_engine = { ignore_accent: true, threshold: 0.3 }
56
+ search.array_engine = { ignore_accent: true, any_word: true }
57
+ search.engines = [Mincer::PgSearch::SearchEngines::Fulltext, Mincer::PgSearch::SearchEngines::Array, Mincer::PgSearch::SearchEngines::Trigram]
58
+ end
59
+ config.pagination do |paginaition|
60
+ paginaition.page_param_name = :page
61
+ paginaition.per_page_param_name = :per_page
62
+ end
63
+ config.sorting do |paginaition|
64
+ paginaition.sort_param_name = :sort
65
+ paginaition.sort_attribute = :id
66
+ paginaition.order_param_name = :order
67
+ paginaition.order_attribute = :asc
68
+ end
69
+ end
70
+ end
71
+
36
72
  # Run specs in random order to surface order dependencies. If you find an
37
73
  # order dependency and want to debug it, you can fix the order by providing
38
74
  # the seed, which is printed after each run.
@@ -1,4 +1,6 @@
1
- def setup_basic_postgres_table
1
+ class ActiveRecordModel < ActiveRecord::Base
2
+ end
3
+ def setup_postgres_table(columns = [['id', 'SERIAL PRIMARY KEY'], ['text', 'TEXT']])
2
4
  config = if ENV['TRAVIS']
3
5
  { adapter: :postgresql, database: 'mincer', username: 'postgres' }
4
6
  else
@@ -7,5 +9,12 @@ def setup_basic_postgres_table
7
9
 
8
10
  ActiveRecord::Base.establish_connection(config)
9
11
  ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS active_record_models')
10
- ActiveRecord::Base.connection.execute('CREATE TABLE IF NOT EXISTS active_record_models (id SERIAL PRIMARY KEY, text TEXT)')
11
- end
12
+
13
+ columns_sql = columns.map {|column| column.join(' ') }.join(',')
14
+ ActiveRecord::Base.connection.execute("CREATE TABLE IF NOT EXISTS active_record_models (#{columns_sql})")
15
+ ActiveRecord::Base.connection.execute('CREATE EXTENSION IF NOT EXISTS unaccent')
16
+ ActiveRecord::Base.connection.execute('CREATE EXTENSION IF NOT EXISTS pgcrypto')
17
+ ActiveRecordModel.reset_column_information
18
+ end
19
+
20
+
@@ -1,4 +1,7 @@
1
+ class ActiveRecordModel < ActiveRecord::Base
2
+ end
1
3
  def setup_basic_sqlite3_table
2
4
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
3
5
  ActiveRecord::Base.connection.execute('CREATE TABLE active_record_models (id INTEGER PRIMARY KEY, text STRING)')
6
+ ActiveRecordModel.reset_column_information
4
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mincer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Krasinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 2.14.1
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: 2.14.1
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: pg
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +108,6 @@ dependencies:
122
108
  - - '>='
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: textacular
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '>='
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
111
  description: Add pagination, cache_digest, order, json generation with postgres, simple
140
112
  search support to all your queries
141
113
  email:
@@ -153,19 +125,36 @@ files:
153
125
  - lib/mincer.rb
154
126
  - lib/mincer/action_view/sort_helper.rb
155
127
  - lib/mincer/base.rb
156
- - lib/mincer/processors/cache_digest.rb
157
- - lib/mincer/processors/paginate.rb
158
- - lib/mincer/processors/pg_json_dumper.rb
159
- - lib/mincer/processors/search.rb
160
- - lib/mincer/processors/sort.rb
128
+ - lib/mincer/config.rb
129
+ - lib/mincer/core_ext/string.rb
130
+ - lib/mincer/processors/cache_digest/processor.rb
131
+ - lib/mincer/processors/helpers.rb
132
+ - lib/mincer/processors/pagination/processor.rb
133
+ - lib/mincer/processors/pg_json_dumper/processor.rb
134
+ - lib/mincer/processors/pg_search/processor.rb
135
+ - lib/mincer/processors/pg_search/sanitizer.rb
136
+ - lib/mincer/processors/pg_search/search_engines/array.rb
137
+ - lib/mincer/processors/pg_search/search_engines/base.rb
138
+ - lib/mincer/processors/pg_search/search_engines/fulltext.rb
139
+ - lib/mincer/processors/pg_search/search_engines/trigram.rb
140
+ - lib/mincer/processors/pg_search/search_statement.rb
141
+ - lib/mincer/processors/sorting/processor.rb
161
142
  - lib/mincer/version.rb
162
143
  - mincer.gemspec
163
144
  - spec/database.yml.example
164
- - spec/lib/processors/cache_digest_spec.rb
165
- - spec/lib/processors/paginate_spec.rb
166
- - spec/lib/processors/pg_json_dumper_spec.rb
167
- - spec/lib/processors/search_spec.rb
168
- - spec/lib/processors/sort_spec.rb
145
+ - spec/lib/mincer/action_view/sort_helper_spec.rb
146
+ - spec/lib/mincer/base_spec.rb
147
+ - spec/lib/mincer/config_spec.rb
148
+ - spec/lib/mincer/processors/cache_digest/processor_spec.rb
149
+ - spec/lib/mincer/processors/pagination/processor_spec.rb
150
+ - spec/lib/mincer/processors/pg_json_dumper/processor_spec.rb
151
+ - spec/lib/mincer/processors/pg_search/processor_spec.rb
152
+ - spec/lib/mincer/processors/pg_search/sanitizer_spec.rb
153
+ - spec/lib/mincer/processors/pg_search/search_engines/array_spec.rb
154
+ - spec/lib/mincer/processors/pg_search/search_engines/fulltext_spec.rb
155
+ - spec/lib/mincer/processors/pg_search/search_engines/trigram_spec.rb
156
+ - spec/lib/mincer/processors/sorting/processor_spec.rb
157
+ - spec/mincer_config.rb
169
158
  - spec/spec_helper.rb
170
159
  - spec/support/postgres_adapter.rb
171
160
  - spec/support/sqlite3_adapter.rb
@@ -196,11 +185,19 @@ summary: ActiveRecord::Relation wrapper for pagination, order, json, search, cac
196
185
  support
197
186
  test_files:
198
187
  - spec/database.yml.example
199
- - spec/lib/processors/cache_digest_spec.rb
200
- - spec/lib/processors/paginate_spec.rb
201
- - spec/lib/processors/pg_json_dumper_spec.rb
202
- - spec/lib/processors/search_spec.rb
203
- - spec/lib/processors/sort_spec.rb
188
+ - spec/lib/mincer/action_view/sort_helper_spec.rb
189
+ - spec/lib/mincer/base_spec.rb
190
+ - spec/lib/mincer/config_spec.rb
191
+ - spec/lib/mincer/processors/cache_digest/processor_spec.rb
192
+ - spec/lib/mincer/processors/pagination/processor_spec.rb
193
+ - spec/lib/mincer/processors/pg_json_dumper/processor_spec.rb
194
+ - spec/lib/mincer/processors/pg_search/processor_spec.rb
195
+ - spec/lib/mincer/processors/pg_search/sanitizer_spec.rb
196
+ - spec/lib/mincer/processors/pg_search/search_engines/array_spec.rb
197
+ - spec/lib/mincer/processors/pg_search/search_engines/fulltext_spec.rb
198
+ - spec/lib/mincer/processors/pg_search/search_engines/trigram_spec.rb
199
+ - spec/lib/mincer/processors/sorting/processor_spec.rb
200
+ - spec/mincer_config.rb
204
201
  - spec/spec_helper.rb
205
202
  - spec/support/postgres_adapter.rb
206
203
  - spec/support/sqlite3_adapter.rb
@@ -1,50 +0,0 @@
1
- module Mincer
2
- module Processors
3
- class CacheDigest
4
-
5
- def initialize(mincer)
6
- @mincer, @args, @relation = mincer, mincer.args, mincer.relation
7
- end
8
-
9
- def apply
10
- @relation
11
- end
12
-
13
- def digest
14
- Mincer.connection.execute(digest_sql).first.values.first
15
- end
16
-
17
- private
18
-
19
- def digest_sql
20
- <<-SQL
21
- SELECT digest(#{digest_columns_as_sql}, 'md5') as digest
22
- FROM (#{@relation.connection.unprepared_statement { @relation.to_sql }}) as digest_q
23
- SQL
24
- end
25
-
26
- def digest_columns_as_sql
27
- @mincer.class.digest_columns.map { |column| "string_agg(digest_q.#{column}::text, '')" }.join(' || ')
28
- end
29
-
30
- end
31
-
32
- module CacheDigestOptions
33
- extend ActiveSupport::Concern
34
-
35
- def digest
36
- CacheDigest.new(self).digest
37
- end
38
-
39
- module ClassMethods
40
- def digest!(*digest_columns)
41
- @digest_columns = digest_columns
42
- end
43
-
44
- def digest_columns
45
- @digest_columns || []
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,41 +0,0 @@
1
- module Mincer
2
- module Processors
3
-
4
- class Paginate
5
- def initialize(mincer)
6
- @mincer, @args, @relation = mincer, mincer.args, mincer.relation
7
- end
8
-
9
- def apply
10
- if kaminari?
11
- @relation.page(@args['page']).per(@args['per_page'])
12
- elsif will_paginate?
13
- @relation.paginate(page: @args['page'], per_page: @args['per_page'])
14
- else
15
- warn 'To enable pagination please add kaminari or will_paginate to your Gemfile'
16
- @relation
17
- end
18
- end
19
-
20
- #private
21
-
22
- def kaminari?
23
- defined?(::Kaminari)
24
- end
25
-
26
- def will_paginate?
27
- defined?(::WillPaginate)
28
- end
29
- end
30
-
31
- module PaginatorOptions
32
- extend ActiveSupport::Concern
33
-
34
- module ClassMethods
35
- def skip_pagination!
36
- active_processors.delete(Mincer::Processors::Paginate)
37
- end
38
- end
39
- end
40
- end
41
- end