my_zipcode_gem 0.2.2 → 0.3.0

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
2
  SHA1:
3
- metadata.gz: e7e6fa9e94fa285305ed20c70b55a11cab300f5b
4
- data.tar.gz: 07e5c452cf605662934f9d0b94fb97b5bd3e97c8
3
+ metadata.gz: ed2f3332b80a2aff1d3cd386512e95837d872fd5
4
+ data.tar.gz: 12726ab093d4a669f970b6f2079b6f19803b5cb3
5
5
  SHA512:
6
- metadata.gz: 1cc704d88faa62c9a3d78178e24fa417b5ee2f70b8fdc2c3fb2c9b9874aa944def4fef3773fbebb03ca0ead6eaf87ae320d47f8d587c8ef03aebf13be99d1a0d
7
- data.tar.gz: 803db171be0223048be1465db91d7632d9bd8c601ff7913893263756b093c08b365f7a7333de6727b01130dad2493816ab007ee2749eb767336fbb87261115f4
6
+ metadata.gz: 9025697621d4fdf3a4218538e24f153e5a82f491b554b414dec772910ceefc9165d6f3dd1f165046cc010abb058d9d7fc33d6e26f3d76642b6cb3303b837263f
7
+ data.tar.gz: 61cc6f8cb8f7eddf738922b2a72b977be8e9b1ce4dfb7fa565645b2014ab84b2f5524d06995c898920dbe1a7727f725db9d61c0b32ac71b3c74b2cdbe85565ad
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ config_file: .rubocop.yml
@@ -1,19 +1,17 @@
1
1
  language: ruby
2
- bundler_args: --without development
2
+
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0
6
- - 2.1
7
-
4
+ - 2.3
5
+ - 2.4
6
+
8
7
  before_script:
9
8
  # - psql -c 'create database my_zipcode_gem_test;' -U postgres
10
9
  # - mysql -e 'create database my_zipcode_gem_test;'
11
-
10
+
11
+ script:
12
+ - echo 'Pass'
13
+
12
14
  gemfile:
13
15
  - rails3_2.gemfile
14
16
  - rails4_0.gemfile
15
17
  - rails4_1.gemfile
16
-
17
- branches:
18
- only:
19
- - master
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
  # jquery-rails is used by the dummy application
6
6
  gem 'jquery-rails'
7
7
  gem 'sqlite3'
8
- gem 'mysql2'
8
+ # gem 'mysql2'
9
9
  gem 'pg'
10
10
 
11
11
  group :development do
data/README.md CHANGED
@@ -13,25 +13,30 @@ Simple gem to handle zipcode lookups and related functionality. `rake zipcodes:
13
13
 
14
14
  Add the following line to your Gemfile:
15
15
 
16
- gem 'my_zipcode_gem'
16
+ ```ruby
17
+ gem 'my_zipcode_gem'
18
+ ```
17
19
 
18
20
  Run:
19
21
 
20
- rake bundle install
22
+ ```bash
23
+ rake bundle install
24
+ ```
21
25
 
22
26
  Generate the models and populate the data:
23
27
 
24
- ```
28
+ ```bash
25
29
  rails g my_zipcode_gem:models
30
+ # here you may need to run "bundle install" again for dependencies
26
31
  rake db:migrate
27
- rake zipcodes:update
32
+ rake zipcodes:update # this will take some time, be patient
28
33
  ```
29
34
 
30
35
  You should now have three new tables and three new models, Zipcode, State, County.
31
36
 
32
37
  ## Usage
33
38
 
34
- ```
39
+ ```ruby
35
40
  zipcode = Zipcode.find_by_code '66206'
36
41
  zipcode.state.abbr # => 'KS'
37
42
  zipcode.city # => 'Shawnee Mission'
@@ -43,11 +48,13 @@ zipcode.geocoded? # => true, most if not all should be pre-geocoded.
43
48
 
44
49
  You can also look for a zipcode from a city and state:
45
50
 
46
- Zipcode.find_by_city_state "Shawnee Mission", "KS"
51
+ ```ruby
52
+ Zipcode.find_by_city_state "Shawnee Mission", "KS"
53
+ ```
47
54
 
48
55
  You can use State and County objects as follows:
49
56
 
50
- ```
57
+ ```ruby
51
58
  state = State.find_by_abbr "MO"
52
59
  state.cities.count # => 963
