Class: Ea::Cli::Command::Export

Inherits:
Base
  • Object
show all
Defined in:
lib/ea/cli/command/export.rb

Overview

ea export SUB FILE where SUB ∈ json, plantuml, xsd.

Routes to the appropriate Exporter based on sub. Each exporter lives under Ea::Export::* and implements call(model, **opts) → String. Adding a new format = adding a new exporter (OCP), no changes to this command.

Constant Summary collapse

COLUMNS =
%i[format bytes_written path].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Ea::Cli::Command::Base

Class Method Details

.load_if_present(path, loader) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/ea/cli/command/export.rb', line 62

def self.load_if_present(path, loader)
  return nil unless File.exist?(path)

  loader.from_path(path)
rescue StandardError
  nil
end

.xsd_options(opts) ⇒ Object

Load GMLClassMapping + GMLNamespaces fixtures when present (repo-local dev path) and pass to the XSD generator. Keeps fixture-path knowledge in the CLI layer; lib stays pure.



52
53
54
55
56
57
58
59
60
# File 'lib/ea/cli/command/export.rb', line 52

def self.xsd_options(opts)
  mapping = load_if_present("spec/fixtures/mdg/ea_config/gml/GMLClassMapping.xml",
                            Ea::Export::Xsd::ClassMapping)
  namespaces = load_if_present("spec/fixtures/mdg/ea_config/gml/GMLNamespaces.xml",
                                Ea::Export::Xsd::NamespaceRegistry)
  opts[:class_mapping] = mapping if mapping
  opts[:namespaces] = namespaces if namespaces
  opts
end

Instance Method Details

#callObject



17
18
19
20
21
22
# File 'lib/ea/cli/command/export.rb', line 17

def call
  validate_file!(file_path)
  output = exporter.call(model, **exporter_options)
  path = write_output(output, default_name: default_name)
  formatter.render([[sub, output.bytesize, path]], columns: COLUMNS)
end