autocomplete_for 1.0.3 → 1.2

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
- SHA1:
3
- metadata.gz: ec98677c8d47681be045e298a30de50c5a7e7ec6
4
- data.tar.gz: c0815e4bcde599ac3716c37bd5c03ca679e358e5
2
+ SHA256:
3
+ metadata.gz: 1a866f0de096b328e242405a2f80cdb0b4427bba76c4b82802db7caa65bdbdb1
4
+ data.tar.gz: 0711f05bd588f7813bf76dcc6ce9c943dd9c3e750c9da6a737c68a472567f21f
5
5
  SHA512:
6
- metadata.gz: 5fbb265ea62b18b25ecd5f2296dfe203f86a89f4d075a6a08eb8a30183e925c4a7365182b2ed9f24b2f7398462afd3e013491da982cd38c3a38ed6e33cdf6dd7
7
- data.tar.gz: 93fecb69198a2d5694d7ec311136608fdb22458ef5d4d1ac7b760ad0ad8c057d87a2d3331deb6f57c5c6ecfd446cfed28a02b71ad9ab1ce9be5c5c9958a45d31
6
+ metadata.gz: 0646dee01dff94a2cf93e99b344f155769cddf7c22e237a713f9897fe0237218761c11f5273624405cf09a6dfd1febbcc9e08959b1ae222ce84e03c5235f2cf9
7
+ data.tar.gz: 1c80fb60a11a62d12eb978e30ea2b3d5a89e5bcefbc27836e30a1bef2b57f3d272046366ae046626d04d522ddaccd5bead10b6b7cd572ace1197339d31d7d86f
data/README.markdown CHANGED
@@ -16,6 +16,7 @@ It works out-of-the-box with existing front-end autocompletion solutions because
16
16
 
17
17
  ### Example
18
18
 
19
+ ```ruby
19
20
  class Author < ActiveRecord::Base
20
21
  # has a login and open_id column
21
22
  end
@@ -33,21 +34,25 @@ It works out-of-the-box with existing front-end autocompletion solutions because
33
34
  self.author = Author.find(:first, :conditions => {:open_id => @author_open_id})
34
35
  end
35
36
  end
37
+ ```
36
38
 
37
39
  Using autocomplete_for in your models to set belongs_to associations:
38
40
 
41
+ ```ruby
39
42
  author = Author.create! :login => 'baz'
40
43
  post = Post.create! :author_login => 'baz' # automatically finds the author with the login 'baz'
41
44
  puts post.author.login # will output 'baz'
45
+ ```
42
46
 
43
47
  Errors are generated automatically if the given information does not correspond to a valid model:
44
48
 
49
+ ```ruby
45
50
  author = Author.create! :login => 'baz'
46
51
  post = Post.create :author_login => 'quux'
47
52
  puts post.errors[:author_login] # will print an error message
53
+ ```
48
54
 
49
55
  ### Running the tests
50
- You can run the unit tests using `bundle exec rake test`; it assumes you have a Postgres database
51
- configured as per `test/database.yml` (e.g. credentials are valid, database exists).
56
+ You can run the unit tests using `rake`
52
57
 
53
- Copyright (c) 2018 Nulogy Corporation, released under the MIT license
58
+ Copyright (c) 2019 Nulogy Corporation, released under the MIT license
@@ -1 +1,7 @@
1
- require 'autocomplete_for/autocomplete_for.rb'
1
+ # frozen_string_literal: true
2
+
3
+ require "autocomplete_for/autocomplete_for"
4
+ require "autocomplete_for/version"
5
+
6
+ module AutocompleteFor
7
+ end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AutocompleteFor
2
4
  def self.included(base)
3
- base.send :extend, ClassMethods
5
+ base.send(:extend, ClassMethods)
4
6
  end
5
7
 
6
8
  module ClassMethods
7
- def autocomplete_for association, field, options = {}, &block
9
+ def autocomplete_for(association, field, options = {}, &block)
8
10
  allow_nil = options[:allow_nil] || false
9
11
  validate :"validate_#{association}_by_#{field}"
10
12
  before_validation :"associate_#{association}_by_#{field}"
@@ -38,7 +40,8 @@ module AutocompleteFor
38
40
  return unless instance_variable_get(:"@#{association}_#{field}")
39
41
  return if send(association.to_sym)
40
42
  return if self.class.instance_variable_get(:"@#{association}_#{field}_allow_nil") && instance_variable_get(:"@#{association}_#{field}") == ""
