autocompl 0.2.0 → 0.2.1

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: d2c522e7a3820bd72329a60bb3f2e6db9348db2b
4
- data.tar.gz: 7bf631b5de96b73795ee15bb594064fe6a44c455
3
+ metadata.gz: 451f4f6c82f31bc074c13cfaa4214803940aee40
4
+ data.tar.gz: 34797507e45ea10880975998c50ec3853ba5e603
5
5
  SHA512:
6
- metadata.gz: 6fd35e1abb615f661759fbc65ea2675ab5ba8e3ac590c7c18eff7fcbad8ca0f9aa4f3c6d96dcc2ba332fd3455abf6672c0433dfa0862b044aba6981dcd3a3bf0
7
- data.tar.gz: a5d07694c71bfac7ed3611ed964ae98536c7ac7ed7fa23adfaeb71f3e38b7fbd5c51d0ad6d4a2c7a834ba89f253612b3db9e4d6a32b6bc442548cd0b8d586876
6
+ metadata.gz: 34baf7b4c8d83315ffbd3eebf9c818dc7b061ab14366ecfe4b01093600bcf39bd5dfb664f8aec427a725e78ae3ebad52226d653ec8782ec4bb4db0b60f935d87
7
+ data.tar.gz: 4fee165adf480e89c0d078169d789ae610059acd8f841572d03c268b4b6beada7bd139e536f96388a064314d759011df2746024933d05dc2c58a4a7e732e60e9
@@ -2,38 +2,42 @@ require 'autocompl/repository'
2
2
 
3
3
  module Autocompl
4
4
  module Base
5
+ BASE_CACHE_KEY = 'autocomplete_cache'.freeze
6
+
5
7
  def self.included(target)
6
8
  target.extend Autocompl::Base::ClassMethods
7
9
  target.send :include, Autocompl::Repository
8
10
  end
9
11
 
10
12
  module ClassMethods
11
- BASE_CACHE_KEY = 'autocomplete_cache'.freeze
12
-
13
13
  def autocomplete(options = {})
14
14
  define_method('autocomplete_endpoint') do
15
15
  render json: [] if params[:term].nil?
16
16
  render json: [] if options.nil?
17
- if cacheable?
18
- items = Rails.cache.fetch(get_cache_key(options), expires_in: cache_expire) { get_items(options) }
19
- else
20
- items = get_items(options)
21
- end
17
+ # if cacheable?
18
+ # items = Rails.cache.fetch(get_cache_key(options), expires_in: cache_expire) { get_items(options, params[:term]) }
19
+ # elsle
20
+ items = get_items(options, params)
21
+ # end
22
22
  render json: items
23
23
  end
24
24
  end
25
25
  end
26
26
 
27
- def get_items(options)
27
+ def get_items(options, params)
28
28
  klasses = options.keys
29
29
  items = []
30
30
  for klass in klasses
31
31
  columns = options[klass].instance_of?(Array) ? options[klass] : [] << options[klass]
32
- items.concat(get_collection(klass, columns))
32
+ items.concat(get_collection(klass, columns, term: params[:term], limit: get_limit(params)))
33
33
  end
34
34
  items
35
35
  end
36
36
 
37
+ def get_limit(params)
38
+ params[:limit] ||= 20
39
+ end
40
+
37
41
  def cacheable?
38
42
  Rails.application.config.cache_store.present? && Rails.application.config.cache_autocomplete
39
43
  end
@@ -43,7 +47,7 @@ module Autocompl
43
47
  end
44
48
 
45
49
  def get_cache_key(options)
46
- ClassMethods::BASE_CACHE_KEY + ':' + get_model_cache_key(options)
50
+ BASE_CACHE_KEY + ':' + get_model_cache_key(options)
47
51
  end
48
52
 
49
53
  def get_model_cache_key(options)
@@ -1,10 +1,10 @@
1
1
  module Autocompl
2
2
  module Repository
3
- def get_collection(model, columns)
3
+ def get_collection(model, columns, options)
4
4
  klass = model.to_s.camelize.constantize