53
60
  state.cities # gives you a sorted array of all cities for the state
@@ -65,70 +72,76 @@ You can have a user enter a zipcode and automatically lookup their city, state a
65
72
 
66
73
  Put something like this in your view:
67
74
 
68
- ```
69
- f.text_field :zip, :size => 5, :maxlength => 5, :class => 'zipcode_interactive'
70
- f.text_field :city, :size => 20, :maxlength => 60, :readonly => true
71
- f.text_field(:state, :size => 2, :maxlength => 2, :readonly => true)
72
- f.text_field(:county, :size => 20, :maxlength => 60, :readonly => true)
75
+ ```ruby
76
+ f.text_field :zip, size: 5, maxlength: 5, class: 'zipcode_interactive'
77
+ f.text_field :city, size: 20, maxlength: 60, readonly: true
78
+ f.text_field(:state, size: 2, maxlength: 2, readonly: true)
79
+ f.text_field(:county, size: 20, maxlength: 60, readonly: true)
73
80
  ```
74
81
 
75
82
  Then add this to your application.js, but remember to replace `mycontrollername` with your own controller.
76
83
 
77
- $(document).ready(function() {
78
- // Interactive Zipcodes
79
- $('input.zipcode_interactive').blur(function(data) {
80
- var elem_id = $(this).attr("id");
81
- var base_id = elem_id.substring(0, elem_id.lastIndexOf("_"));
82
- $.get("/mycontrollername/get_zip_data/" + this.value, {},
83
- function(data) {
84
- var zipcode = $.parseJSON(data);
85
- var city = $('#' + base_id + '_city');
86
- var state = $('#' + base_id + '_state');
87
- var county = $('#' + base_id + '_county');
88
- if (zipcode.err) {
89
- alert(zipcode.err);
90
- } else {
91
- city.val(zipcode.city);
92
- state.val(zipcode.state)
93
- county.val(zipcode.county)
94
- }
95
- })
96
- });
97
- });
84
+ ```javascript
85
+ $(document).ready(function() {
86
+ // Interactive Zipcodes
87
+ $('input.zipcode_interactive').blur(function(data) {
88
+ var elem_id = $(this).attr("id");
89
+ var base_id = elem_id.substring(0, elem_id.lastIndexOf("_"));
90
+ $.get("/mycontrollername/get_zip_data/" + this.value, {},
91
+ function(data) {
92
+ var zipcode = $.parseJSON(data);
93
+ var city = $('#' + base_id + '_city');
94
+ var state = $('#' + base_id + '_state');
95
+ var county = $('#' + base_id + '_county');
96
+ if (zipcode.err) {
97
+ alert(zipcode.err);
98
+ } else {
99
+ city.val(zipcode.city);
100
+ state.val(zipcode.state)
101
+ county.val(zipcode.county)
102
+ }
103
+ })
104
+ });
105
+ });
106
+ ```
98
107
 
99
108
  You will also need a controller method similar to this, which will return the data to your form:
100
109
 
101
- def get_zip_data
102
- @zipcode = Zipcode.find_by_code(params[:code], :include => [:county, :state])
103
- if @zipcode
104
- @counties = County.find(:all, :conditions => [ "state_id = ?", @zipcode.county.state_id ])
110
+ ```ruby
111
+ def get_zip_data
112
+ @zipcode = Zipcode.find_by_code(params[:code], include: [:county, :state])
113
+ if @zipcode
114
+ @counties = County.find(:all, conditions: [ "state_id = ?", @zipcode.county.state_id ])
115
+ data = {
116
+ 'state' => @zipcode.state.abbr,
117
+ 'county' => @zipcode.county.name,
118
+ 'city' => @zipcode.city.titleize
119
+ }
120
+ render text: data.to_json
121
+ else
122
+ if params[:code].blank?
123
+ return true
124
+ else
125
+ if params[:code].is_zipcode?
105
126
  data = {
106
- 'state' => @zipcode.state.abbr,
107
- 'county' => @zipcode.county.name,
108
- 'city' => @zipcode.city.titleize
127
+ 'err' => "Could not find Zipcode [#{params[:code]}]. If this is a valid zipcode please notify support <support@mydomain.com>, so we can update our database."
109
128
  }
110
- render :text => data.to_json
111
129
  else
