dba 2.0.0 → 2.2.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: 7a165d5ff98a815002bea9e1d54744639aba99bb1e678d66afe8743ffcb2fe30
4
- data.tar.gz: dadb161b89dde586047a0a8b6aded72be9499db6c48a27c2e9c57c7172a9c1a9
3
+ metadata.gz: ff91c96a26c84120b2294eaceafbc9cd97d50ae7b8138ed08657efe355fe905b
4
+ data.tar.gz: 1e25615aea3aab8f5820f790d038363ea2854488e950d3925e48953d1055006c
5
5
  SHA512:
6
- metadata.gz: 5f8033d0911e384525fb846228840d4ff5c7527df5c5e0d64fedc6fc158e6e809b5d88ab57483592954e8313961cd23696ae030efe97b7f06a342bfbd40c8c7e
7
- data.tar.gz: 461b1d4e5eb81151aa5350c2f09362da3d6a31a42c959edb48a5dbd97206a239c3f6b4ad8e166e4185df2e6569f63445443af30a41d1064f9679c8dae7aa2a0f
6
+ metadata.gz: b77b8fe626319fe20ac77cb31bb5bd2ed349438ea76ef6472b7367e22a804d1027a99744bde3ad2e32e7104f88a52b125a49f32c40223095281f648f150c8f64
7
+ data.tar.gz: 21d2f2a661aacc27375c7e9031c1057471ca627f0fb1bcb2c47dc051096e9d15d507d186854bb2fbac2b9851ba63ef2c807d7f91814ecd9490c564c6e073bdf1
data/CHANGES.md CHANGED
@@ -1,3 +1,19 @@
1
+ # 2.2.0
2
+
3
+ * Fixed compatibility with psych 4+
4
+
5
+ * The sample command now excludes nil/null values
6
+
7
+
8
+ # 2.1.0
9
+
10
+ * Fixed arity check for commands with optional arguments
11
+
12
+ * Added support for .jsonl extension to dump and load commands
13
+
14
+ * Added support for .ndjson extension to dump and load commands
15
+
16
+
1
17
  # 2.0.0
2
18
 
3
19
  * **Required ruby version is now 2.5.0**
data/dba.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dba'
3
- s.version = '2.0.0'
3
+ s.version = '2.2.0'
4
4
  s.license = 'GPL-3.0'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Tim Craft']
data/lib/dba/command.rb CHANGED
@@ -1,4 +1,16 @@
1
1
  class DBA::Command
2
+ def self.arity_check(args)
3
+ parameters = instance_method(:call).parameters
4
+
5
+ required, optional = parameters.partition { |(type, name)| type == :req }
6
+
7
+ expected = optional.empty? ? required.size : (required.size .. required.size + optional.size)
8
+
9
+ unless expected === args.size
10
+ raise DBA::Error, "incorrect number of arguments (given #{args.size}, expected #{expected})"
11
+ end
12
+ end
13
+
2
14
  def initialize(database)
3
15
  self.database = database
4
16
  end
data/lib/dba/database.rb CHANGED
@@ -64,12 +64,22 @@ module DBA::Database
64
64
  File.exist?('.env')
65
65
  end
66
66
 
67
+ def database_config_path
68
+ File.join('config', 'database.yml')
69
+ end
70
+
67
71
  def database_config?
68
- File.exist?('config/database.yml')
72
+ File.exist?(database_config_path)
69
73
  end
70
74
 
71
75
  def database_config
72
- YAML.load(ERB.new(File.read('config/database.yml')).result)
76
+ source = ERB.new(File.read(database_config_path)).result
77
+
78
+ if YAML.respond_to?(:unsafe_load)
79
+ YAML.unsafe_load(source)
80
+ else
81
+ YAML.load(source)
82
+ end
73
83
  end
74
84
 
75
85
  def development_database_args
data/lib/dba/dump.rb CHANGED
@@ -3,7 +3,9 @@
3
3
  class DBA::Dump < DBA::Command
4
4
  ADAPTERS = {
5
5
  'csv' => :CSV,
6
+ 'jsonl' => :LDJSON,
6
7
  'ldjson' => :LDJSON,
8
+ 'ndjson' => :LDJSON,
7
9
  'yml' => :YAML,
8
10
  'yaml' => :YAML
9
11
  }
data/lib/dba/load.rb CHANGED
@@ -3,7 +3,9 @@
3
3
  class DBA::Load < DBA::Command
4
4
  ADAPTERS = {
5
5
  '.csv' => :CSV,
6
+ '.jsonl' => :LDJSON,
6
7
  '.ldjson' => :LDJSON,
8
+ '.ndjson' => :LDJSON,
7
9
  '.yml' => :YAML,
8
10
  '.yaml' => :YAML
9
11
  }
@@ -26,7 +28,7 @@ class DBA::Load < DBA::Command
26
28
 
27
29
  def file_list(path)
28
30
  if File.directory?(path)
29
- Dir.glob(File.join(path, '*.{csv,ldjson,yml,yaml}'))
31
+ Dir.glob(File.join(path, '*.{csv,jsonl,ldjson,ndjson,yml,yaml}'))
30
32
  else
31
33
  [path]
32
34
  end
data/lib/dba/sample.rb CHANGED
@@ -5,7 +5,7 @@ class DBA::Sample < DBA::Command
5
5
  column_name = column.to_sym if column
6
6
 
7
7
  if column_name
8
- dataset = database[table_name].distinct.select(column_name)
8
+ dataset = database[table_name].exclude(column_name => nil).distinct.select(column_name)
9
9
  dataset.from_self.order(random_function).limit(20).each do |row|
10
10
  puts row[column_name]
11
11
  end
data/lib/dba/shell.rb CHANGED
@@ -16,11 +16,7 @@ module DBA::Shell
16
16
 
17
17
  command = DBA.const_get(command)
18
18
 
19
- arity = command.instance_method(:call).arity
20
-
21
- if arity >= 0 && args.size != arity
22
- raise DBA::Error, "incorrect number of args (given #{args.size}, expected #{arity})"
23
- end
19
+ command.arity_check(args)
24
20
 
25
21
  database = DBA::Database.connect
26
22
 
data/lib/dba.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2019-2021 TIMCRAFT
1
+ # Copyright (c) 2019-2024 TIMCRAFT
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dba
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-06 00:00:00.000000000 Z
11
+ date: 2024-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.1.4
117
+ rubygems_version: 3.4.10
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: See description