looky-lu 0.0.1 → 0.0.2
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 +8 -8
- data/README.md +34 -8
- data/lib/data/lu/states.rb +16 -54
- data/lib/data/lu/states.yml +66 -0
- data/lib/generators/lookylu/state_data_generator.rb +12 -9
- data/lib/generators/lookylu/state_generator.rb +9 -10
- data/lib/looky-lu/version.rb +1 -1
- data/spec/data/state_data_spec.rb +22 -0
- data/spec/generators/state_data_generator_spec.rb +3 -2
- data/spec/models/state_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2RkZTA3N2Q3YzI0YzcxMzg0NGUwMDUyYTViMTg1YTAzMmNkZmY3Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjlmNmMzNWQxNmZkMTFmOTQxNTJkYjRkZGI4YmJhODEyZGExMTMzZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDU4ZGNlMTU0NzZiM2UzOTM2NGFlNTZmMTZjYjIwMTRiYzMzMDI5MmY1NDNk
|
10
|
+
MTMxNWZhNDc2MjU5NzU4NzQ1ZTZjMmI4NWVlZjA1NTZmZTI2YTY0N2RkMzQ4
|
11
|
+
ZWU2NTNlNWJmYzgyYTRiNTY0MzhmNjJjNGRjZjZiMDE4NDZjODQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTVkMzgyN2Q1NWM2MGI2NzU0NWU1MDNjMTM1NGZlNDAzMzZmMjNiYzVmYzg2
|
14
|
+
NmIzMjNmZjhhOWE3ZDM0Y2Y0N2Y5NmQ4NDZiOTAxNjZmMDMzZTIzNmVmOTgy
|
15
|
+
OGRkODg4MDQ0NmRmMDU4ZmFkMmZmODk2MTk3OThhM2MyMTg1NWM=
|
data/README.md
CHANGED
@@ -2,32 +2,58 @@
|
|
2
2
|
[](https://coveralls.io/r/agapered/looky-lu?branch=master)
|
3
3
|
|
4
4
|
|
5
|
-
## What is it? ##
|
6
|
-
|
7
|
-
looky-lu will generate standard look up data abilities for your rails application
|
8
|
-
|
9
5
|
## What is it for? ##
|
10
6
|
|
11
|
-
|
7
|
+
LookyLu gives you easy ability to generate an ActiveRecord object for lookup data, as well as the ability to populate that object with data.
|
12
8
|
|
13
|
-
|
9
|
+
For example, you need a State object that is an LU table for all of the states in the United States, then this gem is perfect for you.
|
14
10
|
|
15
11
|
## How to use it ##
|
16
12
|
|
17
|
-
|
13
|
+
Using my example above of needing a State object:
|
18
14
|
|
15
|
+
Install LookyLu
|
16
|
+
```
|
17
|
+
gem install looky-lu
|
18
|
+
```
|
19
|
+
Or add to your gemfile
|
20
|
+
```
|
21
|
+
gem 'looky-lu'
|
22
|
+
```
|
23
|
+
|
24
|
+
Generate the ActiveRecord model and the needed migration
|
19
25
|
```
|
20
26
|
rails g lookylu:state
|
27
|
+
```
|
28
|
+
|
29
|
+
Migrate your database
|
30
|
+
```
|
21
31
|
rake db:migrate
|
22
|
-
|
32
|
+
```
|
33
|
+
|
34
|
+
Populate the database with the 50 stats plus D.C.
|
35
|
+
```
|
36
|
+
rails g lookylu:state_data State united_states
|
23
37
|
```
|
24
38
|
|
25
39
|
## Additional Options ##
|
26
40
|
|
41
|
+
For generating the Model and migration
|
27
42
|
```
|
28
43
|
rails g lookylu:state -h
|
29
44
|
```
|
30
45
|
|
46
|
+
For generating the LU data
|
47
|
+
```
|
48
|
+
rails g lookylu:state_data -h
|
49
|
+
```
|
50
|
+
|
51
|
+
## Current LU Data Available ##
|
52
|
+
|
53
|
+
* State
|
54
|
+
* United States
|
55
|
+
* Canada
|
56
|
+
|
31
57
|
|
32
58
|
## Who are you? ##
|
33
59
|
|
data/lib/data/lu/states.rb
CHANGED
@@ -1,60 +1,22 @@
|
|
1
1
|
module LookyLu
|
2
2
|
class States
|
3
3
|
|
4
|
-
def self.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
{name: 'Indiana', abbreviation: 'IN'},
|
21
|
-
{name: 'Iowa', abbreviation: 'IA'},
|
22
|
-
{name: 'Kansas', abbreviation: 'KS'},
|
23
|
-
{name: 'Kentucky', abbreviation: 'KY'},
|
24
|
-
{name: 'Louisiana', abbreviation: 'LA'},
|
25
|
-
{name: 'Maine', abbreviation: 'ME'},
|
26
|
-
{name: 'Maryland', abbreviation: 'MD'},
|
27
|
-
{name: 'Massachusetts', abbreviation: 'MA'},
|
28
|
-
{name: 'Michigan', abbreviation: 'MI'},
|
29
|
-
{name: 'Minnesota', abbreviation: 'MN'},
|
30
|
-
{name: 'Mississippi', abbreviation: 'MS'},
|
31
|
-
{name: 'Missouri', abbreviation: 'MO'},
|
32
|
-
{name: 'Montana', abbreviation: 'MT'},
|
33
|
-
{name: 'Nebraska', abbreviation: 'NE'},
|
34
|
-
{name: 'Nevada', abbreviation: 'NV'},
|
35
|
-
{name: 'New Hampshire', abbreviation: 'NH'},
|
36
|
-
{name: 'New Jersey', abbreviation: 'NJ'},
|
37
|
-
{name: 'New Mexico', abbreviation: 'NM'},
|
38
|
-
{name: 'New York', abbreviation: 'NY'},
|
39
|
-
{name: 'North Carolina', abbreviation: 'NC'},
|
40
|
-
{name: 'North Dakota', abbreviation: 'ND'},
|
41
|
-
{name: 'Ohio', abbreviation: 'OH'},
|
42
|
-
{name: 'Oklahoma', abbreviation: 'OK'},
|
43
|
-
{name: 'Oregon', abbreviation: 'OR'},
|
44
|
-
{name: 'Pennsylvania', abbreviation: 'PA'},
|
45
|
-
{name: 'Rhode Island', abbreviation: 'RI'},
|
46
|
-
{name: 'South Carolina', abbreviation: 'SC'},
|
47
|
-
{name: 'South Dakota', abbreviation: 'SD'},
|
48
|
-
{name: 'Tennessee', abbreviation: 'TN'},
|
49
|
-
{name: 'Texas', abbreviation: 'TX'},
|
50
|
-
{name: 'Utah', abbreviation: 'UT'},
|
51
|
-
{name: 'Vermont', abbreviation: 'VT'},
|
52
|
-
{name: 'Virginia', abbreviation: 'VA'},
|
53
|
-
{name: 'Washington', abbreviation: 'WA'},
|
54
|
-
{name: 'West Virginia', abbreviation: 'WV'},
|
55
|
-
{name: 'Wisconsin', abbreviation: 'WI'},
|
56
|
-
{name: 'Wyoming', abbreviation: 'WY'}
|
57
|
-
]
|
4
|
+
def self.from_country(country_name)
|
5
|
+
|
6
|
+
yml = YAML.load_file(File.dirname(__FILE__) + "/states.yml")
|
7
|
+
|
8
|
+
if country_name == 'all'
|
9
|
+
states = []
|
10
|
+
|
11
|
+
yml.each do |k,v|
|
12
|
+
states += v
|
13
|
+
end
|
14
|
+
|
15
|
+
else
|
16
|
+
states = yml[country_name]
|
17
|
+
end
|
18
|
+
|
19
|
+
states
|
58
20
|
end
|
59
21
|
|
60
22
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
united_states: [
|
2
|
+
{name: 'Alabama', abbreviation: 'AL'},
|
3
|
+
{name: 'Alaska', abbreviation: 'AK'},
|
4
|
+
{name: 'Arizona', abbreviation: 'AZ'},
|
5
|
+
{name: 'Arkansas', abbreviation: 'AR'},
|
6
|
+
{name: 'California', abbreviation: 'CA'},
|
7
|
+
{name: 'Colorado', abbreviation: 'CO'},
|
8
|
+
{name: 'Connecticut', abbreviation: 'CT'},
|
9
|
+
{name: 'Delaware', abbreviation: 'DE'},
|
10
|
+
{name: 'District of Columbia', abbreviation: 'DC'},
|
11
|
+
{name: 'Florida', abbreviation: 'FL'},
|
12
|
+
{name: 'Georgia', abbreviation: 'GA'},
|
13
|
+
{name: 'Hawaii', abbreviation: 'HI'},
|
14
|
+
{name: 'Idaho', abbreviation: 'ID'},
|
15
|
+
{name: 'Illinois', abbreviation: 'IL'},
|
16
|
+
{name: 'Indiana', abbreviation: 'IN'},
|
17
|
+
{name: 'Iowa', abbreviation: 'IA'},
|
18
|
+
{name: 'Kansas', abbreviation: 'KS'},
|
19
|
+
{name: 'Kentucky', abbreviation: 'KY'},
|
20
|
+
{name: 'Louisiana', abbreviation: 'LA'},
|
21
|
+
{name: 'Maine', abbreviation: 'ME'},
|
22
|
+
{name: 'Maryland', abbreviation: 'MD'},
|
23
|
+
{name: 'Massachusetts', abbreviation: 'MA'},
|
24
|
+
{name: 'Michigan', abbreviation: 'MI'},
|
25
|
+
{name: 'Minnesota', abbreviation: 'MN'},
|
26
|
+
{name: 'Mississippi', abbreviation: 'MS'},
|
27
|
+
{name: 'Missouri', abbreviation: 'MO'},
|
28
|
+
{name: 'Montana', abbreviation: 'MT'},
|
29
|
+
{name: 'Nebraska', abbreviation: 'NE'},
|
30
|
+
{name: 'Nevada', abbreviation: 'NV'},
|
31
|
+
{name: 'New Hampshire', abbreviation: 'NH'},
|
32
|
+
{name: 'New Jersey', abbreviation: 'NJ'},
|
33
|
+
{name: 'New Mexico', abbreviation: 'NM'},
|
34
|
+
{name: 'New York', abbreviation: 'NY'},
|
35
|
+
{name: 'North Carolina', abbreviation: 'NC'},
|
36
|
+
{name: 'North Dakota', abbreviation: 'ND'},
|
37
|
+
{name: 'Ohio', abbreviation: 'OH'},
|
38
|
+
{name: 'Oklahoma', abbreviation: 'OK'},
|
39
|
+
{name: 'Oregon', abbreviation: 'OR'},
|
40
|
+
{name: 'Pennsylvania', abbreviation: 'PA'},
|
41
|
+
{name: 'Rhode Island', abbreviation: 'RI'},
|
42
|
+
{name: 'South Carolina', abbreviation: 'SC'},
|
43
|
+
{name: 'South Dakota', abbreviation: 'SD'},
|
44
|
+
{name: 'Tennessee', abbreviation: 'TN'},
|
45
|
+
{name: 'Texas', abbreviation: 'TX'},
|
46
|
+
{name: 'Utah', abbreviation: 'UT'},
|
47
|
+
{name: 'Vermont', abbreviation: 'VT'},
|
48
|
+
{name: 'Virginia', abbreviation: 'VA'},
|
49
|
+
{name: 'Washington', abbreviation: 'WA'},
|
50
|
+
{name: 'West Virginia', abbreviation: 'WV'},
|
51
|
+
{name: 'Wisconsin', abbreviation: 'WI'},
|
52
|
+
{name: 'Wyoming', abbreviation: 'WY'}
|
53
|
+
]
|
54
|
+
|
55
|
+
canada: [
|
56
|
+
{name: 'Alberta', abbreviation: 'AB'},
|
57
|
+
{name: 'British Columbia', abbreviation: 'BC'},
|
58
|
+
{name: 'Manitoba', abbreviation: 'MB'},
|
59
|
+
{name: 'New Brunswick', abbreviation: 'NB'},
|
60
|
+
{name: 'Newfoundland and Labrador', abbreviation: 'NL'},
|
61
|
+
{name: 'Nova Scotia', abbreviation: 'NS'},
|
62
|
+
{name: 'Ontario', abbreviation: 'ON'},
|
63
|
+
{name: 'Prince Edward Island', abbreviation: 'PE'},
|
64
|
+
{name: 'Quebec', abbreviation: 'QC'},
|
65
|
+
{name: 'Saskatchewan', abbreviation: 'SK'}
|
66
|
+
]
|
@@ -4,6 +4,7 @@ require 'generators/lookylu/base_generator'
|
|
4
4
|
module Lookylu
|
5
5
|
module Generators
|
6
6
|
class StateDataGenerator < Lookylu::Generators::BaseGenerator
|
7
|
+
class_option :country_name, type: :string, default: 'united_states', desc: "Choose a country: united_states, canada, or all."
|
7
8
|
|
8
9
|
def populate_data
|
9
10
|
connect_to_db
|
@@ -11,10 +12,12 @@ module Lookylu
|
|
11
12
|
raise "Table #{plural_name} does not exist. Please build the needed migration and migrate your database"
|
12
13
|
end
|
13
14
|
begin
|
14
|
-
class_object = eval(object_name)
|
15
|
-
|
16
|
-
|
15
|
+
class_object = eval(object_name.capitalize)
|
16
|
+
|
17
|
+
LookyLu::States.from_country(options.country_name).each do |data|
|
18
|
+
class_object.where(data).first_or_create
|
17
19
|
end
|
20
|
+
|
18
21
|
puts "There are now #{pluralize(class_object.count, model_name)}"
|
19
22
|
rescue => e
|
20
23
|
raise "Could not find object for #{model_name}"
|
@@ -24,13 +27,13 @@ module Lookylu
|
|
24
27
|
|
25
28
|
private
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
def connect_to_db
|
31
|
+
ActiveRecord::Base.establish_connection db_config
|
32
|
+
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
def db_config
|
35
|
+
Rails.configuration.database_configuration[::Rails.env]
|
36
|
+
end
|
34
37
|
|
35
38
|
end
|
36
39
|
end
|
@@ -9,7 +9,6 @@ module Lookylu
|
|
9
9
|
|
10
10
|
class_option :model, :type => :boolean, :default => true, :desc => "Generate a default model object."
|
11
11
|
|
12
|
-
|
13
12
|
def generate_migration
|
14
13
|
if Dir.glob(migration_location('*')).empty?
|
15
14
|
template "states_migration.erb", migration_location(next_migration_number)
|
@@ -26,17 +25,17 @@ module Lookylu
|
|
26
25
|
|
27
26
|
private
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def next_migration_number
|
29
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def migration_location version
|
33
|
+
"db/migrate/#{version}_lookylu_create_#{plural_name}.rb"
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def model_location
|
37
|
+
"app/models/#{model_name}.rb"
|
38
|
+
end
|
40
39
|
|
41
40
|
end
|
42
41
|
end
|
data/lib/looky-lu/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'data/lu/states'
|
3
|
+
|
4
|
+
describe LookyLu::States do
|
5
|
+
|
6
|
+
describe 'from country' do
|
7
|
+
|
8
|
+
it 'should pull only united states' do
|
9
|
+
LookyLu::States.from_country('united_states').count.should == 51
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should pull only canada' do
|
13
|
+
LookyLu::States.from_country('canada').count.should == 10
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should pull all' do
|
17
|
+
LookyLu::States.from_country('all').count.should == 61
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -38,10 +38,11 @@ describe Lookylu::Generators::StateDataGenerator do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should add object data' do
|
41
|
-
Object.any_instance.should_receive(:puts).with("There are now #{@gen.pluralize(LookyLu::States.united_states.count, @gen.plural_model_name)}")
|
41
|
+
Object.any_instance.should_receive(:puts).with("There are now #{@gen.pluralize(LookyLu::States.from_country('united_states').count, @gen.plural_model_name)}")
|
42
42
|
|
43
|
+
@gen.options.country_name = 'united_states'
|
43
44
|
@gen.populate_data
|
44
|
-
State.count.should == LookyLu::States.united_states.count
|
45
|
+
State.count.should == LookyLu::States.from_country('united_states').count
|
45
46
|
end
|
46
47
|
|
47
48
|
it 'should not fail if object does not exist' do
|
data/spec/models/state_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -18,11 +18,6 @@ require 'rails/all'
|
|
18
18
|
require 'rails/generators'
|
19
19
|
require "rails/test_help"
|
20
20
|
|
21
|
-
|
22
|
-
ActiveRecord::Base.establish_connection(YAML.load_file("spec/support/database.yml")[ENV['RAILS_ENV']])
|
23
|
-
load 'spec/support/schema.rb'
|
24
|
-
|
25
|
-
|
26
21
|
if ENV['RCOV'] == 'true'
|
27
22
|
require 'simplecov-rcov'
|
28
23
|
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
@@ -53,3 +48,7 @@ RSpec.configure do |config|
|
|
53
48
|
end
|
54
49
|
|
55
50
|
end
|
51
|
+
|
52
|
+
connect_to_db
|
53
|
+
load_db
|
54
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: looky-lu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Hopp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- Rakefile
|
196
196
|
- lib/app/models/State.rb
|
197
197
|
- lib/data/lu/states.rb
|
198
|
+
- lib/data/lu/states.yml
|
198
199
|
- lib/db/migrations/create_states.rb.erb
|
199
200
|
- lib/generators/lookylu/base_generator.rb
|
200
201
|
- lib/generators/lookylu/state_data_generator.rb
|
@@ -205,6 +206,7 @@ files:
|
|
205
206
|
- lib/looky-lu/engine.rb
|
206
207
|
- lib/looky-lu/version.rb
|
207
208
|
- looky-lu.gemspec
|
209
|
+
- spec/data/state_data_spec.rb
|
208
210
|
- spec/generators/base_generator_spec.rb
|
209
211
|
- spec/generators/state_data_generator_spec.rb
|
210
212
|
- spec/generators/state_generator_spec.rb
|
@@ -237,6 +239,7 @@ signing_key:
|
|
237
239
|
specification_version: 4
|
238
240
|
summary: ''
|
239
241
|
test_files:
|
242
|
+
- spec/data/state_data_spec.rb
|
240
243
|
- spec/generators/base_generator_spec.rb
|
241
244
|
- spec/generators/state_data_generator_spec.rb
|
242
245
|
- spec/generators/state_generator_spec.rb
|