pgcli-rails 0.7.0 → 0.8.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: 3cbab19637a46e7a7f097af1d3b312411469c330d717be8d3f025c7558d55692
4
- data.tar.gz: 82eb2f746f696b4e16fa63ec227594bf53aadb88220af6c1325100a14162122f
3
+ metadata.gz: 3fcf132264e4377997cfe3c761a4f40defd41ec677b20953fe87c012e5c9f87f
4
+ data.tar.gz: c3b5f858539b5fd498611bc3b1b3cb65cfb39844449cdec8167e82cb3463f196
5
5
  SHA512:
6
- metadata.gz: 351bbf4f0f7b209c488dc698d364d05ad786991fc78b13de8f8aaddfadfc947f2bb1605f42bdabbf0d6968209f0bba91a22793c31eb0abc15230dd002fcb2960
7
- data.tar.gz: 72373571948af3606f6ffcb08aff0d9466c0e3a5979c4ab2e1e92f2a611aab35e905227c3046627b3ec7078e904602b9e2a329e896c1c270760b3a0d400b74a2
6
+ metadata.gz: dcd32ff24c09273cab3a5077bb64238ef5f853ced0fd2e05ae8dea265055ad937665ea7a44d8ef2b678e507a6e88188b69951c495bcd55c14bd1868b76f12843
7
+ data.tar.gz: 39d38025056b0a972005659a9a547a752aded31ed90032364942208479e6a58e05d90db713ca428407ace9bbfa39169e6a71a94d1526aae10538b441c1ecd254
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # pgcli-rails
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/pgcli-rails.svg)](http://badge.fury.io/rb/pgcli-rails)
4
- [![Build Status](https://mattbrictson.semaphoreci.com/badges/pgcli-rails/branches/main.svg?style=shields)](https://mattbrictson.semaphoreci.com/projects/pgcli-rails)
3
+ [![Gem Version](https://img.shields.io/gem/v/pgcli-rails)](https://rubygems.org/gems/pgcli-rails)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/pgcli-rails)](https://www.ruby-toolbox.com/projects/pgcli-rails)
5
+ [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/mattbrictson/pgcli-rails/ci.yml)](https://github.com/mattbrictson/pgcli-rails/actions/workflows/ci.yml)
5
6
 
6
7
  [pgcli][] is a command-line interface for PostgreSQL that offers many improvements over `psql`, like auto-completion and syntax highlighting. Wouldn't it be nice to have a convenient way to use `pgcli` with your Rails app?
7
8
 
@@ -48,7 +49,7 @@ RAILS_ENV=test bin/rake pgcli
48
49
 
49
50
  ## How it works
50
51
 
51
- pgcli-rails is simply a Rake task that reuses the existing `Rails::DBConsole` command class provided by Rails. It subclasses DBConsole to execute `pgcli` instead of `psql`. All you need to do is require the pgcli-rails gem by placing it in your Gemfile.
52
+ pgcli-rails is simply a Rake task that reuses the existing `Rails::DBConsole` command class provided by Rails. It applies a monkey patch so that `pgcli` is executed instead of `psql`. All you need to do is require the pgcli-rails gem by placing it in your Gemfile.
52
53
 
53
54
  ## Configuration
54
55
 
@@ -0,0 +1,19 @@
1
+ module Pgcli
2
+ module Rails
3
+ module MonkeyPatch
4
+ def self.apply!
5
+ if ::Rails.gem_version >= Gem::Version.new("7.1.0")
6
+ require "active_record/connection_adapters/postgresql_adapter"
7
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.singleton_class.prepend self
8
+ else
9
+ ::Rails::DBConsole.prepend self
10
+ end
11
+ end
12
+
13
+ def find_cmd_and_exec(commands, *args)
14
+ commands = "pgcli" if commands == "psql"
15
+ super(commands, *args)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,16 +1,22 @@
1
1
  desc "Start pgcli using connection info from database.yml"
2
2
  task :pgcli do
3
- require "pgcli/rails/dbconsole"
3
+ begin
4
+ require "rails/commands/dbconsole"
5
+ rescue LoadError
6
+ require "rails/commands/dbconsole/dbconsole_command"
7
+ end
4
8
 
5
9
  # APP_PATH constant must be set for DBConsole to work
6
10
  APP_PATH = Rails.root.join("config", "application") unless defined?(APP_PATH)
7
11
 
8
- opt = if Rails.version >= "5.1"
12
+ opt = if Rails.gem_version >= Gem::Version.new("5.1.0")
9
13
  { "--include-password" => true }
10
14
  else
11
15
  ["--include-password"]
12
16
  end
13
17
 
14
- console = Pgcli::Rails::DBConsole.new(opt)
18
+ require "pgcli/rails/monkey_patch"
19
+ Pgcli::Rails::MonkeyPatch.apply!
20
+ Rails::DBConsole.new(opt).start
15
21
  console.start
16
22
  end
@@ -1,5 +1,5 @@
1
1
  module Pgcli
2
2
  module Rails
3
- VERSION = "0.7.0".freeze
3
+ VERSION = "0.8.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgcli-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brictson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-02 00:00:00.000000000 Z
11
+ date: 2023-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -34,7 +34,7 @@ files:
34
34
  - LICENSE.txt
35
35
  - README.md
36
36
  - lib/pgcli/rails.rb
37
- - lib/pgcli/rails/dbconsole.rb
37
+ - lib/pgcli/rails/monkey_patch.rb
38
38
  - lib/pgcli/rails/railtie.rb
39
39
  - lib/pgcli/rails/tasks.rake
40
40
  - lib/pgcli/rails/version.rb
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  requirements: []
65
- rubygems_version: 3.4.12
65
+ rubygems_version: 3.4.21
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: Replaces the Rails PostgreSQL dbconsole with the much nicer pgcli
@@ -1,19 +0,0 @@
1
- begin
2
- require "rails/commands/dbconsole"
3
- rescue LoadError
4
- require "rails/commands/dbconsole/dbconsole_command"
5
- end
6
-
7
- module Pgcli
8
- module Rails
9
- # Subclass the built-in Rails DBConsole to override "psql" with "pgcli".
10
- class DBConsole < ::Rails::DBConsole
11
- protected
12
-
13
- def find_cmd_and_exec(commands, *args)
14
- commands = "pgcli" if commands == "psql"
15
- super(commands, *args)
16
- end
17
- end
18
- end
19
- end