pg_meta 0.2.6 → 0.2.7

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: f0d741d0b68b88b139a2dbd981877cce8f73678d975187f4953fbdc07eab2d3a
4
- data.tar.gz: 6d5783a4deb8d4141ee423126a5d17325bbff9682b5839493ad1f97c28e99496
3
+ metadata.gz: 58339598c12ed8e286ecdd941ab1497947e5de3001c1dd1434888c05056551ba
4
+ data.tar.gz: e4b3bcf44fe2286760fd83841f8e42d5ca98a09cf08a8f3406f78a1d76c25671
5
5
  SHA512:
6
- metadata.gz: b001fd75b740c0802b8b5ff30c6bbe9497172e84585f71afffb272bb75dad67bf3f28c8d5fe4be28b57d620fc5fad770b8e36147370870064731c139adf2dc15
7
- data.tar.gz: e4a7faf1ffd89e923af720fa97651e94edace462d9d6b7b496efabb0f22ce2905e1f5212b8d788f8df85365f7dc47e05e2ba201216e3ef002b1c3a68b1b7698d
6
+ metadata.gz: a6918852294bd4207e93dc1730a64e6b4036db0807c2158de808da264de7200a34e08c8f40b7b59a07fbc454e098fdd9a9fbc436a2dd8bf5972e51a8aa7d8beb
7
+ data.tar.gz: 7c7c1166566190064ef0f45c24c2eee1b5a23fb89272963951203e915fd0a23cc8be5fc37c7499920684d754e0ee543e897bd20961667b31ab0536c9b651ce3a
@@ -1,3 +1,3 @@
1
1
  module PgMeta
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
data/lib/pg_meta.rb CHANGED
@@ -23,6 +23,10 @@ module PgMeta
23
23
  Database.load_conn(PgConn.ensure(*args), exclude_schemas: exclude_schemas)
24
24
  end
25
25
 
26
+ # Read PgMeta object from cache file and return it. If the file is not
27
+ # present, a new PgMeta object is created and written to the file. The file
28
+ # can be either a yaml (:yaml option) or a Ruby marshal file (:marshall
29
+ # option)
26
30
  def self.cache(*args, yaml: nil, marshal: nil, **opts)
27
31
  yaml.nil? != marshal.nil? or raise ArgumentError, "Require either of :yaml or :marshal"
28
32
  file = yaml || marshal
@@ -35,25 +39,36 @@ module PgMeta
35
39
  end
36
40
  else
37
41
  db = self.new(*args, **opts)
38
- IO.write(file, db.to_yaml)
42
+ case kind
43
+ when :yaml; save_file(db, file)
44
+ when :marshall; save_marshal(db, file)
45
+ end
46
+ db
39
47
  end
40
48
  end
41
49
 
42
- # Load data from a YAML object
50
+ # Load data from a YAML hash object
43
51
  def self.load_yaml(yaml)
44
52
  Database.load_yaml(yaml)
45
53
  end
46
54
 
47
55
  # Load data from a YAML file
48
56
  def self.load_file(file)
49
- exit
50
- load_yaml(YAML.load(IO.read file))
57
+ load_yaml(YAML.unsafe_load(IO.read file))
58
+ end
59
+
60
+ def self.save_file(db, file)
61
+ IO.write(file, db.to_h.to_yaml)
51
62
  end
52
63
 
53
64
  def self.load_marshal(file)
54
65
  Marshal.load(IO.read file)
55
66
  end
56
67
 
68
+ def self.save_marshall(db, file)
69
+ IO.write(file, Marshal.dump(db))
70
+ end
71
+
57
72
  # Make the PgMeta module pretend to have PgMeta::Database object instances
58
73
  def self.===(element) element.is_a?(PgMeta::Database) or super end
59
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-24 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: indented_io
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubygems_version: 3.3.18
170
+ rubygems_version: 3.3.7
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: pg_meta gem