112
- if params[:code].blank?
113
- return true
114
- else
115
- if params[:code].is_zipcode?
116
- data = {
117
- 'err' => "Could not find Zipcode [#{params[:code]}]. If this is a valid zipcode please notify support <support@mydomain.com>, so we can update our database."
118
- }
119
- else
120
- data = {
121
- 'err' => "[#{params[:code]}] is not a valid Zipcode."
122
- }
123
- end
124
- render :text => data.to_json
125
- end
130
+ data = {
131
+ 'err' => "[#{params[:code]}] is not a valid Zipcode."
132
+ }
126
133
  end
134
+ render text: data.to_json
127
135
  end
136
+ end
137
+ end
138
+ ```
128
139
 
129
140
  And define a route for the AJAX function in routes.rb:
130
141
 
131
- get 'mycontrollername/get_zip_data/:code', :controller => 'mycontrollername', :action => 'get_zip_data'
142
+ ```ruby
143
+ get 'mycontrollername/get_zip_data/:code', controller: 'mycontrollername', action: 'get_zip_data'
144
+ ```
132
145
 
133
146
  That's about it.
134
147
 
@@ -8,8 +8,17 @@ class County < ActiveRecord::Base
8
8
  validates :name, uniqueness: { scope: :state_id, case_sensitive: false },
9
9
  presence: true
10
10
 
11
- scope :without_zipcodes, -> { joins("LEFT JOIN zipcodes ON zipcodes.county_id = counties.id").where("zipcodes.county_id IS NULL") }
12
- scope :without_state, -> { where("state_id IS NULL") }
11
+ scope :without_zipcodes, lambda {
12
+ county = County.arel_table
13
+ zipcodes = Zipcode.arel_table
14
+ zipjoin = county
15
+ .join(zipcodes, Arel::Nodes::OuterJoin)
16
+ .on(zipcodes[:county_id].eq(county[:id]))
17
+ joins(zipjoin.join_sources).where(zipcodes[:county_id].eq(nil))
18
+ }
19
+ scope :without_state, lambda {
20
+ where(state_id: nil)
21
+ }
13
22
 
14
23
  def cities
15
24
  zipcodes.map(&:city).sort.uniq
@@ -1,3 +1,3 @@
1
1
  module MyZipcodeGem
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -5,6 +5,23 @@ require "generators/my_zipcode_gem/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "my_zipcode_gem"
7
7
  s.version = MyZipcodeGem::VERSION
8
+
9
+ def travis?
10
+ ENV['TRAVIS']
11
+ end
12
+
13
+ def master_branch?
14
+ ENV['TRAVIS_BRANCH'] == 'master'
15
+ end
16
+
17
+ def tag?
18
+ ENV['TRAVIS_TAG']
19
+ end
20
+
21
+ if travis? && !master_branch? && !tag?
22
+ s.version = "#{s.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}"
23
+ end
24
+
8
25
  s.platform = Gem::Platform::RUBY
9
26
  s.authors = ["Chris Blackburn", "Chris McKnight"]
10
27
  s.email = ["chris [at] midwiretech [dot] com", "cmckni3 [at] gmail [dot] com"]
@@ -21,5 +38,5 @@ Gem::Specification.new do |s|
21
38
  s.require_paths = ["lib"]
22
39
 
23
40
  s.add_dependency('rails', '>= 3.0.0')
24
- s.add_dependency('memoist', '~> 0.11.0')
41
+ s.add_dependency('memoist', '~> 0.16.0')
25
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_zipcode_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Blackburn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-21 00:00:00.000000000 Z
12
+ date: 2019-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.11.0
34
+ version: 0.16.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 0.11.0
41
+ version: 0.16.0
42
42
  description: A Ruby gem for looking up and manipulating US postal codes and geocodes.
43
43
  email:
44
44
  - chris [at] midwiretech [dot] com
@@ -48,6 +48,7 @@ extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
50
  - ".gitignore"
51
+ - ".hound.yml"
51
52
  - ".rubocop.yml"
52
53
  - ".rubocop_todo.yml"
53
54
  - ".travis.yml"
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  version: '0'
93
94
  requirements: []
94
95
  rubyforge_project: my_zipcode_gem
95
- rubygems_version: 2.5.2.2
96
+ rubygems_version: 2.5.2.3
96
97
  signing_key:
97
98
  specification_version: 4
98
99
  summary: A Ruby gem to handle all things zipcode.