arql 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4f6b01a4cae5f453322b2adf85b21ca4442d83dc07c504b73048b2640322af5
4
- data.tar.gz: 78b66856a6bb72ae2247b3f1f6ea82434696fd5f5f345fda904f6017fcd4c009
3
+ metadata.gz: dc86cf0d1862e52ea16793c51d8bd46e9c0d9463bbb2c096bb265e524d74edf9
4
+ data.tar.gz: d66f20e0a5f969179dcf70404f3a9c4c698618793e51c3bb0ddd928c7668ef8f
5
5
  SHA512:
6
- metadata.gz: d01f9fe3b5a3264476e76eb8446054daec67648edefe1d67c7b1c97ed96f8695d924b48b4a5c7b3f60ac535ccfdb9919d2106f6517b7f898289c8970a0574642
7
- data.tar.gz: c6be97e00d33908f45866c267b054c913e615b4f594b6baccf72d374a8e92b30136b7cd4e122cacdd7ffbf80dd1a8925b2e7e2a676edf4a2aec0f56a9058e054
6
+ metadata.gz: 5b201e845a4c691a274874b31c9b3a9cd3d23212d47496becea0ad167653f79126071329ba0f1c5bcc4bbeb6552a2c0b240006aa11f8c3ae36828ca931f595e7
7
+ data.tar.gz: e2d7bd2a8a3da1122e8624ef09e6854aac9f7708b4c2bd88985d43d0a5610e0fe4a5bfd85e6764492e9c8f7067209de3959fd6364e15ec4da51d0525ed722e87
data/Gemfile.lock CHANGED
@@ -1,27 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.1.1)
4
+ arql (0.1.2)
5
5
  activerecord (~> 6.0.0)
6
6
  activesupport (~> 6.0.0)
7
7
  mysql2 (~> 0.5.3)
8
+ net-ssh-gateway (~> 2.0.0)
8
9
  pry (~> 0.13.1)
9
10
  pry-byebug (~> 3.9.0)
10
11
 
11
12
  GEM
12
13
  remote: https://rubygems.org/
13
14
  specs:
14
- activemodel (6.0.2.2)
15
- activesupport (= 6.0.2.2)
16
- activerecord (6.0.2.2)
17
- activemodel (= 6.0.2.2)
18
- activesupport (= 6.0.2.2)
19
- activesupport (6.0.2.2)
15
+ activemodel (6.0.3)
16
+ activesupport (= 6.0.3)
17
+ activerecord (6.0.3)
18
+ activemodel (= 6.0.3)
19
+ activesupport (= 6.0.3)
20
+ activesupport (6.0.3)
20
21
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
22
  i18n (>= 0.7, < 2)
22
23
  minitest (~> 5.1)
23
24
  tzinfo (~> 1.1)
24
- zeitwerk (~> 2.2)
25
+ zeitwerk (~> 2.2, >= 2.2.2)
25
26
  byebug (11.1.3)
26
27
  coderay (1.1.2)
27
28
  concurrent-ruby (1.1.6)
@@ -30,6 +31,9 @@ GEM
30
31
  method_source (1.0.0)
31
32
  minitest (5.14.0)
32
33
  mysql2 (0.5.3)
34
+ net-ssh (6.0.2)
35
+ net-ssh-gateway (2.0.0)
36
+ net-ssh (>= 4.0.0)
33
37
  pry (0.13.1)
34
38
  coderay (~> 1.1)
35
39
  method_source (~> 1.0)
data/arql.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'mysql2', '~> 0.5.3'
27
27
  spec.add_dependency 'activerecord', '~> 6.0.0'
28
28
  spec.add_dependency 'activesupport', '~> 6.0.0'
29
+ spec.add_dependency 'net-ssh-gateway', '~> 2.0.0'
29
30
  spec.add_dependency 'pry', '~> 0.13.1'
30
31
  spec.add_dependency 'pry-byebug', '~> 3.9.0'
31
32
  end
data/lib/arql/app.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'net/ssh/gateway'
2
+
1
3
  module Arql
2
4
  class App
3
5
  def initialize(options)
@@ -7,38 +9,46 @@ module Arql
7
9
  end
8
10
 
9
11
  def connect_options
10
- if use_db_cmd_options?
11
- {
12
- adapter: @options.db_adapter,
13
- host: @options.db_host,
14
- username: @options.db_user,
15
- password: @options.db_password || '',
16
- database: @options.db_name,
17
- encoding: @options.db_encoding,
18
- pool: @options.db_pool,
19
- port: @options.db_port
20
- }
21
- else
22
- db_config
12
+ connect_conf = effective_config.slice(:adapter, :host, :username,
13
+ :password, :database, :encoding,
14
+ :pool, :port)
15
+ if effective_config[:ssh].present?
16
+ connect_conf.merge!(start_ssh_proxy!)
23
17
  end
18
+
19
+ connect_conf
20
+ end
21
+
22
+ def start_ssh_proxy!
23
+ ssh_config = effective_config[:ssh]
24
+ @ssh_gateway = Net::SSH::Gateway.new(ssh_config[:host], ssh_config[:user])
25
+ @local_ssh_proxy_port = @ssh_gateway.open(effective_config[:host], effective_config[:port], ssh_config[:local_port])
26
+ {
27
+ host: '127.0.0.1',
28
+ port: @local_ssh_proxy_port
29
+ }
24
30
  end
25
31
 
26
32
  def config
