padrino-gen 0.15.1 → 0.15.2

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: 9897984eee6550c278a48190ada56e7d88d38cec9b6a912ce8136b911a8578f7
4
- data.tar.gz: cc0de388292f104d491401feffbf673000b439728696ac4cd012a1fbba668bfd
3
+ metadata.gz: 4715ef3a71b10c1c828571ecc035af5e589b4f657376fc6c7ee17a5dbd21bcf5
4
+ data.tar.gz: 6a38e83c98b6db24b9415194fac781daeb477ffac5cafd8bf5bd5283a22898bb
5
5
  SHA512:
6
- metadata.gz: 1c5f835446e50a8009cf55c37439fb0134faa3b1f2ea5fd14e342fbfe6688b4300a45f49a7efd7281a7af4aebfa471ba5eeac0061c8c2ac3c7d3aba861b664ba
7
- data.tar.gz: e3cc0d72979f835fdaf9b04672eb7b0775cff146a65816b8b336bb340763d7f97dd292e46160ac403dc8a07ac294a91b5e5d4fe80a7cd675d2c9bdd0205725b6
6
+ metadata.gz: ed706f3cd3d2e29c84155019bffb0967ddb35641cb2e2afb84e05bed4dbbd603fc672342f54714d76723de706de1ab4b991f7f39d2384799625e2fba6dd8e5e1
7
+ data.tar.gz: 41cb109b4e0afeb29150e406416de84bd28a1c403d808ebb4729fb5c4e19f8d15612a549a2fcf87ffaeb5d64006eafaffe504bea39265f7badd44dd6fe543218
@@ -2,28 +2,30 @@ AR = (<<-AR) unless defined?(AR)
2
2
  ##
3
3
  # You can use other adapters like:
4
4
  #
5
- # ActiveRecord::Base.configurations[:development] = {
6
- # :adapter => 'mysql2',
7
- # :encoding => 'utf8',
8
- # :reconnect => true,
9
- # :database => 'your_database',
10
- # :pool => 5,
11
- # :username => 'root',
12
- # :password => '',
13
- # :host => 'localhost',
14
- # :socket => '/tmp/mysql.sock'
5
+ # ActiveRecord::Base.configurations = {
6
+ # :development => {
7
+ # :adapter => 'mysql2',
8
+ # :encoding => 'utf8',
9
+ # :reconnect => true,
10
+ # :database => 'your_database',
11
+ # :pool => 5,
12
+ # :username => 'root',
13
+ # :password => '',
14
+ # :host => 'localhost',
15
+ # :socket => '/tmp/mysql.sock'
16
+ # }
15
17
  # }
16
18
  #
