ruian 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +2 -0
  7. data/example/.gitignore +15 -0
  8. data/example/Gemfile +28 -0
  9. data/example/README.md +23 -0
  10. data/example/Rakefile +7 -0
  11. data/example/app/assets/images/rails.png +0 -0
  12. data/example/app/assets/javascripts/application.js +13 -0
  13. data/example/app/assets/stylesheets/application.css +13 -0
  14. data/example/app/controllers/application_controller.rb +3 -0
  15. data/example/app/helpers/application_helper.rb +2 -0
  16. data/example/app/mailers/.gitkeep +0 -0
  17. data/example/app/models/.gitkeep +0 -0
  18. data/example/app/models/address.rb +5 -0
  19. data/example/app/models/address/city.rb +7 -0
  20. data/example/app/models/address/city_part.rb +7 -0
  21. data/example/app/models/address/county.rb +3 -0
  22. data/example/app/models/address/county_name_count.rb +7 -0
  23. data/example/app/models/address/momc_name.rb +5 -0
  24. data/example/app/models/address/mop_name.rb +5 -0
  25. data/example/app/models/address/name.rb +18 -0
  26. data/example/app/models/address/name_type.rb +6 -0
  27. data/example/app/models/address/place.rb +13 -0
  28. data/example/app/models/address/region.rb +3 -0
  29. data/example/app/models/address/region_name_count.rb +7 -0
  30. data/example/app/models/address/street_name.rb +5 -0
  31. data/example/app/views/layouts/application.html.erb +14 -0
  32. data/example/config.ru +4 -0
  33. data/example/config/application.rb +63 -0
  34. data/example/config/boot.rb +6 -0
  35. data/example/config/database.yml +25 -0
  36. data/example/config/environment.rb +5 -0
  37. data/example/config/environments/development.rb +32 -0
  38. data/example/config/environments/production.rb +54 -0
  39. data/example/config/environments/test.rb +37 -0
  40. data/example/config/initializers/backtrace_silencers.rb +7 -0
  41. data/example/config/initializers/inflections.rb +15 -0
  42. data/example/config/initializers/mime_types.rb +5 -0
  43. data/example/config/initializers/secret_token.rb +7 -0
  44. data/example/config/initializers/session_store.rb +8 -0
  45. data/example/config/initializers/wrap_parameters.rb +14 -0
  46. data/example/config/locales/en.yml +5 -0
  47. data/example/config/routes.rb +58 -0
  48. data/example/db/migrate/20140418190407_create_tables.rb +170 -0
  49. data/example/db/schema.rb +182 -0
  50. data/example/db/seeds.rb +7 -0
  51. data/example/lib/assets/.gitkeep +0 -0
  52. data/example/lib/importer.rb +163 -0
  53. data/example/lib/tasks/.gitkeep +0 -0
  54. data/example/lib/tasks/ruian.rake +4 -0
  55. data/example/log/.gitkeep +0 -0
  56. data/example/public/404.html +26 -0
  57. data/example/public/422.html +26 -0
  58. data/example/public/500.html +25 -0
  59. data/example/public/favicon.ico +0 -0
  60. data/example/public/index.html +241 -0
  61. data/example/public/robots.txt +5 -0
  62. data/example/script/rails +6 -0
  63. data/example/vendor/assets/javascripts/.gitkeep +0 -0
  64. data/example/vendor/assets/stylesheets/.gitkeep +0 -0
  65. data/example/vendor/plugins/.gitkeep +0 -0
  66. data/fixtures/counties.csv +92 -0
  67. data/fixtures/vazby-cr.csv +15072 -0
  68. data/fixtures/vazby-okresy-cr.csv +15072 -0
  69. data/lib/ruian.rb +86 -0
  70. data/lib/ruian/enum_updater.rb +59 -0
  71. data/lib/ruian/fetcher.rb +71 -0
  72. data/lib/ruian/files_updater.rb +54 -0
  73. data/lib/ruian/importer.rb +21 -0
  74. data/lib/ruian/model.rb +10 -0
  75. data/lib/ruian/model/county.rb +6 -0
  76. data/lib/ruian/model/county_integration.rb +6 -0
  77. data/lib/ruian/model/region.rb +6 -0
  78. data/lib/ruian/model/region_integration.rb +6 -0
  79. data/lib/ruian/model/row.rb +9 -0
  80. data/lib/ruian/parser.rb +12 -0
  81. data/lib/ruian/queue.rb +24 -0
  82. data/lib/ruian/railtie.rb +9 -0
  83. data/lib/ruian/tasks/ruian.rake +18 -0
  84. data/lib/ruian/version.rb +3 -0
  85. data/ruian.gemspec +26 -0
  86. metadata +198 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d0d41e4ce58585d4ebd8ada6e6e1f921bbebf2d
4
+ data.tar.gz: e15fcd0ab484ce45fbbb3519556aa320ca294d68
5
+ SHA512:
6
+ metadata.gz: 5f3dfcff52eaf83c942715e2ec2dd348639c2c7bef051a0d3997864f77ccc651a44e5841e4d5a8fa7f4477792bea5b96fb47b594ef3b53ccff441f282a6ffe0d
7
+ data.tar.gz: a3ff4e3a3b6396b8e456e8dd9a645616bcb3946c408118e36deee0c75f5ab8733b75d3083e1a5d75727707b5bcbb3e7b48efd3ac068472cb7f36e964a46772da
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ fixtures/CSV
24
+ fixtures counties.csv
25
+ fixtures/regions.csv
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruian.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Josef Šimánek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Ruian
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ruian'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ruian
18
+
19
+ ## Usage
20
+
21
+ See example directory.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/simi/ruian/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ Dir["lib/tasks/*.rake"].each { |ext| load ext }
@@ -0,0 +1,15 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
@@ -0,0 +1,28 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '3.2.16'
4
+
5
+ # Bundle edge Rails instead:
6
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+
8
+ gem 'sqlite3'
9
+
10
+ gem 'ruian', path: '../'
11
+ gem 'jtsk', '0.0.2'
12
+
13
+ gem 'activerecord-import', '~> 0.3.0'
14
+
15
+ # To use ActiveModel has_secure_password
16
+ # gem 'bcrypt-ruby', '~> 3.0.0'
17
+
18
+ # To use Jbuilder templates for JSON
19
+ # gem 'jbuilder'
20
+
21
+ # Use unicorn as the app server
22
+ # gem 'unicorn'
23
+
24
+ # Deploy with Capistrano
25
+ # gem 'capistrano'
26
+
27
+ # To use debugger
28
+ # gem 'debugger'
@@ -0,0 +1,23 @@
1
+ # RUIAN Rails importer example
2
+
3
+ ## Install
4
+
5
+ ```
6
+ bundle install
7
+ bundle exec rake db:setup
8
+ ```
9
+
10
+ ## Start import
11
+
12
+ ```
13
+ bundle rake ruian:update_all
14
+ bundle rake ruian:import
15
+ ```
16
+
17
+ ## How it works
18
+
19
+ See example lib/tasks/ruian.rake for details about ruian:import task. Mainly example/lib/importer.rb is used for importing.
20
+
21
+ 'Interface' is defined in lib/ruian/importer.rb.
22
+
23
+ Update tasks are defined in lib/tasks/ruian.rake.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Example::Application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ module Address
2
+ def self.table_name_prefix
3
+ 'address_'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class Address::City < ActiveRecord::Base
2
+ belongs_to :county
3
+ belongs_to :region
4
+ attr_accessible :code, :name
5
+
6
+ validates_presence_of :code, :name
7
+ end
@@ -0,0 +1,7 @@
1
+ class Address::CityPart < ActiveRecord::Base
2
+ belongs_to :city
3
+
4
+ attr_accessible :code, :name, :city, :city_id
5
+
6
+ validates_presence_of :city_id, :code, :name
7
+ end
@@ -0,0 +1,3 @@
1
+ class Address::County < ActiveRecord::Base
2
+ attr_accessible :code, :name
3
+ end
@@ -0,0 +1,7 @@
1
+ class Address::CountyNameCount < ActiveRecord::Base
2
+ belongs_to :county
3
+ belongs_to :name
4
+ attr_accessible :count, :county_id, :name_id
5
+
6
+ validates_presence_of :county_id, :name_id
7
+ end
@@ -0,0 +1,5 @@
1
+ class Address::MomcName < ActiveRecord::Base
2
+ attr_accessible :name
3
+
4
+ validates_presence_of :name
5
+ end
@@ -0,0 +1,5 @@
1
+ class Address::MopName < ActiveRecord::Base
2
+ attr_accessible :name
3
+
4
+ validates_presence_of :name
5
+ end
@@ -0,0 +1,18 @@
1
+ class Address::Name < ActiveRecord::Base
2
+ attr_accessible :name, :type
3
+ self.inheritance_column = :sti_type
4
+
5
+ has_many :county_name_counts, :dependent => :delete_all
6
+ has_many :region_name_counts, :dependent => :delete_all
7
+
8
+ has_enum :type, :class_name => 'Address::NameType'
9
+
10
+ def self.find_and_touch(name, type)
11
+ if n = where(:type => type, :name => name).first
12
+ n.touch
13
+ else
14
+ n = create!(:type => type, :name => name)
15
+ end
16
+ n
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ module Address
2
+ class NameType < Hex::Enum
3
+ FIRST_NAME = new(1, 'first_name')
4
+ LAST_NAME = new(2, 'last_name')
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ class Address::Place < ActiveRecord::Base
2
+ belongs_to :street_name
3
+ belongs_to :mop_name
4
+ belongs_to :momc_name
5
+ belongs_to :city
6
+ belongs_to :city_part
7
+
8
+ attr_accessible :e, :p, :o, :zip, :code, :street_name, :street_name_id, :mop_name, :mop_name_id,
9
+ :momc_name, :momc_name_id, :city, :city_id, :city_part, :city_part_id, :latitude, :longitude
10
+
11
+ validates_presence_of :code, :city_id
12
+ validates_format_of :zip, :with => %r(\A\d{5}\z), :allow_blank => true
13
+ end
@@ -0,0 +1,3 @@
1
+ class Address::Region < ActiveRecord::Base
2
+ attr_accessible :ruian_code, :ruian_name, :mvcr_code, :mvcr_name
3
+ end
@@ -0,0 +1,7 @@
1
+ class Address::RegionNameCount < ActiveRecord::Base
2
+ belongs_to :region
3
+ belongs_to :name
4
+ attr_accessible :count, :region_id, :name_id
5
+
6
+ validates_presence_of :name_id, :region_id
7
+ end
@@ -0,0 +1,5 @@
1
+ class Address::StreetName < ActiveRecord::Base
2
+ attr_accessible :name
3
+
4
+ validates_presence_of :name
5
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Example</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Example::Application
@@ -0,0 +1,63 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "active_resource/railtie"
8
+ # require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ if defined?(Bundler)
12
+ # If you precompile assets before deploying to production, use this line
13
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
14
+ # If you want your assets lazily compiled in production, use this line
15
+ # Bundler.require(:default, :assets, Rails.env)
16
+ end
17
+
18
+ module Example
19
+ class Application < Rails::Application
20
+ # Settings in config/environments/* take precedence over those specified here.
21
+ # Application configuration should go into files in config/initializers
22
+ # -- all .rb files in that directory are automatically loaded.
23
+
24
+ # Custom directories with classes and modules you want to be autoloadable.
25
+ config.autoload_paths += %W(#{config.root}/lib)
26
+
27
+ # Only load the plugins named here, in the order given (default is alphabetical).
28
+ # :all can be used as a placeholder for all plugins not explicitly named.
29
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
30
+
31
+ # Activate observers that should always be running.
32
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
+
34
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
36
+ # config.time_zone = 'Central Time (US & Canada)'
37
+
38
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
40
+ # config.i18n.default_locale = :de
41
+
42
+ # Configure the default encoding used in templates for Ruby 1.9.
43
+ config.encoding = "utf-8"
44
+
45
+ # Configure sensitive parameters which will be filtered from the log file.
46
+ config.filter_parameters += [:password]
47
+
48
+ # Enable escaping HTML in JSON.
49
+ config.active_support.escape_html_entities_in_json = true
50
+
51
+ # Use SQL instead of Active Record's schema dumper when creating the database.
52
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
53
+ # like if you have constraints or database-specific column types
54
+ # config.active_record.schema_format = :sql
55
+
56
+ # Enforce whitelist mode for mass assignment.
57
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
58
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
59
+ # parameters by using an attr_accessible or attr_protected declaration.
60
+ config.active_record.whitelist_attributes = true
61
+
62
+ end
63
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000