27
33
  @config ||= YAML.load(IO.read(@options.config_file)).with_indifferent_access
28
34
  end
29
35
 
30
- def db_config
31
- config[:db][@options.env]
36
+ def selected_config
37
+ config[@options.env]
38
+ end
39
+
40
+ def effective_config
41
+ @effective_config ||= selected_config.merge(@options.to_h)
32
42
  end
33
43
 
34
44
  def run!
35
45
  show_sql if should_show_sql?
36
46
  write_sql if should_write_sql?
37
47
  append_sql if should_append_sql?
38
- if @options.code.present?
39
- eval(@options.code)
40
- elsif @options.args.present?
41
- @options.args.each { |rb| load(rb) }
48
+ if effective_config[:code].present?
49
+ eval(effective_config[:code])
50
+ elsif effective_config[:args].present?
51
+ effective_config[:args].each { |rb| load(rb) }
42
52
  else
43
53
  run_repl!
44
54
  end
@@ -48,20 +58,16 @@ module Arql
48
58
  Repl.new
49
59
  end
50
60
 
51
- def use_db_cmd_options?
52
- @options.db_host.present?
53
- end
54
-
55
61
  def should_show_sql?
56
- @options.show_sql || db_config[:show_sql]
62
+ effective_config[:show_sql]
57
63
  end
58
64
 
59
65
  def should_write_sql?
60
- @options.write_sql || db_config[:write_sql]
66
+ effective_config[:write_sql]
61
67
  end
62
68
 
63
69
  def should_append_sql?
64
- @options.append_sql || db_config[:append_sql]
70
+ effective_config[:append_sql]
65
71
  end
66
72
 
67
73
  def show_sql
@@ -71,14 +77,14 @@ module Arql
71
77
  end
72
78
 
73
79
  def write_sql
74
- write_sql_file = @options.write_sql || db_config[:write_sql]
80
+ write_sql_file = effective_config[:write_sql]
75
81
  @log_io ||= MultiIO.new
76
82
  ActiveRecord::Base.logger = Logger.new(@log_io)
77
83
  @log_io << File.new(write_sql_file, 'w')
78
84
  end
79
85
 
80
86
  def append_sql
81
- write_sql_file = @options.append_sql || db_config[:append_sql]
87
+ write_sql_file = effective_config[:append_sql]
82
88
  @log_io ||= MultiIO.new
83
89
  ActiveRecord::Base.logger = Logger.new(@log_io)
84
90
  @log_io << File.new(write_sql_file, 'a')
data/lib/arql/cli.rb CHANGED
@@ -10,9 +10,9 @@ module Arql
10
10
  end
11
11
 
12
12
  def parse_options!
13
- @options = OpenStruct.new(db_adapter: 'mysql2',
14
- db_encoding: 'UFF-8',
15
- db_pool: 5,
13
+ @options = OpenStruct.new(adapter: 'mysql2',
14
+ encoding: 'utf8',
15
+ pool: 5,
16
16
  config_file: default_config_file,
17
17
  initializer: default_initializer)
18
18
 
@@ -43,35 +43,35 @@ module Arql
43
43
  end
44
44
 
45
45
  opts.on('-ADB_ADAPTER', '--db-adapter=DB_ADAPTER', 'Specify DB Adapter, default is mysql2') do |db_adapter|
46
- @options.db_adapter = db_adapter
46
+ @options.dapter = db_adapter
47
47
  end
48
48
 
49
49
  opts.on('-HDB_HOST', '--db-host=DB_HOST', 'Specify DB host, if specified -E option will be ignored') do |db_host|
50
- @options.db_host = db_host
50
+ @options.host = db_host
51
51
  end
52
52
 
53
53
  opts.on('-PDB_PORT', '--db-port=DB_PORT', 'Specify DB port, if specified -E option will be ignored') do |db_port|
54
- @options.db_port = db_port.to_i
54
+ @options.port = db_port.to_i
55
55
  end
56
56
 
57
57
  opts.on('-DDB_NAME', '--db-name=DB_NAME', 'Specify database name, if specified -E option will be ignored') do |db_name|
58
- @options.db_name = db_name
58
+ @options.database = db_name
59
59
  end
60
60
 
61
61
  opts.on('-UDB_USER', '--db-user=DB_USER', 'Specify database user, if specified -E option will be ignored') do |db_user|
62
- @options.db_user = db_user
62
+ @options.username = db_user
63
63
  end
64
64
 
65
65
  opts.on('-pDB_PASSWORD', '--db-password=DB_PASSWORD', 'Specify database password, if specified -E option will be ignored') do |db_password|
66
- @options.db_password = db_password
66
+ @options.password = db_password
67
67
  end
68
68
 
69
69
  opts.on('-n', '--db-encoding=DB_ENCODING', 'Specify database encoding, default is UTF-8') do |db_encoding|
70
- @options.db_encoding = db_encoding
70
+ @options.encoding = db_encoding
71
71
  end
72
72
 
73
73
  opts.on('-o', '--db-pool=DB_POOL', 'Specify database pool size, default is 5') do |db_pool|
74
- @options.db_pool = db_pool
74
+ @options.pool = db_pool
75
75
  end
76
76
 
77
77
  opts.on('-eCODE', '--eval=CODE', 'evaluate CODE') do |code|
data/lib/arql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-03 00:00:00.000000000 Z
11
+ date: 2020-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 6.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-ssh-gateway
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry
57
71
  requirement: !ruby/object:Gem::Requirement