Class: ActiveCypher::Schema::Dumper
- Inherits:
-
Object
- Object
- ActiveCypher::Schema::Dumper
- Defined in:
- lib/active_cypher/schema/dumper.rb
Overview
Dumps the graph schema to a Cypher script
Constant Summary collapse
- DEFAULT_PATH =
'graphdb'
Class Method Summary collapse
Instance Method Summary collapse
- #dump_to_file(path) ⇒ Object
- #dump_to_string ⇒ Object
-
#initialize(connection = ActiveCypher::Base.connection, base_dir: Dir.pwd) ⇒ Dumper
constructor
A new instance of Dumper.
Constructor Details
#initialize(connection = ActiveCypher::Base.connection, base_dir: Dir.pwd) ⇒ Dumper
Returns a new instance of Dumper.
12 13 14 15 |
# File 'lib/active_cypher/schema/dumper.rb', line 12 def initialize(connection = ActiveCypher::Base.connection, base_dir: Dir.pwd) @connection = connection @base_dir = base_dir end |
Class Method Details
.output_file(conn) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_cypher/schema/dumper.rb', line 49 def self.output_file(conn) case conn.to_sym when :primary File.join(DEFAULT_PATH, 'schema.cypher') when :analytics File.join(DEFAULT_PATH, 'schema.analytics.cypher') else File.join(DEFAULT_PATH, "schema.#{conn}.cypher") end end |
.run_from_cli(argv = ARGV) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_cypher/schema/dumper.rb', line 29 def self.run_from_cli(argv = ARGV) opts = { stdout: false, connection: :primary } OptionParser.new do |o| o.on('--stdout') { opts[:stdout] = true } o.on('--connection=NAME') { |v| opts[:connection] = v.to_sym } end.parse!(argv) pool = ActiveCypher::Base.connection_handler.pool(opts[:connection]) raise "Unknown connection: #{opts[:connection]}" unless pool dumper = new(pool.connection) file = output_file(opts[:connection]) if opts[:stdout] puts dumper.dump_to_string else dumper.dump_to_file(file) puts "Written #{file}" end end |
Instance Method Details
#dump_to_file(path) ⇒ Object
23 24 25 26 27 |
# File 'lib/active_cypher/schema/dumper.rb', line 23 def dump_to_file(path) FileUtils.mkdir_p(File.dirname(path)) File.write(path, dump_to_string) path end |
#dump_to_string ⇒ Object
17 18 19 20 21 |
# File 'lib/active_cypher/schema/dumper.rb', line 17 def dump_to_string cat = @connection.schema_catalog cat = catalog_from_migrations if cat.respond_to?(:empty?) && cat.empty? Writer::Cypher.new(cat, @connection.vendor).to_s end |