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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb7a4ba9afffa06e9951668c3b118fff38af7384
4
- data.tar.gz: 6d1d2d68a4f9cfefebcf6b9a80f0554d6fec9b8a
3
+ metadata.gz: 9e28ca0436e1c02e7842fda2168254af0c1a095e
4
+ data.tar.gz: a1b649576d71c22856263875df33c28c9e190df8
5
5
  SHA512:
6
- metadata.gz: 931fa75b8e33bf6692cd59a6cb1a074341bef82be9052a71a1570f38208153bea10a0f20ff788f9a7132db51b18ef49bd4fc9e066542cd34faca29908c46ef45
7
- data.tar.gz: 9cc9a236a8cf053e9aea0b55549c616fa673ffb56dd3d991e6e26bf0c2db58756ca02039a9522f0353f416f83f1ddc4ba34ade89506eec3e658f00a2f67de777
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 the generator:
18
+ After you install the gem, you need run below tasks one by one:
19
19
 
20
- rails g china_region_fu:install
20
+ 1. Copy migration file to your app.
21
21
 
22
- It will:
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
- Now you have there ActiveRecord modules: `Province`, `City`, `District`.
24
+ 2. Run db:migrate to create region tables.
29
25
 
30
- Region data if from [ChinaRegionData](https://github.com/Xuhao/china_region_data), check it out to see what kind of data you have now.
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
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_dependency 'activesupport'
25
25
  spec.add_dependency 'actionpack'
26
+ spec.add_dependency 'httparty'
26
27
  end
@@ -31,7 +31,7 @@ class CreateChinaRegionTables < ActiveRecord::Migration
31
31
  add_index :cities, :pinyin_abbr
32
32
  end
33
33
 
34
- unless table_exists? 'districts'
34
+ unless table_exists? 'districts'
35
35
  create_table :districts do |t|
36
36
  t.string :name
37
37
  t.integer :city_id
@@ -1,3 +1,3 @@
1
1
  module ChinaRegionFu
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,10 +1,35 @@
1
- require 'yaml'
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
- file_path = File.join(Rails.root, 'config', 'regions.yml')
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.5
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-07-20 00:00:00.000000000 Z
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.3
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,8 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- rails generate china_region:fu:migration Thing
6
-
7
- This will create:
8
- db/migrate/create_china_region_tables.rb
@@ -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