41
- self.errors.add(:"#{association}_#{field}", :does_not_exist)
43
+
44
+ errors.add(:"#{association}_#{field}", :does_not_exist)
42
45
  end
43
46
 
44
47
  # Resolve the autocompleted name to an actual entity
@@ -61,12 +64,13 @@ module AutocompleteFor
61
64
  # end
62
65
  define_method(:"associate_#{association}_by_#{field}") do
63
66
  return unless instance_variable_get(:"@#{association}_#{field}")
64
- if instance_variable_get(:"@#{association}_#{field}") == ''
65
- self.send(:"#{association}=", nil)
67
+
68
+ if instance_variable_get(:"@#{association}_#{field}") == ""
69
+ send(:"#{association}=", nil)
66
70
  return
67
71
  end
68
72
 
69
- self.send(:"autocomplete_find_#{association}_by_#{field}")
73
+ send(:"autocomplete_find_#{association}_by_#{field}")
70
74
  end
71
75
 
72
76
  # set up validation on association in case the customer_name isn't set
@@ -79,19 +83,20 @@ module AutocompleteFor
79
83
  unless allow_nil
80
84
  # we must make sure that the validate_by_customer validation runs
81
85
  # after ALL validations on autocomplete fields
82
- #skip_callback :validate, :by, :"#{association}"
86
+ # skip_callback :validate, :by, :"#{association}"
83
87
 
84
88
  validate :"validate_by_#{association}"
85
89
 
86
90
  unless instance_methods.include?("validate_by_#{association}")
87
91
 
88
92
  # def validate_by_customer
89
- # self.errors.add_on_blank(:customer) unless @@customer_autocompolete_error_fields.any? {|ef| self.errors[ef]}
93
+ # self.errors.add_on_blank(:customer) unless @@customer_autocomplete_error_fields.any? {|ef| self.errors[ef]}
90
94
  # end
91
95
  define_method(:"validate_by_#{association}") do
92
- return if self.class.instance_variable_get(error_fields_name).any? {|ef| self.errors[ef].any? }
93
- return unless self.send(:read_attribute_for_validation, association.to_sym).blank?
94
- self.errors.add(association.to_sym, :blank, options)
96
+ return if self.class.instance_variable_get(error_fields_name).any? { |ef| errors[ef].any? }
97
+ return unless send(:read_attribute_for_validation, association.to_sym).blank?
98
+
99
+ errors.add(association.to_sym, :blank, options)
95
100
  end
96
101
  end
97
102
  end
@@ -99,4 +104,4 @@ module AutocompleteFor
99
104
  end
100
105
  end
101
106
 
102
- ActiveRecord::Base.send :include, AutocompleteFor
107
+ ActiveRecord::Base.send(:include, AutocompleteFor) # rubocop:disable Lint/SendWithMixinArgument
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AutocompleteFor
4
+ VERSION = "1.2"
5
+ end
metadata CHANGED
@@ -1,130 +1,147 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autocomplete_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kirby
8
- autorequire:
8
+ - Alistair McKinnell
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2011-10-26 00:00:00.000000000 Z
12
+ date: 2021-07-13 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: pg
15
+ name: activerecord
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
20
+ version: '5.1'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '7.0'
24
+ type: :runtime
21
25
  prerelease: false
22
26
  version_requirements: !ruby/object:Gem::Requirement
23
27
  requirements:
24
28
  - - ">="
25
29
  - !ruby/object:Gem::Version
26
- version: '0'
30
+ version: '5.1'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
27
34
  - !ruby/object:Gem::Dependency
28
- name: rake
35
+ name: appraisal
29
36
  requirement: !ruby/object:Gem::Requirement
30
37
  requirements:
31
- - - ">="
38
+ - - "~>"
32
39
  - !ruby/object:Gem::Version
33
- version: '0'
40
+ version: '2.4'
34
41
  type: :development
35
42
  prerelease: false
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - ">="
45
+ - - "~>"
39
46
  - !ruby/object:Gem::Version
40
- version: '0'
47
+ version: '2.4'
41
48
  - !ruby/object:Gem::Dependency
42
- name: activerecord
49
+ name: rails
43
50
  requirement: !ruby/object:Gem::Requirement
44
51
  requirements:
45
52
  - - ">="
46
53
  - !ruby/object:Gem::Version
47
- version: 4.2.10
48
- - - "<="
54
+ version: '6.0'
55
+ - - "<"
49
56
  - !ruby/object:Gem::Version
