lancelot 0.3.3 → 0.3.4

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: b6da55f7ccdf6c0b08d1e317e63a627573e9599af9fe2c2f7c93ab8cdefc755d
4
- data.tar.gz: fd75f76de200412842b7ad963a54dff99e691cf6a4a9c4e1df37ea65587c23a1
3
+ metadata.gz: 1861aeee032e7c7e742136fa606816034a5b22812862265e17bdf5c5ef1717cb
4
+ data.tar.gz: a0154bea94678710902d6696deb71f62e4b0fafafbe4adca8433ddb81c17074b
5
5
  SHA512:
6
- metadata.gz: 44762f80ae8374f6ecf930360ca30b7e6987bbd978ae40d1fdb0c69093cc22d68877f5af2d18e25d088a13d386a2cfaba663c48d118c310e061ad130d5d86f1f
7
- data.tar.gz: 976fee93527713f6404d9a3057e2feaa2d9b2f38601280a961c30653e9706a762aab2d1bf729dcee0b3954d4c07103f2db02e788736853ae70cd026bda0f8021
6
+ metadata.gz: 550b2dde6c3868f62ddc1247a44045a07a46352dc4d6b3466876a35b5b4cae6d0df0b93faf41d45cdaec99092e074b72cac67a7a3dec53f268df11bacf791812
7
+ data.tar.gz: 32fab876ba1873e7648b4c9174e773cf69b604d158f7b71449172670363080390a7365b581f121d2d459a5516aaecc9c56f8f36925b1307b290f2f182d266f95
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
4
+
3
5
  module Lancelot
4
6
  class Dataset
5
7
  class << self
@@ -15,10 +17,40 @@ module Lancelot
15
17
  dataset
16
18
  end
17
19
 
18
- def open_or_create(path, schema:)
20
+ def open_or_create(path, schema:, mode: nil)
21
+ # Check if path exists
19
22
  if File.exist?(path)
20
- open(path)
23
+ # Check if it's a file instead of directory
24
+ if File.file?(path)
25
+ if mode == "overwrite"
26
+ # Remove the file and create dataset
27
+ FileUtils.rm_f(path)
28
+ create(path, schema: schema)
29
+ else
30
+ raise ArgumentError, "Path #{path} exists as a file, not a directory. " \
31
+ "Use mode: 'overwrite' to replace it, or choose a different path."
32
+ end
33
+ # Path exists as directory - check if it's a valid Lance dataset
34
+ elsif File.exist?(File.join(path, "_versions"))
35
+ # Valid dataset exists - open it
36
+ open(path)
37
+ elsif !Dir.empty?(path)
38
+ # Non-empty directory that's not a Lance dataset
39
+ if mode == "overwrite"
40
+ # User explicitly wants to overwrite - remove and create new
41
+ FileUtils.rm_rf(path)
42
+ create(path, schema: schema)
43
+ else
44
+ # Fail safely - don't overwrite existing non-dataset directory
45
+ raise ArgumentError, "Directory exists at #{path} but is not a valid Lance dataset. " \
46
+ "Use mode: 'overwrite' to replace it, or choose a different path."
47
+ end
48
+ else
49
+ # Empty directory - safe to create dataset
50
+ create(path, schema: schema)
51
+ end
21
52
  else
53
+ # Path doesn't exist - create new dataset
22
54
  create(path, schema: schema)
23
55
  end
24
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lancelot
4
- VERSION = "0.3.3"
4
+ VERSION = "0.3.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lancelot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Petersen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-09-06 00:00:00.000000000 Z
11
+ date: 2025-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys