pan_domain 0.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +160 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +21 -0
- data/app/models/pan_domain/human/blood_classification_system.rb +35 -0
- data/app/models/pan_domain/human/blood_group_name.rb +25 -0
- data/bin/console +14 -0
- data/bin/pan_domain +4 -0
- data/bin/rails +25 -0
- data/bin/setup +8 -0
- data/db/human_domain/seeds.rb +28 -0
- data/db/migrate/human_domain/0001_create_blood_classification_systems.rb +17 -0
- data/db/migrate/human_domain/0002_create_blood_group_names.rb +20 -0
- data/db/seeds.rb +21 -0
- data/lib/generators/human_domain/generate/migrations_generator.rb +49 -0
- data/lib/pan_domain.rb +6 -0
- data/lib/pan_domain/cli.rb +53 -0
- data/lib/pan_domain/engine.rb +5 -0
- data/lib/pan_domain/human/engine.rb +11 -0
- data/lib/pan_domain/version.rb +3 -0
- data/lib/tasks/human_domain.rake +45 -0
- data/lib/tasks/pan_domain.rake +23 -0
- data/pan_domain.gemspec +44 -0
- data/spec/lib/generators/test_generate_migrations_generator.rb +48 -0
- data/spec/lib/pan_domain/cli_spec.rb +53 -0
- data/spec/pan_domain_spec.rb +5 -0
- data/spec/sample_app/app/channels/application_cable/channel.rb +4 -0
- data/spec/sample_app/app/channels/application_cable/connection.rb +4 -0
- data/spec/sample_app/app/controllers/application_controller.rb +2 -0
- data/spec/sample_app/app/helpers/application_helper.rb +2 -0
- data/spec/sample_app/app/jobs/application_job.rb +2 -0
- data/spec/sample_app/app/mailers/application_mailer.rb +4 -0
- data/spec/sample_app/app/models/application_record.rb +3 -0
- data/spec/sample_app/config/application.rb +29 -0
- data/spec/sample_app/config/boot.rb +5 -0
- data/spec/sample_app/config/environment.rb +5 -0
- data/spec/sample_app/config/environments/development.rb +61 -0
- data/spec/sample_app/config/environments/production.rb +94 -0
- data/spec/sample_app/config/environments/test.rb +46 -0
- data/spec/sample_app/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/sample_app/config/initializers/assets.rb +14 -0
- data/spec/sample_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/sample_app/config/initializers/content_security_policy.rb +25 -0
- data/spec/sample_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/sample_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/sample_app/config/initializers/inflections.rb +16 -0
- data/spec/sample_app/config/initializers/mime_types.rb +4 -0
- data/spec/sample_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/sample_app/config/puma.rb +34 -0
- data/spec/sample_app/config/routes.rb +3 -0
- data/spec/sample_app/config/spring.rb +6 -0
- data/spec/sample_app/db/schema.rb +18 -0
- data/spec/sample_app/db/seeds.rb +1 -0
- data/spec/sample_app/spec/lib/tasks/human_domain_spec.rb +89 -0
- data/spec/sample_app/spec/lib/tasks/pan_domain_spec.rb +38 -0
- data/spec/sample_app/spec/models/pan_domain/human/blood_classification_system_spec.rb +46 -0
- data/spec/sample_app/spec/models/pan_domain/human/blood_group_name_spec.rb +39 -0
- data/spec/sample_app/spec/rails_helper.rb +98 -0
- data/spec/sample_app/spec/spec_helper.rb +96 -0
- data/spec/spec_helper.rb +97 -0
- metadata +244 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateBloodClassificationSystems < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :blood_classification_systems, id: false do |t|
|
4
|
+
# create primary key with integer not bigint
|
5
|
+
t.integer :id, null: false, primary_key: true
|
6
|
+
t.string :description, null: false
|
7
|
+
t.string :name, limit: 50, null: false
|
8
|
+
|
9
|
+
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
10
|
+
t.column :created_at, :timestamptz, null: false
|
11
|
+
t.column :updated_at, :timestamptz, null: false
|
12
|
+
else
|
13
|
+
t.timestamps null: false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateBloodGroupNames < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :blood_group_names, id: false do |t|
|
4
|
+
# create primary key with integer not bigint
|
5
|
+
t.integer :id, null: false, primary_key: true
|
6
|
+
t.integer :blood_classification_system_id, null: false, index: true
|
7
|
+
t.string :name, limit: 10, null: false
|
8
|
+
t.string :symbol, limit: 10, null: false
|
9
|
+
|
10
|
+
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
11
|
+
t.column :created_at, :timestamptz, null: false
|
12
|
+
t.column :updated_at, :timestamptz, null: false
|
13
|
+
else
|
14
|
+
t.timestamps null: false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
add_foreign_key :blood_group_names, :blood_classification_systems
|
19
|
+
end
|
20
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module PanDomain
|
2
|
+
module Human
|
3
|
+
if BloodClassificationSystem::SYSTEMS.size != BloodClassificationSystem.count
|
4
|
+
BloodClassificationSystem::SYSTEMS.each do |system_params|
|
5
|
+
BloodClassificationSystem.where(
|
6
|
+
name: system_params[:name]
|
7
|
+
).first_or_create(description: system_params[:description])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
if BloodGroupName::GROUP_NAMES.size != BloodGroupName.count
|
12
|
+
BloodGroupName::GROUP_NAMES.each do |group_name_params|
|
13
|
+
BloodGroupName.where(
|
14
|
+
name: group_name_params[:name], symbol: group_name_params[:symbol]
|
15
|
+
).first_or_create(
|
16
|
+
blood_classification_system: group_name_params[:blood_classification_system]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
module HumanDomain
|
6
|
+
module Generate
|
7
|
+
class MigrationsGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
|
10
|
+
# Root directory
|
11
|
+
source_root File.expand_path('../../../..', __dir__)
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def next_migration_number(dirname)
|
15
|
+
current_migration_timestamp = current_migration_number(dirname)
|
16
|
+
|
17
|
+
if ActiveRecord::Base.timestamped_migrations
|
18
|
+
timestamp_str = Time.new.utc.strftime("%Y%m%d%H%M%S")
|
19
|
+
|
20
|
+
# Check if timestamp is the same with previous migration
|
21
|
+
# due to fast generation in the same second
|
22
|
+
if timestamp_str == current_migration_timestamp.to_s
|
23
|
+
"%.3d" % (current_migration_timestamp + 1)
|
24
|
+
else
|
25
|
+
timestamp_str
|
26
|
+
end
|
27
|
+
else
|
28
|
+
"%.3d" % (current_migration_timestamp + 1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_migration_files
|
34
|
+
source_dir = 'db/migrate/human_domain'
|
35
|
+
destination_dir = 'db/migrate'
|
36
|
+
|
37
|
+
migration_template(
|
38
|
+
"#{source_dir}/0001_create_blood_classification_systems.rb",
|
39
|
+
"#{destination_dir}/create_blood_classification_systems.rb"
|
40
|
+
)
|
41
|
+
|
42
|
+
migration_template(
|
43
|
+
"#{source_dir}/0002_create_blood_group_names.rb",
|
44
|
+
"#{destination_dir}/create_blood_group_names.rb"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/pan_domain.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module PanDomain
|
4
|
+
class CLI < Thor
|
5
|
+
available_domains = []
|
6
|
+
|
7
|
+
desc 'version', 'Display version'
|
8
|
+
map %w[-v --version] => :version
|
9
|
+
def version
|
10
|
+
say "PanDomain #{VERSION}"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Dynamically get all available domains from rake task files
|
14
|
+
Dir.glob("#{__dir__}/../tasks/*_domain.rake").each do |file_path|
|
15
|
+
file_name = File.basename(file_path)
|
16
|
+
# exclude pan_domain rake file
|
17
|
+
next if file_name.include?('pan_domain')
|
18
|
+
file_name = file_name.sub('_domain.rake', '').capitalize
|
19
|
+
available_domains << "- #{file_name}\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'install', 'Install all domains'
|
23
|
+
long_desc <<-INSTALL_DOMAINS
|
24
|
+
|
25
|
+
'install' will install all available domains.
|
26
|
+
|
27
|
+
Installing a domain means it will generate migrations
|
28
|
+
to your Rails application, run 'rake db:migrate' as a bash command,
|
29
|
+
and seed data for each domain if available.
|
30
|
+
|
31
|
+
Available domains are:
|
32
|
+
|
33
|
+
\e[34m#{available_domains.join("\n")}\e[0m
|
34
|
+
INSTALL_DOMAINS
|
35
|
+
def install
|
36
|
+
system 'rake pan_domain:install'
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'generate_migrations', 'Generate migrations for all domains'
|
40
|
+
def generate_migrations
|
41
|
+
say_status 'start', 'Generate all migrations'
|
42
|
+
|
43
|
+
system 'rails g human_domain:generate:migrations'
|
44
|
+
|
45
|
+
say_status 'finish', 'Generate all migrations'
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'generate_seeds', 'Generate seed data for all domains'
|
49
|
+
def generate_seeds
|
50
|
+
system 'rake human_domain:db:seed'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
thor = Thor.new
|
2
|
+
|
3
|
+
namespace :human_domain do
|
4
|
+
namespace :generate do
|
5
|
+
desc 'Generates all migrations in Human Domain to application'
|
6
|
+
task :migrations => :environment do
|
7
|
+
thor.say_status 'start', 'Generate migrations'
|
8
|
+
|
9
|
+
system 'rails g human_domain:generate:migrations'
|
10
|
+
|
11
|
+
thor.say_status 'finish', 'Generate migrations'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :db do
|
16
|
+
desc 'Loads the seed data in Human Domain to application'
|
17
|
+
task :seed => :environment do
|
18
|
+
thor.say_status 'start', 'Seeding Human domain data'
|
19
|
+
|
20
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
21
|
+
config ||= Rails.application.config.database_configuration[Rails.env]
|
22
|
+
config['pool'] = ENV['DB_POOL'] || ENV['RAILS_MAX_THREADS'] || 5
|
23
|
+
|
24
|
+
ActiveRecord::Base.establish_connection(config)
|
25
|
+
|
26
|
+
PanDomain::Human::Engine.load_seed
|
27
|
+
|
28
|
+
thor.say_status 'finish', 'Seeding Human domain data'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Install Human Domain to application'
|
33
|
+
task :install => :environment do
|
34
|
+
thor.say_status 'start', 'Install Human Domain'
|
35
|
+
|
36
|
+
Rake::Task['human_domain:generate:migrations'].invoke
|
37
|
+
|
38
|
+
thor.say_status 'run', 'db:migrate'
|
39
|
+
Rake::Task['db:migrate'].invoke
|
40
|
+
|
41
|
+
Rake::Task['human_domain:db:seed'].invoke
|
42
|
+
|
43
|
+
thor.say_status 'finish', 'Install Human Domain'
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
thor = Thor.new
|
2
|
+
|
3
|
+
namespace :pan_domain do
|
4
|
+
desc 'Install all domains'
|
5
|
+
task :install do
|
6
|
+
thor.say_status 'start', 'Install All Domains'
|
7
|
+
|
8
|
+
Rake::Task['human_domain:install'].invoke
|
9
|
+
|
10
|
+
thor.say_status 'finish', 'Install All Domains'
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :db do
|
14
|
+
desc 'Loads seed data from all domains'
|
15
|
+
task :seed do
|
16
|
+
thor.say_status 'start:', 'Seed data from All Domains'
|
17
|
+
|
18
|
+
Rake::Task['human_domain:db:seed'].invoke
|
19
|
+
|
20
|
+
thor.say_status 'finish:', 'Seed data from All Domains'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/pan_domain.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'pan_domain/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'pan_domain'
|
7
|
+
spec.version = PanDomain::VERSION
|
8
|
+
spec.authors = ['Yosua Jaya Candra']
|
9
|
+
spec.email = ['yosuajayacandra@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'A tool for create common tables powered by ActiveRecord'
|
12
|
+
spec.description = 'A gem which create common tables and data' \
|
13
|
+
' which prioritize on data integrity.'
|
14
|
+
spec.homepage = 'https://github.com/pangrams/pan_domain'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org.
|
18
|
+
# To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host
|
20
|
+
# or delete this section to allow pushing to any host.
|
21
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem
|
25
|
+
# that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
spec.executables = ['pan_domain']
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
spec.test_files = Dir.glob('spec/**/*.rb')
|
35
|
+
|
36
|
+
spec.add_dependency 'rails', '~> 5.2'
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
39
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
40
|
+
spec.add_development_dependency 'pg', '~> 1.1'
|
41
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.8'
|
42
|
+
spec.add_development_dependency 'shoulda-matchers', '~> 4.0.0.rc1'
|
43
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.6'
|
44
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require File.expand_path('../../../lib/generators/human_domain/generate/migrations_generator', __dir__)
|
4
|
+
|
5
|
+
class HumanDomainGenerateMigrationsGenerator < Rails::Generators::TestCase
|
6
|
+
tests HumanDomain::Generate::MigrationsGenerator
|
7
|
+
destination File.expand_path('../../dummy', __dir__)
|
8
|
+
teardown :clean_migrations
|
9
|
+
|
10
|
+
def clean_migrations
|
11
|
+
Dir.glob("#{destination_root}/db/migrate/*.rb").each do |file_path|
|
12
|
+
File.delete(file_path) if File.exist?(file_path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'generates blood classification system migration' do
|
17
|
+
run_generator
|
18
|
+
|
19
|
+
assert_migration 'db/migrate/create_blood_classification_systems.rb'
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'generates blood group name migration' do
|
23
|
+
run_generator
|
24
|
+
|
25
|
+
assert_migration 'db/migrate/create_blood_group_names.rb'
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'do not generate any migration with same timestamp' do
|
29
|
+
dir_path = "#{destination_root}/db/migrate"
|
30
|
+
migration_timestamps = []
|
31
|
+
|
32
|
+
run_generator
|
33
|
+
|
34
|
+
migration_files = Dir.glob("#{dir_path}/*_create_blood_group_names.rb")
|
35
|
+
migration_files += Dir.glob(
|
36
|
+
"#{dir_path}/*_create_blood_classification_systems.rb"
|
37
|
+
)
|
38
|
+
|
39
|
+
migration_files.each do |file_path|
|
40
|
+
file_name = File.basename(file_path)
|
41
|
+
timestamp_str = file_name[0...14]
|
42
|
+
|
43
|
+
assert !migration_timestamps.include?(timestamp_str)
|
44
|
+
|
45
|
+
migration_timestamps << timestamp_str
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'pan_domain/cli'
|
2
|
+
|
3
|
+
describe PanDomain::CLI do
|
4
|
+
describe '--version' do
|
5
|
+
it 'displays "PanDomain {VERSION}\n"' do
|
6
|
+
expect { PanDomain::CLI.start ['--version'] }.to output(
|
7
|
+
"PanDomain #{PanDomain::VERSION}\n"
|
8
|
+
).to_stdout
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '-v' do
|
13
|
+
it 'displays "PanDomain {VERSION}\n"' do
|
14
|
+
expect { PanDomain::CLI.start ['-v'] }.to output(
|
15
|
+
"PanDomain #{PanDomain::VERSION}\n"
|
16
|
+
).to_stdout
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'version' do
|
21
|
+
it 'displays "PanDomain {VERSION}\n"' do
|
22
|
+
expect { PanDomain::CLI.start ['version'] }.to output(
|
23
|
+
"PanDomain #{PanDomain::VERSION}\n"
|
24
|
+
).to_stdout
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'install' do
|
29
|
+
# Suppress thor messages
|
30
|
+
before { allow($stdout).to receive(:write) }
|
31
|
+
|
32
|
+
it 'runs "rake pan_domain:install"' do
|
33
|
+
expect_any_instance_of(Kernel).to(
|
34
|
+
receive(:system).with 'rake pan_domain:install'
|
35
|
+
)
|
36
|
+
|
37
|
+
PanDomain::CLI.start ['install']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'generate_migrations' do
|
42
|
+
# Suppress thor messages
|
43
|
+
before { allow($stdout).to receive(:write) }
|
44
|
+
|
45
|
+
it 'runs "rails g humain_domain:generate:migrations"' do
|
46
|
+
expect_any_instance_of(Kernel).to(
|
47
|
+
receive(:system).with 'rails g human_domain:generate:migrations'
|
48
|
+
)
|
49
|
+
|
50
|
+
PanDomain::CLI.start ['generate_migrations']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|