50
- version: 5.1.6
51
- type: :runtime
57
+ version: '7.0'
58
+ type: :development
52
59
  prerelease: false
53
60
  version_requirements: !ruby/object:Gem::Requirement
54
61
  requirements:
55
62
  - - ">="
56
63
  - !ruby/object:Gem::Version
57
- version: 4.2.10
58
- - - "<="
64
+ version: '6.0'
65
+ - - "<"
59
66
  - !ruby/object:Gem::Version
60
- version: 5.1.6
67
+ version: '7.0'
61
68
  - !ruby/object:Gem::Dependency
62
- name: rails
69
+ name: rake
63
70
  requirement: !ruby/object:Gem::Requirement
64
71
  requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 4.2.10
68
- - - "<="
72
+ - - "~>"
69
73
  - !ruby/object:Gem::Version
70
- version: 5.1.6
74
+ version: '13.0'
71
75
  type: :development
72
76
  prerelease: false
73
77
  version_requirements: !ruby/object:Gem::Requirement
74
78
  requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: 4.2.10
78
- - - "<="
79
+ - - "~>"
79
80
  - !ruby/object:Gem::Version
80
- version: 5.1.6
81
+ version: '13.0'
81
82
  - !ruby/object:Gem::Dependency
82
83
  name: rspec-rails
83
84
  requirement: !ruby/object:Gem::Requirement
84
85
  requirements:
85
86
  - - "~>"
86
87
  - !ruby/object:Gem::Version
87
- version: '3.8'
88
+ version: '5.0'
88
89
  type: :development
89
90
  prerelease: false
90
91
  version_requirements: !ruby/object:Gem::Requirement
91
92
  requirements:
92
93
  - - "~>"
93
94
  - !ruby/object:Gem::Version
94
- version: '3.8'
95
+ version: '5.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rubocop
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.18'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.18'
95
110
  - !ruby/object:Gem::Dependency
96
111
  name: sqlite3
97
112
  requirement: !ruby/object:Gem::Requirement
98
113
  requirements:
99
114
  - - "~>"
100
115
  - !ruby/object:Gem::Version
101
- version: '1.3'
116
+ version: '1.4'
102
117
  type: :development
103
118
  prerelease: false
104
119
  version_requirements: !ruby/object:Gem::Requirement
105
120
  requirements:
106
121
  - - "~>"
107
122
  - !ruby/object:Gem::Version
108
- version: '1.3'
123
+ version: '1.4'
109
124
  description: Model-side logic for autocompleting belongs_to associations
110
- email: sskirby@gmail.com
125
+ email: skirby@gmail.com
111
126
  executables: []
112
127
  extensions: []
113
- extra_rdoc_files:
114
- - README.markdown
128
+ extra_rdoc_files: []
115
129
  files:
116
- - Gemfile
117
- - Gemfile.lock
118
130
  - MIT-LICENSE
119
131
  - README.markdown
120
- - Rakefile
121
- - autocomplete_for.gemspec
122
132
  - lib/autocomplete_for.rb
123
133
  - lib/autocomplete_for/autocomplete_for.rb
124
- homepage: http://github.com/nulogy/autocomplete_for
125
- licenses: []
126
- metadata: {}
127
- post_install_message:
134
+ - lib/autocomplete_for/version.rb
135
+ homepage: https://github.com/nulogy/autocomplete_for
136
+ licenses:
137
+ - MIT
138
+ - GPL-3.0
139
+ metadata:
140
+ homepage_uri: https://github.com/nulogy/autocomplete_for
141
+ changelog_uri: https://github.com/nulogy/autocomplete_for/blob/master/CHANGELOG.md
142
+ source_code_uri: https://github.com/nulogy/autocomplete_for
143
+ bug_tracker_uri: https://github.com/nulogy/autocomplete_for/issues
144
+ post_install_message:
128
145
  rdoc_options: []
129
146
  require_paths:
130
147
  - lib
@@ -132,16 +149,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
149
  requirements:
133
150
  - - ">="
134
151
  - !ruby/object:Gem::Version
135
- version: '0'
152
+ version: '2.6'
136
153
  required_rubygems_version: !ruby/object:Gem::Requirement
137
154
  requirements:
138
155
  - - ">="
139
156
  - !ruby/object:Gem::Version
140
157
  version: '0'
141
158
  requirements: []
