prick 0.12.0 → 0.13.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: d22544dd4510ae8e2ca01c940e3020dab601ac8661429be316fa549576f54ab1
4
- data.tar.gz: f94264fb4beea7ede50dd57ede3902e6128ced4230177c6a6a5bbb84662b7f67
3
+ metadata.gz: da40d1823b2163a2ce84de52d2a41aa222ae87afc6bb7cbe22e2d5045a162fba
4
+ data.tar.gz: cee09b71589069b2dbe386afec271ef1677980e0e6d6735462a8c087338e71d9
5
5
  SHA512:
6
- metadata.gz: d1f1b9222fd94b4fdf66137f307c19efe64cdbcc301b00a5904ce7013eedb7652aaf3a5dbabbe0defad7b9f8d7e396a1efbc73fe568d83f46e5c4ef79b9b6760
7
- data.tar.gz: 7eaeb1c2923ed69188e51c071097cca27a1c66d90226f26e99ff26d9e4c7540912ed62be74fda30006d914077faa70e9d384dc02bdbd9e4d0b9753f08f66af92
6
+ metadata.gz: 1b8f5f478092b60b5745983d911f37e516b24957bcdd978157e97263d97c65857e71b1335dc10a7f38fdd742f27c62f4cd28071e4ff31f53cca4f51e88f55557
7
+ data.tar.gz: 7a3efb1a894edfa8b5ca82688b4820126f2898f2448a92d84af49e611b9156bfbf20f34e62deb605ca50cb9fbb57691d6e2ceae2d604fbb6bb6dc3166e751213
data/exe/prick CHANGED
@@ -195,6 +195,13 @@ begin
195
195
  exit 0
196
196
  end
197
197
 
198
+ # Change to parent directory containing the Prick version file if not found
199
+ # in the current directory
200
+ program.current_directory = Dir.getwd
201
+ while !Dir.getwd != "/" && !File.exist?(PRICK_VERSION_FILE)
202
+ Dir.chdir("..")
203
+ end
204
+
198
205
  # Check prick version
199
206
  file = PrickVersion.new
200
207
  file.exist? or raise Prick::Error, "Can't find prick version file '#{file.path}'"
data/lib/prick/program.rb CHANGED
@@ -10,8 +10,10 @@ module Prick
10
10
 
11
11
  attr_accessor :quiet
12
12
  attr_accessor :verbose
13
+ attr_accessor :current_directory # Path to the directory where prick was called from
13
14
 
14
- def initialize(quiet: false, verbose: false)
15
+ def initialize(current_directory = Dir.getwd, quiet: false, verbose: false)
16
+ @current_directory = current_directory
15
17
  @quiet = quiet
16
18
  @verbose = verbose
17
19
  end
@@ -95,8 +97,9 @@ module Prick
95
97
  database = database ? Database.new(database, project.user) : project.database(version)
96
98
  project.load(database, version: version)
97
99
  mesg "Loaded v#{version}", into_mesg, "from cache"
98
- else file = file_or_version
99
- project.load(database, file: file)
100
+ else
101
+ file = file_or_version
102
+ project.load(database, file: norm_path(file))
100
103
  mesg "Loaded #{File.basename(file)}", into_mesg
101
104
  end
102
105
  end
@@ -104,9 +107,8 @@ module Prick
104
107
  def save(version, file)
105
108
  database = project.database(version)
106
109
  database.exist? or raise "Can't find database '#{database}'"
107
- subj_mesg = file ? file : "cache"
108
- project.save(database, file: file)
109
- mesg "Saved #{database} to #{subj_mesg}"
110
+ project.save(database, file: norm_path(file))
111
+ mesg "Saved #{database} to #{file || 'cache'}"
110
112
  end
111
113
 
112
114
  def drop(database, all)
@@ -230,15 +232,16 @@ module Prick
230
232
 
231
233
  # TODO: Create a Backup class and a Project#backup_store object
232
234
  def backup(file = nil)
233
- file = file || File.join(SPOOL_DIR, "#{project.name}-#{Time.now.utc.strftime("%Y%m%d-%H%M%S")}.sql.gz")
234
- project.save(file: file)
235
+ path = norm_path(file) ||
236
+ File.join(SPOOL_DIR, "#{project.name}-#{Time.now.utc.strftime("%Y%m%d-%H%M%S")}.sql.gz")
237
+ project.save(file: path)
235
238
  mesg "Backed-up database to #{file}"
236
239
  end
237
240
 
238
- def restore(file_arg = nil)
239
- file = file_arg || Dir.glob(File.join(SPOOL_DIR, "#{name}-*.sql.gz")).sort.last
240
- File.exist?(file) or raise Error, "Can't find #{file_arg || "any backup file"}"
241
- project.load(file: file)
241
+ def restore(file = nil)
242
+ path = norm_path(file) || Dir.glob(File.join(SPOOL_DIR, "#{name}-*.sql.gz")).sort.last
243
+ File.exist?(path) or raise Error, "Can't find #{file || "any backup file"}"
244
+ project.load(file: path)
242
245
  mesg "Restored database from #{file}"
243
246
  end
244
247
 
@@ -249,6 +252,16 @@ module Prick
249
252
  project_name == project.name or raise Error, "Database not owned by this prick project: #{database}"
250
253
  end
251
254
 
255
+ # Expand relative path with respect to the directory where prick was called
256
+ # from. Return nil if file is nil
257
+ def norm_path(file)
258
+ if file && !file.start_with?("/")
259
+ File.join(current_directory, file)
260
+ else
261
+ file
262
+ end
263
+ end
264
+
252
265
  def mesg(*args) puts args.compact.grep(/\S/).join(' ') if !quiet end
253
266
  def verb(*args) puts args.compact.grep(/\S/).join(' ') if verbose end
254
267
  end
data/lib/prick/version.rb CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Required by gem
6
6
  module Prick
7
- VERSION = "0.12.0"
7
+ VERSION = "0.13.0"
8
8
  end
9
9
 
10
10
  # Project related code starts here
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen