indonesian-territory-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ require File.expand_path('includes/ruby/provinces', __dir__)
2
+ require File.expand_path('includes/ruby/regencies', __dir__)
3
+ require File.expand_path('includes/ruby/districts', __dir__)
4
+ require File.expand_path('includes/ruby/villages', __dir__)
@@ -0,0 +1,5 @@
1
+ # TODO: update for timestamp
2
+ # Province.update_all(created_at: DateTime.now, updated_at: DateTime.now)
3
+ # Regency.update_all(created_at: DateTime.now, updated_at: DateTime.now)
4
+ # District.update_all(created_at: DateTime.now, updated_at: DateTime.now)
5
+ # Village.update_all(created_at: DateTime.now, updated_at: DateTime.now)
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "indonesian/territory/rails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "indonesian-territory-rails"
8
+ spec.version = Indonesian::Territory::Rails::VERSION
9
+ spec.authors = ["Cahyadi Triyansyah"]
10
+ spec.email = ["sundi3yansyah@gmail.com"]
11
+
12
+ spec.summary = %q{Indonesian Territory for Rails}
13
+ spec.description = %q{Database of Indonesian Territory for Rails}
14
+ spec.homepage = "https://github.com/SunDi3yansyah/indonesian-territory-rails"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 12.3"
28
+ spec.add_development_dependency "minitest", "~> 5.11"
29
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+
4
+ module IndonesianTerritory
5
+ class MigrationGenerator < ActiveRecord::Generators::Base
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ def install
9
+ migration_template 'create_province.rb', 'db/migrate/create_province.rb', force: true
10
+ migration_template 'create_regency.rb', 'db/migrate/create_regency.rb', force: true
11
+ migration_template 'create_district.rb', 'db/migrate/create_district.rb', force: true
12
+ migration_template 'create_village.rb', 'db/migrate/create_village.rb', force: true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module IndonesianTerritory
2
+ class ModelGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../../../app/models', __dir__)
4
+
5
+ def models dir_model = nil
6
+ dist_dir = dir_model.nil? ? 'app/models' : dir_model
7
+
8
+ copy_file 'district.rb', "#{dist_dir}/district.rb", force: true
9
+ copy_file 'province.rb', "#{dist_dir}/province.rb", force: true
10
+ copy_file 'regency.rb', "#{dist_dir}/regency.rb", force: true
11
+ copy_file 'village.rb', "#{dist_dir}/village.rb", force: true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ @migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreateDistrict < @migration_class
9
+ def change
10
+ create_table :districts do |t|
11
+ t.string :name
12
+
13
+ t.timestamps
14
+ end
15
+
16
+ add_reference :districts, :regency, foreign_key: true, after: :id
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ @migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreateProvince < @migration_class
9
+ def change
10
+ create_table :provinces do |t|
11
+ t.string :name
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ @migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreateRegency < @migration_class
9
+ def change
10
+ create_table :regencies do |t|
11
+ t.string :name
12
+
13
+ t.timestamps
14
+ end
15
+
16
+ add_reference :regencies, :province, foreign_key: true, after: :id
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ @migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreateVillage < @migration_class
9
+ def change
10
+ create_table :villages do |t|
11
+ t.string :name
12
+
13
+ t.timestamps
14
+ end
15
+
16
+ add_reference :villages, :district, foreign_key: true, after: :id
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require 'indonesian/territory/rails/version'
2
+
3
+ module Indonesian
4
+ module Territory
5
+ module Rails
6
+ class Error < StandardError; end
7
+
8
+ class << self
9
+ def load!
10
+ if rails?
11
+ register_rails_engine
12
+ end
13
+ end
14
+
15
+ def rails?
16
+ defined?(::Rails)
17
+ end
18
+
19
+ def register_rails_engine
20
+ require "indonesian/territory/rails/engine"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ Indonesian::Territory::Rails.load!
@@ -0,0 +1,8 @@
1
+ module Indonesian
2
+ module Territory
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Indonesian
2
+ module Territory
3
+ module Rails
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ namespace :db do
2
+ namespace :seed do
3
+ Dir[File.expand_path('../../db/seed/*.rb', __dir__)].each do |filename|
4
+ task_name = File.basename(filename, '.rb')
5
+ desc "Seed: #{task_name}"
6
+ task task_name.to_sym => :environment do
7
+ load(filename) if File.exist?(filename)
8
+ end
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: indonesian-territory-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cahyadi Triyansyah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.11'
55
+ description: Database of Indonesian Territory for Rails
56
+ email:
57
+ - sundi3yansyah@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".editorconfig"
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - CONTRIBUTING.md
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - app/models/district.rb
72
+ - app/models/province.rb
73
+ - app/models/regency.rb
74
+ - app/models/village.rb
75
+ - bin/console
76
+ - bin/setup
77
+ - db/seed/includes/ruby/districts.rb
78
+ - db/seed/includes/ruby/provinces.rb
79
+ - db/seed/includes/ruby/regencies.rb
80
+ - db/seed/includes/ruby/villages.rb
81
+ - db/seed/indonesian_territory.rb
82
+ - db/seed/indonesian_territory_sql.rb
83
+ - indonesian-territory-rails.gemspec
84
+ - lib/generators/indonesian_territory/migration_generator.rb
85
+ - lib/generators/indonesian_territory/model_generator.rb
86
+ - lib/generators/indonesian_territory/templates/create_district.rb
87
+ - lib/generators/indonesian_territory/templates/create_province.rb
88
+ - lib/generators/indonesian_territory/templates/create_regency.rb
89
+ - lib/generators/indonesian_territory/templates/create_village.rb
90
+ - lib/indonesian/territory/rails.rb
91
+ - lib/indonesian/territory/rails/engine.rb
92
+ - lib/indonesian/territory/rails/version.rb
93
+ - lib/tasks/indonesian_territory.rake
94
+ homepage: https://github.com/SunDi3yansyah/indonesian-territory-rails
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Indonesian Territory for Rails
117
+ test_files: []