5
5
  items = []
6
6
  for column in columns
7
- items.concat(klass.select(column).distinct.map(&column))
7
+ items.concat(klass.select(column).where("#{column} LIKE ?", "%#{options[:term]}%").limit(options[:limit]).distinct.map(&column))
8
8
  end
9
9
  items
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module Autocompl
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- autocompl (0.1.2)
4
+ autocompl (0.2.1)
5
5
  rails (>= 4.2.0)
6
6
 
7
7
  GEM
@@ -2956,3 +2956,136 @@ Processing by MakersController#autocomplete_endpoint as JSON
2956
2956
  Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms)
2957
2957
 
2958
2958
 
2959
+ Started GET "/products" for ::1 at 2017-01-26 23:44:15 +0900
2960
+ DEPRECATION WARNING: ActiveRecord::Base.raise_in_transactional_callbacks= is deprecated, has no effect and will be removed without replacement. (called from block (3 levels) in <class:Railtie> at /Users/takahashiseiji/src/github.com/timakin/autocompl/test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/railtie.rb:113)
2961
+ ActiveRecord::SchemaMigration Load (1.6ms) SELECT "schema_migrations".* FROM "schema_migrations"
2962
+ Processing by ProductsController#index as HTML
2963
+ Rendering products/index.html.erb within layouts/application
2964
+ Product Load (1.3ms) SELECT "products".* FROM "products"
2965
+ Rendered products/index.html.erb within layouts/application (64.1ms)
2966
+ Started GET "/products" for ::1 at 2017-01-26 23:44:16 +0900
2967
+ Processing by ProductsController#index as HTML
2968
+ Rendering products/index.html.erb within layouts/application
2969
+ Product Load (0.2ms) SELECT "products".* FROM "products"
2970
+ Rendered products/index.html.erb within layouts/application (2.1ms)
2971
+ Completed 200 OK in 160ms (Views: 158.2ms | ActiveRecord: 0.2ms)
2972
+
2973
+
2974
+ Completed 200 OK in 609ms (Views: 597.8ms | ActiveRecord: 1.8ms)
2975
+
2976
+
2977
+ Started GET "/assets/makers.self-08dba1ca5eca7ae6468c13bb588e6b0aa62676d80e307c312855bcac16be80a3.js?body=1" for ::1 at 2017-01-26 23:44:16 +0900
2978
+ Started GET "/assets/products.self-bbcb94d3a0d5bcf6c07b22138897d08cbb40bd52d52c699d9fa0fc2200dc35e0.js?body=1" for ::1 at 2017-01-26 23:44:16 +0900
2979
+ Started GET "/products/autocomplete_endpoint?term=a" for ::1 at 2017-01-26 23:44:23 +0900
2980
+ Processing by ProductsController#autocomplete_endpoint as JSON
2981
+ Parameters: {"term"=>"a"}
2982
+ Product Load (0.2ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%a%') LIMIT ? [["LIMIT", 20]]
2983
+ Completed 200 OK in 5ms (Views: 0.4ms | ActiveRecord: 0.2ms)
2984
+
2985
+
2986
+ Started GET "/products" for ::1 at 2017-01-26 23:44:23 +0900
2987
+ Processing by ProductsController#index as HTML
2988
+ Rendering products/index.html.erb within layouts/application
2989
+ Product Load (0.1ms) SELECT "products".* FROM "products"
2990
+ Rendered products/index.html.erb within layouts/application (2.5ms)
2991
+ Completed 200 OK in 20ms (Views: 17.2ms | ActiveRecord: 0.1ms)
2992
+
2993
+
2994
+ Started GET "/products/autocomplete_endpoint?term=%E3%81%BF" for ::1 at 2017-01-26 23:44:26 +0900
2995
+ Processing by ProductsController#autocomplete_endpoint as JSON
2996
+ Parameters: {"term"=>"み"}
2997
+ Product Load (0.4ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%み%') LIMIT ? [["LIMIT", 20]]
2998
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.4ms)
2999
+
3000
+
3001
+ Started GET "/products/autocomplete_endpoint?term=%E3%81%BF%E3%81%8B%E3%82%93a" for ::1 at 2017-01-26 23:44:29 +0900
3002
+ Processing by ProductsController#autocomplete_endpoint as JSON
3003
+ Parameters: {"term"=>"みかんa"}
3004
+ Product Load (0.3ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%みかんa%') LIMIT ? [["LIMIT", 20]]
3005
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.3ms)
3006
+
3007
+
3008
+ Started GET "/products/autocomplete_endpoint?term=%E3%81%BF%E3%81%8B%E3%82%93" for ::1 at 2017-01-26 23:44:29 +0900
3009
+ Processing by ProductsController#autocomplete_endpoint as JSON
3010
+ Parameters: {"term"=>"みかん"}
3011
+ Product Load (0.2ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%みかん%') LIMIT ? [["LIMIT", 20]]
3012
+ Completed 200 OK in 2ms (Views: 0.2ms | ActiveRecord: 0.2ms)
3013
+
3014
+
3015
+ Started GET "/products/autocomplete_endpoint?term=%E3%81%BF%E3%81%8B" for ::1 at 2017-01-26 23:44:30 +0900
3016
+ Processing by ProductsController#autocomplete_endpoint as JSON
3017
+ Parameters: {"term"=>"みか"}
3018
+ Product Load (0.3ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%みか%') LIMIT ? [["LIMIT", 20]]
3019
+ Completed 200 OK in 2ms (Views: 0.4ms | ActiveRecord: 0.3ms)
3020
+
3021
+
3022
+ Started GET "/products/autocomplete_endpoint?term=%E3%81%BF%E3%81%8Bf" for ::1 at 2017-01-26 23:44:31 +0900
3023
+ Processing by ProductsController#autocomplete_endpoint as JSON
3024
+ Parameters: {"term"=>"みかf"}
3025
+ Product Load (0.4ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%みかf%') LIMIT ? [["LIMIT", 20]]
3026
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.4ms)
3027
+
3028
+
3029
+ Started GET "/products/autocomplete_endpoint?term=%E3%82%8A" for ::1 at 2017-01-26 23:44:36 +0900
3030
+ Processing by ProductsController#autocomplete_endpoint as JSON
3031
+ Parameters: {"term"=>"り"}
3032
+ Product Load (0.3ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%り%') LIMIT ? [["LIMIT", 20]]
3033
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.3ms)
3034
+
3035
+
3036
+ Started GET "/products/autocomplete_endpoint?term=%E3%82%8An" for ::1 at 2017-01-26 23:44:37 +0900
3037
+ Processing by ProductsController#autocomplete_endpoint as JSON
3038
+ Parameters: {"term"=>"りn"}
3039
+ Product Load (0.2ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%りn%') LIMIT ? [["LIMIT", 20]]
3040
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.2ms)
3041
+
3042
+
3043
+ Started GET "/products/autocomplete_endpoint?term=%E3%82%8A%E3%82%93" for ::1 at 2017-01-26 23:44:39 +0900
3044
+ Processing by ProductsController#autocomplete_endpoint as JSON
3045
+ Parameters: {"term"=>"りん"}
3046
+ Product Load (0.3ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%りん%') LIMIT ? [["LIMIT", 20]]
3047
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.3ms)
3048
+
3049
+
3050
+ Started GET "/products/autocomplete_endpoint?term=%E3%82%8A%E3%82%93" for ::1 at 2017-01-26 23:44:42 +0900
3051
+ Processing by ProductsController#autocomplete_endpoint as JSON
3052
+ Parameters: {"term"=>"りん"}
3053
+ Product Load (0.3ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%りん%') LIMIT ? [["LIMIT", 20]]
3054
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.3ms)
3055
+
3056
+
3057
+ Started GET "/products/autocomplete_endpoint?term=%E3%82%8A%E3%82%93%E3%81%82" for ::1 at 2017-01-26 23:44:44 +0900
3058
+ Processing by ProductsController#autocomplete_endpoint as JSON
3059
+ Parameters: {"term"=>"りんあ"}
3060
+ Product Load (0.2ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%りんあ%') LIMIT ? [["LIMIT", 20]]
3061
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.2ms)
3062
+
3063
+
3064
+ Started GET "/products/autocomplete_endpoint?term=%E3%82%8A%E3%82%93%E3%81%94" for ::1 at 2017-01-26 23:44:44 +0900
3065
+ Processing by ProductsController#autocomplete_endpoint as JSON
3066
+ Parameters: {"term"=>"りんご"}
3067
+ Product Load (0.2ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%りんご%') LIMIT ? [["LIMIT", 20]]
3068
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.2ms)
3069
+
3070
+
3071
+ Started GET "/products/autocomplete_endpoint?term=%E3%82%8A%E3%82%93%E3%81%94%E3%81%82" for ::1 at 2017-01-26 23:44:45 +0900
3072
+ Processing by ProductsController#autocomplete_endpoint as JSON
3073
+ Parameters: {"term"=>"りんごあ"}
3074
+ Product Load (0.2ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%りんごあ%') LIMIT ? [["LIMIT", 20]]
3075
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.2ms)
3076
+
3077
+
3078
+ Started GET "/products/autocomplete_endpoint?term=%E3%82%81" for ::1 at 2017-01-26 23:44:47 +0900
3079
+ Processing by ProductsController#autocomplete_endpoint as JSON
3080
+ Parameters: {"term"=>"め"}
3081
+ Product Load (0.3ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%め%') LIMIT ? [["LIMIT", 20]]
3082
+ Completed 200 OK in 2ms (Views: 0.2ms | ActiveRecord: 0.3ms)
3083
+
3084
+
3085
+ Started GET "/products/autocomplete_endpoint?term=%E3%83%A1%E3%83%AD" for ::1 at 2017-01-26 23:44:48 +0900
3086
+ Processing by ProductsController#autocomplete_endpoint as JSON
3087
+ Parameters: {"term"=>"メロ"}
3088
+ Product Load (0.4ms) SELECT DISTINCT "products"."name" FROM "products" WHERE (name LIKE '%メロ%') LIMIT ? [["LIMIT", 20]]
3089
+ Completed 200 OK in 3ms (Views: 0.4ms | ActiveRecord: 0.4ms)
3090
+
3091
+
@@ -0,0 +1 @@
1
+ I"�app/assets/javascripts/application.js?type=application/javascript&id=f55b68c7c1013259b4e47da503fea086e775ff13475dc1d49372c28d29732a96:ET
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autocompl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - timakin
@@ -136,6 +136,7 @@ files:
136
136
  - test/dummy/tmp/cache/75D/921/autocomplete_cache%3Aproduct_name_and_maker_name_ja_name_en
137
137
  - test/dummy/tmp/cache/D00/DC0/autocomplete_cache%3Aproduct_name
138
138
  - test/dummy/tmp/cache/assets/sprockets/v3.0/-I/-IXSJkaKinU8Fl50eKDwB1ydQ0JtcZ5gnVse55EfjIw.cache
139
+ - test/dummy/tmp/cache/assets/sprockets/v3.0/01/01H2EkpZWXO0y1JdqGg-x30S7nb2tN2h5beZiwZn-gQ.cache
139
140
  - test/dummy/tmp/cache/assets/sprockets/v3.0/0s/0saAXDP1LgnauZgKcL7RYa23dQGPLLL5Qsc6inAVKVA.cache
140
141
  - test/dummy/tmp/cache/assets/sprockets/v3.0/1c/1cJQq91B0zcYUIcPj7LP7CA1sE-McgS0WSCA_V0kZaA.cache
141
142
  - test/dummy/tmp/cache/assets/sprockets/v3.0/3C/3CBEbL4TspoWoNsPcQ1zQTj-exbwnq339w_7UnHBD3Y.cache
@@ -174,6 +175,7 @@ files:
174
175
  - test/dummy/tmp/cache/assets/sprockets/v3.0/Z2/Z2P0w0owMglA0uqkRDlcbkDdIJNQ8nonHbQC2TtA8QE.cache
175
176
  - test/dummy/tmp/cache/assets/sprockets/v3.0/Zb/ZbrDOS-Sy277xxdvxjn0aweKst_5fnfJ7LLJlZ0IsQA.cache
176
177
  - test/dummy/tmp/cache/assets/sprockets/v3.0/az/azI5AS0eFV_y-Ld5TnIKGxuM-KYbgdR4IpUIVJqHOmU.cache
178
+ - test/dummy/tmp/cache/assets/sprockets/v3.0/bG/bG1YH6QB51Was7wJ99y1omNpZSY4K-T8WlXDcfNWENk.cache
177
179
  - test/dummy/tmp/cache/assets/sprockets/v3.0/dO/dOZ5cU6HWKj5BNcnPUIFjH8930y3pFITKcXLUTB7V2A.cache
178
180
  - test/dummy/tmp/cache/assets/sprockets/v3.0/dd/ddD0bTKZ3paS1rj4G_xcZc6t9S8MAKgTZwdXA7G6zoI.cache
179
181
  - test/dummy/tmp/cache/assets/sprockets/v3.0/e3/e3muujThQ4WWrJ9-qrxh0dUVwSv9MfVOETtK7F-Zt_4.cache
@@ -3574,6 +3576,7 @@ test_files:
3574
3576
  - test/dummy/test/models/product_test.rb
3575
3577
  - test/dummy/tmp/cache/75D/921/autocomplete_cache%3Aproduct_name_and_maker_name_ja_name_en
3576
3578
  - test/dummy/tmp/cache/assets/sprockets/v3.0/-I/-IXSJkaKinU8Fl50eKDwB1ydQ0JtcZ5gnVse55EfjIw.cache
3579
+ - test/dummy/tmp/cache/assets/sprockets/v3.0/01/01H2EkpZWXO0y1JdqGg-x30S7nb2tN2h5beZiwZn-gQ.cache
3577
3580
  - test/dummy/tmp/cache/assets/sprockets/v3.0/0s/0saAXDP1LgnauZgKcL7RYa23dQGPLLL5Qsc6inAVKVA.cache
3578
3581
  - test/dummy/tmp/cache/assets/sprockets/v3.0/1c/1cJQq91B0zcYUIcPj7LP7CA1sE-McgS0WSCA_V0kZaA.cache
3579
3582
  - test/dummy/tmp/cache/assets/sprockets/v3.0/3C/3CBEbL4TspoWoNsPcQ1zQTj-exbwnq339w_7UnHBD3Y.cache
@@ -3586,6 +3589,7 @@ test_files:
3586
3589
  - test/dummy/tmp/cache/assets/sprockets/v3.0/9u/9uxgGG9_QdAxOXdXscuoVWfjxLJiPCQS21uY5gQTI8w.cache
3587
3590
  - test/dummy/tmp/cache/assets/sprockets/v3.0/Aq/AqNGhHk1VeXGpnPVZLp6ae6CjLXApTRdQXbYDj4Ldr0.cache
3588
3591
  - test/dummy/tmp/cache/assets/sprockets/v3.0/az/azI5AS0eFV_y-Ld5TnIKGxuM-KYbgdR4IpUIVJqHOmU.cache
3592
+ - test/dummy/tmp/cache/assets/sprockets/v3.0/bG/bG1YH6QB51Was7wJ99y1omNpZSY4K-T8WlXDcfNWENk.cache
3589
3593
  - test/dummy/tmp/cache/assets/sprockets/v3.0/BN/BN4Jum0nAu0cumhqUUs9QERjQpKaPBammfrYyv9MVbc.cache
3590
3594
  - test/dummy/tmp/cache/assets/sprockets/v3.0/C1/C1ZE2hO2C1AJh0F5vK0fsog_QGcOlMRhQxMa2H8WBgs.cache
3591
3595
  - test/dummy/tmp/cache/assets/sprockets/v3.0/C_/C_o_CSo6amWaEQVLG47OH0oI8rfhOuyVsHyYMZfwRLM.cache