17
- ActiveRecord::Base.configurations[:development] = {
19
+ ActiveRecord::Base.configurations = {
20
+ :development => {
18
21
  !DB_DEVELOPMENT!
19
- }
20
-
21
- ActiveRecord::Base.configurations[:production] = {
22
+ },
23
+ :production => {
22
24
  !DB_PRODUCTION!
23
- }
24
-
25
- ActiveRecord::Base.configurations[:test] = {
25
+ },
26
+ :test => {
26
27
  !DB_TEST!
28
+ }
27
29
  }
28
30
 
29
31
  # Setup our logger
@@ -52,48 +54,49 @@ ActiveSupport.use_standard_json_time_format = true
52
54
  ActiveSupport.escape_html_entities_in_json = false
53
55
 
54
56
  # Now we can establish connection with our db.
55
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
56
-
57
- # Timestamps are in the utc by default.
58
- ActiveRecord::Base.default_timezone = :utc
57
+ if ActiveRecord::VERSION::MAJOR.to_i < 6
58
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
59
+ else
60
+ ActiveRecord::Base.establish_connection(Padrino.env)
61
+ end
59
62
  AR
60
63
 
61
64
  MYSQL = (<<-MYSQL) unless defined?(MYSQL)
62
- :adapter => 'mysql',
63
- :encoding => 'utf8',
64
- :reconnect => true,
65
- :database => !DB_NAME!,
66
- :pool => 5,
67
- :username => 'root',
68
- :password => '',
69
- :host => 'localhost',
70
- :socket => '/tmp/mysql.sock'
65
+ :adapter => 'mysql',
66
+ :encoding => 'utf8',
67
+ :reconnect => true,
68
+ :database => !DB_NAME!,
69
+ :pool => 5,
70
+ :username => 'root',
71
+ :password => '',
72
+ :host => 'localhost',
73
+ :socket => '/tmp/mysql.sock'
71
74
  MYSQL
72
75
 
73
76
  MYSQL2 = (<<-MYSQL2) unless defined?(MYSQL2)
74
- :adapter => 'mysql2',
75
- :encoding => 'utf8',
76
- :reconnect => true,
77
- :database => !DB_NAME!,
78
- :pool => 5,
79
- :username => 'root',
80
- :password => '',
81
- :host => 'localhost',
82
- :socket => '/tmp/mysql.sock'
77
+ :adapter => 'mysql2',
78
+ :encoding => 'utf8',
79
+ :reconnect => true,
80
+ :database => !DB_NAME!,
81
+ :pool => 5,
82
+ :username => 'root',
83
+ :password => '',
84
+ :host => 'localhost',
85
+ :socket => '/tmp/mysql.sock'
83
86
  MYSQL2
84
87
 
85
88
  POSTGRES = (<<-POSTGRES) unless defined?(POSTGRES)
86
- :adapter => 'postgresql',
87
- :database => !DB_NAME!,
88
- :username => 'root',
89
- :password => '',
90
- :host => 'localhost',
91
- :port => 5432
89
+ :adapter => 'postgresql',
90
+ :database => !DB_NAME!,
91
+ :username => 'root',
92
+ :password => '',
93
+ :host => 'localhost',
94
+ :port => 5432
92
95
  POSTGRES
93
96
 
94
97
  SQLITE = (<<-SQLITE) unless defined?(SQLITE)
95
- :adapter => 'sqlite3',
96
- :database => !DB_NAME!
98
+ :adapter => 'sqlite3',
99
+ :database => !DB_NAME!
97
100
  SQLITE
98
101
 
99
102
  CONNECTION_POOL_MIDDLEWARE = <<-MIDDLEWARE
@@ -126,7 +126,7 @@ module Padrino
126
126
  when template_file =~ %r{^https?://} && template_file !~ /gist/
127
127
  template_file
128
128
  when template_file =~ /gist/ && template_file !~ /raw/
129
- raw_link, _ = *open(template_file) { |io| io.read.scan(/<a\s+href\s?\=\"(.*?)\"\>raw/) }
129
+ raw_link, _ = *URI.open(template_file) { |io| io.read.scan(/<a\s+href\s?\=\"(.*?)\"\>raw/) }
130
130
  raw_link ? "https://gist.github.com#{raw_link[0]}" : template_file
131
131
  when File.extname(template_file).empty? # referencing official plugin (i.e hoptoad)
132
132
  "https://raw.github.com/padrino/padrino-recipes/master/#{kind.to_s.pluralize}/#{template_file}_#{kind}.rb"
@@ -420,6 +420,10 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
420
420
  ActiveRecord.version < Gem::Version.create("6.0.0")
421
421
  end
422
422
 
423
+ def less_than_active_record_6_1?
424
+ ActiveRecord.version < Gem::Version.create("6.1.0")
425
+ end
426
+
423
427
  def with_database(env_name)
424
428
  if less_than_active_record_6_0?
425
429
  config = ActiveRecord::Base.configurations.with_indifferent_access[env_name]
@@ -429,7 +433,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
429
433
  db_configs = ActiveRecord::Base.configurations.configs_for(env_name: env_name.to_s)
430
434
 
431
435
  db_configs.each do |db_config|
432
- yield db_config.config.with_indifferent_access
436
+ yield configuration_hash(db_config)
433
437
  end
434
438
  end
435
439
  end
@@ -441,11 +445,17 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
441
445
  end
442
446
  else
443
447
  ActiveRecord::Base.configurations.configs_for.each do |db_config|
444
- yield db_config.config.with_indifferent_access
448
+ yield configuration_hash(db_config)
445
449
  end
446
450
  end
447
451
  end
448
452
 
453
+ def configuration_hash(configuration)
454
+ return configuration if less_than_active_record_6_0?
455
+ config = less_than_active_record_6_1 ? configuration.config : configuration.configuration_hash
456
+ config.with_indifferent_access
457
+ end
458
+
449
459
  task 'db:migrate' => 'ar:migrate'
450
460
  task 'db:create' => 'ar:create'
451
461
  task 'db:drop' => 'ar:drop'
@@ -0,0 +1,66 @@
1
+ ##
2
+ # You can use other adapters like:
3
+ #
4
+ # ActiveRecord::Base.configurations = {
5
+ # :development => {
6
+ # :adapter => 'mysql2',
7
+ # :encoding => 'utf8',
8
+ # :reconnect => true,
9
+ # :database => 'your_database',
10
+ # :pool => 5,
11
+ # :username => 'root',
12
+ # :password => '',
13
+ # :host => 'localhost',
14
+ # :socket => '/tmp/mysql.sock'
15
+ # }
16
+ # }
17
+ #
18
+ ActiveRecord::Base.configurations = {
19
+ :development => {
20
+ :adapter => 'sqlite3',
21
+ :database => Padrino.root('db', 'sample_project_development.db')
22
+
23
+ },
24
+ :production => {
25
+ :adapter => 'sqlite3',
26
+ :database => Padrino.root('db', 'sample_project_production.db')
27
+
28
+ },
29
+ :test => {
30
+ :adapter => 'sqlite3',
31
+ :database => Padrino.root('db', 'sample_project_test.db')
32
+
33
+ }
34
+ }
35
+
36
+ # Setup our logger
37
+ ActiveRecord::Base.logger = logger
38
+
39
+ if ActiveRecord::VERSION::MAJOR.to_i < 4
40
+ # Raise exception on mass assignment protection for Active Record models.
41
+ ActiveRecord::Base.mass_assignment_sanitizer = :strict
42
+
43
+ # Log the query plan for queries taking more than this (works
44
+ # with SQLite, MySQL, and PostgreSQL).
45
+ ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
46
+ end
47
+
48
+ # Doesn't include Active Record class name as root for JSON serialized output.
49
+ ActiveRecord::Base.include_root_in_json = false
50
+
51
+ # Store the full class name (including module namespace) in STI type column.
52
+ ActiveRecord::Base.store_full_sti_class = true
53
+
54
+ # Use ISO 8601 format for JSON serialized times and dates.
55
+ ActiveSupport.use_standard_json_time_format = true
56
+
57
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper
58
+ # if you're including raw JSON in an HTML page.
59
+ ActiveSupport.escape_html_entities_in_json = false
60
+
61
+ # Now we can establish connection with our db.
62
+ if ActiveRecord::VERSION::MAJOR.to_i < 6
63
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
64
+ else
65
+ ActiveRecord::Base.establish_connection(Padrino.env)
66
+ end
data/test/helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/pride'
3
- require 'mocha/setup'
4
3
  require 'rack/test'
5
4
  require 'fakeweb'
6
5
  require 'thor/group'
@@ -11,6 +10,7 @@ require 'padrino-helpers'
11
10
 
12
11
  require 'ext/minitest-spec'
13
12
  require 'ext/fakeweb-ruby24'
13
+ require 'mocha/minitest'
14
14
 
15
15
  Padrino::Generators.load_components!
16
16
 
@@ -26,6 +26,8 @@ describe "ComponentGenerator" do
26
26
  assert_match_in_file(/gem 'activerecord', '>= 3.1', :require => 'active_record'/, "#{@apptmp}/sample_project/Gemfile")
27
27
  assert_match_in_file(/gem 'sqlite3'/, "#{@apptmp}/sample_project/Gemfile")
28
28
  refute_match(/Switch renderer to/, out)
29
+ database_template_path = File.join(File.dirname(__FILE__), 'fixtures', 'database_template.rb')
30
+ assert FileUtils.compare_file("#{@apptmp}/sample_project/config/database.rb", database_template_path)
29
31
  components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
30
32
  assert_equal 'activerecord', components_chosen[:orm]
31
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-04-25 00:00:00.000000000 Z
14
+ date: 2022-12-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-core
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.15.1
22
+ version: 0.15.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.15.1
29
+ version: 0.15.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: bundler
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -53,28 +53,28 @@ dependencies:
53
53
  requirements:
54
54
  - - '='
55
55
  - !ruby/object:Gem::Version
56
- version: 0.15.1
56
+ version: 0.15.2
57
57
  type: :development
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.15.1
63
+ version: 0.15.2
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: padrino-mailer
66
66
  requirement: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.15.1
70
+ version: 0.15.2
71
71
  type: :development
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.15.1
77
+ version: 0.15.2
78
78
  description: Generators for easily creating and building padrino applications from
79
79
  the console
80
80
  email: padrinorb@gmail.com
@@ -184,6 +184,7 @@ files:
184
184
  - lib/padrino-gen/padrino-tasks/sql-helpers.rb
185
185
  - padrino-gen.gemspec
186
186
  - test/fixtures/admin_template.rb
187
+ - test/fixtures/database_template.rb
187
188
  - test/fixtures/example_template.rb
188
189
  - test/fixtures/git_template.rb
189
190
  - test/fixtures/plugin_template.rb
@@ -228,6 +229,7 @@ specification_version: 4
228
229
  summary: Generators for easily creating and building padrino applications
229
230
  test_files:
230
231
  - test/fixtures/admin_template.rb
232
+ - test/fixtures/database_template.rb
231
233
  - test/fixtures/example_template.rb
232
234
  - test/fixtures/git_template.rb
233
235
  - test/fixtures/plugin_template.rb