standalone_activerecord_boot_loader 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de6480e8c275a7ca01626b3d90489eed9ac2cfec80b5a45601a1c2f2d4af2afe
4
- data.tar.gz: d6f38032e0450e7e2d9f3d0007c9302fbe9b9ba101cb68783df441c860649c3a
3
+ metadata.gz: b08d0c0520707a045d3a83559a70fd6a19a6cb291d7284bbf92ec822c6cf0604
4
+ data.tar.gz: f3fb37675e52b5fd3acb99cd7334f6339f36227cc8310f36b3ab0ecd8b486982
5
5
  SHA512:
6
- metadata.gz: 6e2044e781bf73bae6b5d549bb70847794dafc3b1a6361c93075cd7b93cd599449ba727ec4bbf0eaa93b2de3c60387ec636dca35ed57802cfd0e30d525f3f701
7
- data.tar.gz: e67a91bf9b93f9028f0f6dc971a8809193ceef24f751976b11c0c3f45c81e10db715dd48d55b1e86e27714436f5a52bbd415ffb376727ee59da1cca944cdd8f2
6
+ metadata.gz: 4cd3d0213e58e9a55a37c913e8fa28239fd1afb2e4e8a428a6f50c2a447d1c976bbb7d20e2173901ef285771884a3dbaff838963eca6993c2f73fe70fd7cc6a5
7
+ data.tar.gz: ade9808858e3dd1e13e22ff5cc4ffe1cbe4e034a622c72f66a1273a5186b9e91b1666aad32bd7467be3ec9366c278e62aee6d334b022431df86c2686b068be38
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StandaloneActiverecordBootLoader
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'standalone_activerecord_boot_loader/version'
4
+ require 'erb'
4
5
  require 'zeitwerk'
5
6
  require 'active_record'
6
7
  require 'active_record/tasks/database_tasks'
@@ -25,31 +26,31 @@ module StandaloneActiverecordBootLoader
25
26
  private
26
27
 
27
28
  def setup_zeitwerk
28
- loader = Zeitwerk::Loader.new
29
+ loader = ::Zeitwerk::Loader.new
29
30
  loader.push_dir(@app_root.join('app/models'))
30
31
  loader.setup
31
32
  end
32
33
 
33
34
  def setup_active_record
34
35
  create_database if @create_database
35
- Time.zone = @timezone
36
- ActiveRecord::Base.establish_connection(database_config[@env])
37
- ActiveRecord::Base.time_zone_aware_attributes = true
36
+ ::Time.zone = @timezone
37
+ ::ActiveRecord::Base.establish_connection(database_config[@env])
38
+ ::ActiveRecord::Base.time_zone_aware_attributes = true
38
39
  end
39
40
 
40
41
  def create_database
41
- tasks = ActiveRecord::Tasks::MySQLDatabaseTasks.new(build_database_config)
42
+ tasks = ::ActiveRecord::Tasks::MySQLDatabaseTasks.new(build_database_config)
42
43
  begin
43
44
  tasks.create
44
45
  rescue StandardError => e
45
46
  # ActiveRecord 5系
46
- if defined?(ActiveRecord::Tasks::DatabaseAlreadyExists)
47
- return if e.instance_of?(ActiveRecord::Tasks::DatabaseAlreadyExists)
47
+ if defined?(::ActiveRecord::Tasks::DatabaseAlreadyExists)
48
+ return if e.instance_of?(::ActiveRecord::Tasks::DatabaseAlreadyExists)
48
49
  end
49
50
 
50
51
  # ActiveRecord 6系以降
51
- if defined?(ActiveRecord::DatabaseAlreadyExists)
52
- return if e.instance_of?(ActiveRecord::DatabaseAlreadyExists)
52
+ if defined?(::ActiveRecord::DatabaseAlreadyExists)
53
+ return if e.instance_of?(::ActiveRecord::DatabaseAlreadyExists)
53
54
  end
54
55
 
55
56
  raise e
@@ -61,15 +62,15 @@ module StandaloneActiverecordBootLoader
61
62
  end
62
63
 
63
64
  def database_config
64
- @database_config ||= YAML::load(ERB.new(File.read(database_yml_path)).result)
65
+ @database_config ||= ::YAML::load(::ERB.new(::File.read(database_yml_path)).result)
65
66
  end
66
67
 
67
68
  def build_database_config
68
- unless defined?(ActiveRecord::DatabaseConfigurations::HashConfig)
69
+ unless defined?(::ActiveRecord::DatabaseConfigurations::HashConfig)
69
70
  return database_config[@env]
70
71
  end
71
72
 
72
- config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@env, 'primary', database_config[@env])
73
+ config = ::ActiveRecord::DatabaseConfigurations::HashConfig.new(@env, 'primary', database_config[@env])
73
74
  return config if config.respond_to?(:configuration_hash)
74
75
 
75
76
  database_config[@env]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standalone_activerecord_boot_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Ooishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-11 00:00:00.000000000 Z
11
+ date: 2023-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -45,16 +45,10 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - ".rspec"
49
- - Gemfile
50
48
  - LICENSE
51
49
  - README.md
52
- - Rakefile
53
- - bin/console
54
- - bin/setup
55
50
  - lib/standalone_activerecord_boot_loader.rb
56
51
  - lib/standalone_activerecord_boot_loader/version.rb
57
- - standalone_activerecord_boot_loader.gemspec
58
52
  homepage: https://github.com/taka0125/standalone_activerecord_boot_loader
59
53
  licenses: []
60
54
  metadata:
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in standalone_activerecord_boot_loader.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rspec", "~> 3.0"
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "standalone_activerecord_boot_loader"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/standalone_activerecord_boot_loader/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "standalone_activerecord_boot_loader"
7
- spec.version = StandaloneActiverecordBootLoader::VERSION
8
- spec.authors = ["Takahiro Ooishi"]
9
- spec.email = ["taka0125@gmail.com"]
10
-
11
- spec.summary = "ActiveRecordを単体で動かす時に使う起動処理"
12
- spec.description = "ActiveRecordを単体で動かす時に使う起動処理"
13
- spec.homepage = "https://github.com/taka0125/standalone_activerecord_boot_loader"
14
- spec.required_ruby_version = ">= 2.6.0"
15
-
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = spec.homepage
18
-
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
- `git ls-files -z`.split("\x0").reject do |f|
23
- (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
- end
25
- end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
30
- spec.add_dependency "zeitwerk"
31
- spec.add_dependency "activerecord"
32
- end