Module: PgMeta
- Defined in:
- lib/pg_meta.rb,
lib/pg_meta/dump.rb,
lib/pg_meta/meta.rb,
lib/pg_meta/version.rb,
lib/pg_meta/load_conn.rb,
lib/pg_meta/load_yaml.rb
Defined Under Namespace
Classes: CheckConstraint, Column, Constraint, Database, Error, Function, MaterializedView, Node, PrimaryKeyConstraint, Procedure, ReferentialConstraint, Schema, Table, Trigger, UniqueConstraint, View
Constant Summary collapse
- CONSTRAINT_KINDS =
{ PrimaryKeyConstraint => :primary_key, UniqueConstraint => :unique, CheckConstraint => :check, ReferentialConstraint => :referential }
- VERSION =
"0.2.8"
Class Method Summary collapse
-
.===(element) ⇒ Object
Make the PgMeta module pretend to have PgMeta::Database object instances.
-
.cache(*args, yaml: nil, marshal: nil, **opts) ⇒ Object
Read PgMeta object from cache file and return it.
-
.load_file(file) ⇒ Object
Load data from a YAML file.
- .load_marshal(file) ⇒ Object
-
.load_yaml(yaml) ⇒ Object
Load data from a YAML hash object.
-
.new(*args, exclude_schemas: []) ⇒ Object
:call-seq: initialize(pg_conn_connection) initialize(*pg_conn_initializers).
- .save_file(db, file) ⇒ Object
- .save_marshall(db, file) ⇒ Object
Class Method Details
.===(element) ⇒ Object
Make the PgMeta module pretend to have PgMeta::Database object instances
73 |
# File 'lib/pg_meta.rb', line 73 def self.===(element) element.is_a?(PgMeta::Database) or super end |
.cache(*args, yaml: nil, marshal: nil, **opts) ⇒ Object
Read PgMeta object from cache file and return it. If the file is not present, a new PgMeta object is created and written to the file. The file can be either a yaml (:yaml option) or a Ruby marshal file (:marshall option)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pg_meta.rb', line 30 def self.cache(*args, yaml: nil, marshal: nil, **opts) yaml.nil? != marshal.nil? or raise ArgumentError, "Require either of :yaml or :marshal" file = yaml || marshal kind = yaml ? :yaml : :marshal if File.exist?(file) if yaml load_file(file) else load_marshal(file) end else db = self.new(*args, **opts) case kind when :yaml; save_file(db, file) when :marshall; save_marshal(db, file) end db end end |
.load_file(file) ⇒ Object
Load data from a YAML file
56 57 58 |
# File 'lib/pg_meta.rb', line 56 def self.load_file(file) load_yaml(YAML.unsafe_load(IO.read file)) end |
.load_marshal(file) ⇒ Object
64 65 66 |
# File 'lib/pg_meta.rb', line 64 def self.load_marshal(file) Marshal.load(IO.read file) end |
.load_yaml(yaml) ⇒ Object
Load data from a YAML hash object
51 52 53 |
# File 'lib/pg_meta.rb', line 51 def self.load_yaml(yaml) Database.load_yaml(yaml) end |
.new(*args, exclude_schemas: []) ⇒ Object
:call-seq:
initialize(pg_conn_connection)
initialize(*pg_conn_initializers)
Initialize a Database object
22 23 24 |
# File 'lib/pg_meta.rb', line 22 def self.new(*args, exclude_schemas: []) Database.load_conn(PgConn.ensure(*args), exclude_schemas: exclude_schemas) end |
.save_file(db, file) ⇒ Object
60 61 62 |
# File 'lib/pg_meta.rb', line 60 def self.save_file(db, file) IO.write(file, db.to_h.to_yaml) end |
.save_marshall(db, file) ⇒ Object
68 69 70 |
# File 'lib/pg_meta.rb', line 68 def self.save_marshall(db, file) IO.write(file, Marshal.dump(db)) end |