142
- rubyforge_project: autocomplete_for
143
- rubygems_version: 2.6.14
144
- signing_key:
145
- specification_version: 3
146
- summary: Model-side logic for autocompleting belongs_to associations
159
+ rubygems_version: 3.1.6
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Autocomplete for models
147
163
  test_files: []
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :gemcutter
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,142 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- autocomplete_for (1.0.2)
5
- activerecord (>= 4.2.10, <= 5.1.6)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actioncable (5.1.6)
11
- actionpack (= 5.1.6)
12
- nio4r (~> 2.0)
13
- websocket-driver (~> 0.6.1)
14
- actionmailer (5.1.6)
15
- actionpack (= 5.1.6)
16
- actionview (= 5.1.6)
17
- activejob (= 5.1.6)
18
- mail (~> 2.5, >= 2.5.4)
19
- rails-dom-testing (~> 2.0)
20
- actionpack (5.1.6)
21
- actionview (= 5.1.6)
22
- activesupport (= 5.1.6)
23
- rack (~> 2.0)
24
- rack-test (>= 0.6.3)
25
- rails-dom-testing (~> 2.0)
26
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (5.1.6)
28
- activesupport (= 5.1.6)
29
- builder (~> 3.1)
30
- erubi (~> 1.4)
31
- rails-dom-testing (~> 2.0)
32
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
- activejob (5.1.6)
34
- activesupport (= 5.1.6)
35
- globalid (>= 0.3.6)
36
- activemodel (5.1.6)
37
- activesupport (= 5.1.6)
38
- activerecord (5.1.6)
39
- activemodel (= 5.1.6)
40
- activesupport (= 5.1.6)
41
- arel (~> 8.0)
42
- activesupport (5.1.6)
43
- concurrent-ruby (~> 1.0, >= 1.0.2)
44
- i18n (>= 0.7, < 2)
45
- minitest (~> 5.1)
46
- tzinfo (~> 1.1)
47
- arel (8.0.0)
48
- builder (3.2.3)
49
- concurrent-ruby (1.1.3)
50
- crass (1.0.4)
51
- diff-lcs (1.3)
52
- erubi (1.7.1)
53
- globalid (0.4.1)
54
- activesupport (>= 4.2.0)
55
- i18n (1.1.1)
56
- concurrent-ruby (~> 1.0)
57
- loofah (2.2.3)
58
- crass (~> 1.0.2)
59
- nokogiri (>= 1.5.9)
60
- mail (2.7.1)
61
- mini_mime (>= 0.1.1)
62
- method_source (0.9.1)
63
- mini_mime (1.0.1)
64
- mini_portile2 (2.3.0)
65
- minitest (5.11.3)
66
- nio4r (2.3.1)
67
- nokogiri (1.8.5)
68
- mini_portile2 (~> 2.3.0)
69
- pg (1.1.3)
70
- rack (2.0.6)
71
- rack-test (1.1.0)
72
- rack (>= 1.0, < 3)
73
- rails (5.1.6)
74
- actioncable (= 5.1.6)
75
- actionmailer (= 5.1.6)
76
- actionpack (= 5.1.6)
77
- actionview (= 5.1.6)
78
- activejob (= 5.1.6)
79
- activemodel (= 5.1.6)
80
- activerecord (= 5.1.6)
81
- activesupport (= 5.1.6)
82
- bundler (>= 1.3.0)
83
- railties (= 5.1.6)
84
- sprockets-rails (>= 2.0.0)
85
- rails-dom-testing (2.0.3)
86
- activesupport (>= 4.2.0)
87
- nokogiri (>= 1.6)
88
- rails-html-sanitizer (1.0.4)
89
- loofah (~> 2.2, >= 2.2.2)
90
- railties (5.1.6)
91
- actionpack (= 5.1.6)
92
- activesupport (= 5.1.6)
93
- method_source
94
- rake (>= 0.8.7)
95
- thor (>= 0.18.1, < 2.0)
96
- rake (12.3.1)
97
- rspec-core (3.8.0)
98
- rspec-support (~> 3.8.0)
99
- rspec-expectations (3.8.1)
100
- diff-lcs (>= 1.2.0, < 2.0)
101
- rspec-support (~> 3.8.0)
102
- rspec-mocks (3.8.0)
103
- diff-lcs (>= 1.2.0, < 2.0)
104
- rspec-support (~> 3.8.0)
105
- rspec-rails (3.8.0)
106
- actionpack (>= 3.0)
107
- activesupport (>= 3.0)
108
- railties (>= 3.0)
109
- rspec-core (~> 3.8.0)
110
- rspec-expectations (~> 3.8.0)
111
- rspec-mocks (~> 3.8.0)
112
- rspec-support (~> 3.8.0)
113
- rspec-support (3.8.0)
114
- sprockets (3.7.2)
115
- concurrent-ruby (~> 1.0)
116
- rack (> 1, < 3)
117
- sprockets-rails (3.2.1)
118
- actionpack (>= 4.0)
119
- activesupport (>= 4.0)
120
- sprockets (>= 3.0.0)
121
- sqlite3 (1.3.13)
122
- thor (0.20.0)
123
- thread_safe (0.3.6)
124
- tzinfo (1.2.5)
125
- thread_safe (~> 0.1)
126
- websocket-driver (0.6.5)
127
- websocket-extensions (>= 0.1.0)
128
- websocket-extensions (0.1.3)
129
-
130
- PLATFORMS
131
- ruby
132
-
133
- DEPENDENCIES
134
- autocomplete_for!
135
- pg
136
- rails (>= 4.2.10, <= 5.1.6)
137
- rake
138
- rspec-rails (~> 3.8)
139
- sqlite3 (~> 1.3)
140
-
141
- BUNDLED WITH
142
- 1.16.2
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rdoc/task'
4
- require 'bundler'
5
- Bundler::GemHelper.install_tasks
6
-
7
- desc 'Default: run unit tests.'
8
- task :default => :test
9
-
10
- desc 'Test the autocomplete_for plugin.'
11
- Rake::TestTask.new(:test) do |t|
12
- t.libs << 'lib'
13
- t.libs << 'test'
14
- t.pattern = 'test/**/*_test.rb'
15
- t.verbose = true
16
- end
17
-
18
- desc 'Generate documentation for the autocomplete_for plugin.'
19
- Rake::RDocTask.new(:rdoc) do |rdoc|
20
- rdoc.rdoc_dir = 'rdoc'
21
- rdoc.title = 'AutocompleteFor'
22
- rdoc.options << '--line-numbers' << '--inline-source'
23
- rdoc.rdoc_files.include('README.markdown')
24
- rdoc.rdoc_files.include('lib/**/*.rb')
25
- end
@@ -1,56 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "autocomplete_for"
8
- s.version = "1.0.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Sean Kirby"]
12
- s.date = "2011-10-26"
13
- s.description = "Model-side logic for autocompleting belongs_to associations"
14
- s.email = "sskirby@gmail.com"
15
- s.extra_rdoc_files = [
16
- "README.markdown"
17
- ]
18
- s.files = [
19
- "Gemfile",
20
- "Gemfile.lock",
21
- "MIT-LICENSE",
22
- "README.markdown",
23
- "Rakefile",
24
- "autocomplete_for.gemspec",
25
- "lib/autocomplete_for.rb",
26
- "lib/autocomplete_for/autocomplete_for.rb"
27
- ]
28
- s.homepage = "http://github.com/nulogy/autocomplete_for"
29
- s.require_paths = ["lib"]
30
- s.rubyforge_project = "autocomplete_for"
31
- s.rubygems_version = "1.8.10"
32
- s.summary = "Model-side logic for autocompleting belongs_to associations"
33
-
34
- if s.respond_to? :specification_version then
35
- s.specification_version = 3
36
-
37
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
- s.add_development_dependency(%q<pg>, [">= 0"])
39
- s.add_development_dependency(%q<rake>, [">= 0"])
40
- s.add_runtime_dependency(%q<activerecord>, [">= 4.2.10", "<= 5.1.6"])
41
- else
42
- s.add_dependency(%q<pg>, [">= 0"])
43
- s.add_dependency(%q<rake>, [">= 0"])
44
- s.add_dependency(%q<activerecord>, [">= 4.2.10", "<= 5.1.6"])
45
- end
46
- else
47
- s.add_dependency(%q<pg>, [">= 0"])
48
- s.add_dependency(%q<rake>, [">= 0"])
49
- s.add_dependency(%q<activerecord>, [">= 4.2.10", "<= 5.1.6"])
50
- end
51
-
52
- s.add_development_dependency("rails", ">= 4.2.10", "<= 5.1.6")
53
- s.add_development_dependency("rspec-rails", "~> 3.8")
54
- s.add_development_dependency("sqlite3", "~> 1.3")
55
- end
56
-