china_region_fu 0.0.5 → 0.0.6
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 +4 -4
- data/README.md +20 -10
- data/china_region_fu.gemspec +1 -0
- data/{lib/generators/china_region_fu/install/templates/migration.rb → db/migrate/20111111111111_create_china_region_tables.rb} +1 -1
- data/lib/china_region_fu/version.rb +1 -1
- data/lib/tasks/region.rake +27 -2
- metadata +18 -6
- data/lib/generators/china_region_fu/install/USAGE +0 -8
- data/lib/generators/china_region_fu/install/install_generator.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e28ca0436e1c02e7842fda2168254af0c1a095e
|
4
|
+
data.tar.gz: a1b649576d71c22856263875df33c28c9e190df8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed31c16f389c36bbda4ecf00b40e9629f0b9962773c1849beba67677b48f94f16bfc8f7d16a3e9ff215354cc45c6cc75f7f968ad23dde0639f4db8ad105f0ea5
|
7
|
+
data.tar.gz: 77c751addd30b359f6bea919f6cd278d6f80d888e8e472ca9a96a5d4fbc2eec655ef6ab8096d6fe24a8f2b7190ff7c674c9fa08345b78d40d4d7474f5d442f66
|
data/README.md
CHANGED
@@ -15,26 +15,36 @@ Run bundler command to install the gem:
|
|
15
15
|
|
16
16
|
bundle install
|
17
17
|
|
18
|
-
After you install the gem, you need run
|
18
|
+
After you install the gem, you need run below tasks one by one:
|
19
19
|
|
20
|
-
|
20
|
+
1. Copy migration file to your app.
|
21
21
|
|
22
|
-
|
23
|
-
* Generate `db/migrate/<timestamp>create_china_region_tables.rb` migrate file to your app.
|
24
|
-
* Download [https://github.com/Xuhao/china_region_data/raw/master/regions.yml](https://github.com/Xuhao/china_region_data/raw/master/regions.yml) to config/regions.yml.
|
25
|
-
* Run `rake db:migrate`.
|
26
|
-
* Run `rake region:import`.
|
22
|
+
<pre>rake china_region_fu_engine:install:migrations</pre>
|
27
23
|
|
28
|
-
|
24
|
+
2. Run db:migrate to create region tables.
|
29
25
|
|
30
|
-
|
26
|
+
<pre>rake db:migrate</pre>
|
27
|
+
|
28
|
+
3. Download the latest regions.yml form [github](https://raw.github.com/Xuhao/china_region_data/master/regions.yml).
|
29
|
+
|
30
|
+
<pre>rake region:download</pre>
|
31
|
+
|
32
|
+
4. Import regions to database.
|
33
|
+
|
34
|
+
<pre>rake region:import</pre>
|
35
|
+
|
36
|
+
You also can use below task to do the same things as four tasks above:
|
37
|
+
|
38
|
+
rake region:install
|
39
|
+
|
40
|
+
Region data is from [ChinaRegionData](https://github.com/Xuhao/china_region_data), check it out to see what kind of data you have now.
|
31
41
|
|
32
42
|
If you want to customize the region modules you can run the generator:
|
33
43
|
|
34
44
|
rails g china_region_fu:models
|
35
45
|
|
36
46
|
This will create:
|
37
|
-
|
47
|
+
|
38
48
|
create app/models/province.rb
|
39
49
|
create app/models/city.rb
|
40
50
|
create app/models/district.rb
|
data/china_region_fu.gemspec
CHANGED
data/lib/tasks/region.rake
CHANGED
@@ -1,10 +1,35 @@
|
|
1
|
-
require '
|
1
|
+
require 'httparty'
|
2
2
|
|
3
3
|
namespace :region do
|
4
4
|
|
5
|
+
desc 'Install china region fu'
|
6
|
+
task :install do
|
7
|
+
Rake::Task['china_region_fu_engine:install:migrations'].invoke
|
8
|
+
Rake::Task['db:migrate'].invoke
|
9
|
+
Rake::Task['region:download'].invoke
|
10
|
+
Rake::Task['region:import'].invoke
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Download regions.yml from https://raw.github.com/Xuhao/china_region_data/master/regions.yml'
|
14
|
+
task :download do
|
15
|
+
begin
|
16
|
+
remote_url = 'https://raw.github.com/Xuhao/china_region_data/master/regions.yml'
|
17
|
+
puts 'Downloading ...'
|
18
|
+
File.open(Rails.root.join('config', 'regions.yml'), 'wb') { |f| f.write(HTTParty.get(remote_url).body)}
|
19
|
+
puts "Done! File located at: \e[32mconfig/regions.yml\e[0m"
|
20
|
+
rescue
|
21
|
+
puts "\e[31mWarnning!!!\e[0m"
|
22
|
+
puts "Download \e[33mregions.yml\e[0m failed!"
|
23
|
+
puts ''
|
24
|
+
puts "You need download \e[33mregions.yml\e[0m by hand from:"
|
25
|
+
puts "\e[32mhttps://github.com/Xuhao/china_region_data/raw/master/regions.yml\e[0m"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
5
29
|
desc "Import region data to database from config/regions.yml"
|
6
30
|
task :import => :environment do
|
7
|
-
|
31
|
+
puts 'Importing ...'
|
32
|
+
file_path = Rails.root.join('config', 'regions.yml')
|
8
33
|
regions = File.open(file_path) { |file| YAML.load(file) }
|
9
34
|
cleanup_regins
|
10
35
|
load_to_db(regions)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: china_region_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xuhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: httparty
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: China region Ruby on rails interface
|
84
98
|
email:
|
85
99
|
- xuhao@rubyfans.com
|
@@ -100,6 +114,7 @@ files:
|
|
100
114
|
- app/models/province.rb
|
101
115
|
- china_region_fu.gemspec
|
102
116
|
- config/routes.rb
|
117
|
+
- db/migrate/20111111111111_create_china_region_tables.rb
|
103
118
|
- lib/china_region_fu.rb
|
104
119
|
- lib/china_region_fu/engine.rb
|
105
120
|
- lib/china_region_fu/exceptions.rb
|
@@ -108,9 +123,6 @@ files:
|
|
108
123
|
- lib/china_region_fu/helpers/simple_form.rb
|
109
124
|
- lib/china_region_fu/helpers/utilities.rb
|
110
125
|
- lib/china_region_fu/version.rb
|
111
|
-
- lib/generators/china_region_fu/install/USAGE
|
112
|
-
- lib/generators/china_region_fu/install/install_generator.rb
|
113
|
-
- lib/generators/china_region_fu/install/templates/migration.rb
|
114
126
|
- lib/generators/china_region_fu/models/USAGE
|
115
127
|
- lib/generators/china_region_fu/models/models_generator.rb
|
116
128
|
- lib/tasks/region.rake
|
@@ -136,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
148
|
version: '0'
|
137
149
|
requirements: []
|
138
150
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.0.
|
151
|
+
rubygems_version: 2.0.6
|
140
152
|
signing_key:
|
141
153
|
specification_version: 4
|
142
154
|
summary: China region Ruby on rails interface
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module ChinaRegionFu
|
2
|
-
class InstallGenerator < Rails::Generators::Base
|
3
|
-
include Rails::Generators::Migration
|
4
|
-
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
|
6
|
-
def copy_migration_file
|
7
|
-
migration_template "migration.rb", "db/migrate/create_china_region_tables.rb"
|
8
|
-
end
|
9
|
-
|
10
|
-
desc "Download https://github.com/Xuhao/china_region_data/raw/master/regions.yml to config/regions.yml."
|
11
|
-
def download_region_config_file
|
12
|
-
get 'https://github.com/Xuhao/china_region_data/raw/master/regions.yml', 'config/regions.yml'
|
13
|
-
end
|
14
|
-
|
15
|
-
def execute_migrate
|
16
|
-
rake("db:migrate")
|
17
|
-
end
|
18
|
-
|
19
|
-
def import_region_to_data
|
20
|
-
rake('region:import')
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.next_migration_number(dirname)
|
24
|
-
if ActiveRecord::Base.timestamped_migrations
|
25
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
26
|
-
else
|
27
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|