autocomplete_for 1.0.3 → 1.0.5

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: 3fd7b798ec8d4f0272517c49f3dd153aa8bd688fd0c88d42de44e3d2462425ae
4
+ data.tar.gz: e9359474e2b033b73ab6e1237ad5a90a3e4dd96ea9ae803b205304146a3868fd
5
5
  SHA512:
6
- metadata.gz: 5fbb265ea62b18b25ecd5f2296dfe203f86a89f4d075a6a08eb8a30183e925c4a7365182b2ed9f24b2f7398462afd3e013491da982cd38c3a38ed6e33cdf6dd7
7
- data.tar.gz: 93fecb69198a2d5694d7ec311136608fdb22458ef5d4d1ac7b760ad0ad8c057d87a2d3331deb6f57c5c6ecfd446cfed28a02b71ad9ab1ce9be5c5c9958a45d31
6
+ metadata.gz: 96fa941cad153eec9fee940fd26d05fab9f06f0caa62a8c2f751dbe56516d09d9673d87022a74dffd31f3467691c7f92434289c687693e7113d2a5929385536a
7
+ data.tar.gz: 435376a64a0df04efd74630f42dac6769c41a4a22161ba1ba9bea2975cad4083c68465500996c8a73317343c2861be94f8e66d8133effe8e255a6c71501b9ef5
@@ -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
+ # frozen_string_literal: true
2
+
1
3
  require 'autocomplete_for/autocomplete_for.rb'
4
+ require 'autocomplete_for/version.rb'
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}"
@@ -37,8 +39,9 @@ module AutocompleteFor
37
39
  define_method(:"validate_#{association}_by_#{field}") do
38
40
  return unless instance_variable_get(:"@#{association}_#{field}")
39
41
  return if send(association.to_sym)
40
- 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)
42
+ return if self.class.instance_variable_get(:"@#{association}_#{field}_allow_nil") && instance_variable_get(:"@#{association}_#{field}") == ''
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}")
67
+
64
68
  if instance_variable_get(:"@#{association}_#{field}") == ''
65
- self.send(:"#{association}=", nil)
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)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AutocompleteFor
4
+ VERSION = '1.0.5'
5
+ end
metadata CHANGED
@@ -1,97 +1,97 @@
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.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kirby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2011-10-26 00:00:00.000000000 Z
11
+ date: 2019-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: pg
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
19
+ version: '5.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ">="
27
+ - - ">"
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: '5.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
27
33
  - !ruby/object:Gem::Dependency
28
- name: rake
34
+ name: rails
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0'
39
+ version: '5.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.0'
34
43
  type: :development
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - ">="
47
+ - - "~>"
39
48
  - !ruby/object:Gem::Version
40
- version: '0'
49
+ version: '5.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.0'
41
53
  - !ruby/object:Gem::Dependency
42
- name: activerecord
54
+ name: rake
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 4.2.10
48
- - - "<="
57
+ - - "~>"
49
58
  - !ruby/object:Gem::Version
50
- version: 5.1.6
51
- type: :runtime
59
+ version: '12.0'
60
+ type: :development
52
61
  prerelease: false
53
62
  version_requirements: !ruby/object:Gem::Requirement
54
63
  requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: 4.2.10
58
- - - "<="
64
+ - - "~>"
59
65
  - !ruby/object:Gem::Version
60
- version: 5.1.6
66
+ version: '12.0'
61
67
  - !ruby/object:Gem::Dependency
62
- name: rails
68
+ name: rspec-rails
63
69
  requirement: !ruby/object:Gem::Requirement
64
70
  requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 4.2.10
68
- - - "<="
71
+ - - "~>"
69
72
  - !ruby/object:Gem::Version
70
- version: 5.1.6
73
+ version: '3.8'
71
74
  type: :development
72
75
  prerelease: false
73
76
  version_requirements: !ruby/object:Gem::Requirement
74
77
  requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: 4.2.10
78
- - - "<="
78
+ - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: 5.1.6
80
+ version: '3.8'
81
81
  - !ruby/object:Gem::Dependency
82
- name: rspec-rails
82
+ name: rubocop
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '3.8'
87
+ version: '0.61'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
- version: '3.8'
94
+ version: '0.61'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: sqlite3
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -107,22 +107,20 @@ dependencies:
107
107
  - !ruby/object:Gem::Version
108
108
  version: '1.3'
109
109
  description: Model-side logic for autocompleting belongs_to associations
110
- email: sskirby@gmail.com
110
+ email: skirby@gmail.com
111
111
  executables: []
112
112
  extensions: []
113
- extra_rdoc_files:
114
- - README.markdown
113
+ extra_rdoc_files: []
115
114
  files:
116
- - Gemfile
117
- - Gemfile.lock
118
115
  - MIT-LICENSE
119
116
  - README.markdown
120
- - Rakefile
121
- - autocomplete_for.gemspec
122
117
  - lib/autocomplete_for.rb
123
118
  - lib/autocomplete_for/autocomplete_for.rb
124
- homepage: http://github.com/nulogy/autocomplete_for
125
- licenses: []
119
+ - lib/autocomplete_for/version.rb
120
+ homepage:
121
+ licenses:
122
+ - MIT
123
+ - GPL-3.0
126
124
  metadata: {}
127
125
  post_install_message:
128
126
  rdoc_options: []
@@ -137,11 +135,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
135
  requirements:
138
136
  - - ">="
139
137
  - !ruby/object:Gem::Version
140
- version: '0'
138
+ version: '2.6'
141
139
  requirements: []
142
- rubyforge_project: autocomplete_for
143
- rubygems_version: 2.6.14
140
+ rubyforge_project: "[none]"
141
+ rubygems_version: 2.7.7
144
142
  signing_key:
145
- specification_version: 3
146
- summary: Model-side logic for autocompleting belongs_to associations
143
+ specification_version: 4
144
+ summary: Autocomplete for models
147
145
  test_files: []
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :gemcutter
2
-
3
- gemspec
@@ -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
-