Module: Stupidedi::Schema::Generation
- Defined in:
- lib/stupidedi/schema/generation.rb,
lib/stupidedi/schema/generation/models.rb,
lib/stupidedi/schema/generation/runner.rb,
lib/stupidedi/schema/generation/support.rb,
lib/stupidedi/schema/generation/version_modules.rb,
lib/stupidedi/schema/generation/flat_file_reader.rb,
lib/stupidedi/schema/generation/element_generator.rb,
lib/stupidedi/schema/generation/segment_generator.rb,
lib/stupidedi/schema/generation/definition_generator.rb,
lib/stupidedi/schema/generation/interchange_generator.rb,
lib/stupidedi/schema/generation/registration_generator.rb,
lib/stupidedi/schema/generation/master_loader_generator.rb,
lib/stupidedi/schema/generation/module_loader_generator.rb,
lib/stupidedi/schema/generation/support_modules_generator.rb,
lib/stupidedi/schema/generation/functional_group_generator.rb
Overview
Grammar generation: turns ASC X12 Table Data flat files into Stupidedi grammar definition source files.
The gem ships the generation machine only. The X12 Table Data it reads is licensed X12 IP and is supplied by the consumer; the generated grammar files are a derivative of that IP and belong to the consumer. Nothing here bundles X12 content.
Stupidedi::Schema::Generation.run(
table_data: "vendor/x12/table_data/005010",
release: "005010",
out: "lib"
)
Defined Under Namespace
Modules: Models, Support Classes: DefinitionGenerator, ElementGenerator, FlatFileReader, FunctionalGroupGenerator, InterchangeGenerator, MasterLoaderGenerator, ModuleLoaderGenerator, RegistrationGenerator, Runner, SegmentGenerator, SupportModulesGenerator
Constant Summary collapse
- VERSION_MODULES =
Maps 6-digit ASC X12 release codes to the Ruby module names used by the generated grammar (e.g. "005010" => "FiftyTen"). This is the canonical list of releases the generator supports.
{ "003060" => "ThirtySixty", "004010" => "FortyTen", "004060" => "FortySixty", "005010" => "FiftyTen", "006010" => "SixtyTen", "007010" => "SeventyTen", "008010" => "EightyTen" }.freeze
- REQUIREMENT_MAP =
Maps X12 requirement designators to Stupidedi ElementReq names. Note: Conditional -> Relational and NotUsed -> Optional are deliberate.
{ "Mandatory" => "Mandatory", "Optional" => "Optional", "Conditional" => "Relational", "NotUsed" => "Optional" }.freeze
- NAMESPACE_FORMAT =
A valid output namespace is a single Ruby constant name (e.g. "Edi"). Nested namespaces ("Acme::Grammars") are not supported: the generated code uses
module <namespace>directly, which only works for a single top-level constant. /\A[A-Z]\w*\z/
Class Method Summary collapse
-
.register(out:, namespace: "Edi", write: true, logger: nil) ⇒ Object
Rebuild the whole-tree aggregation artifacts by scanning the live output tree: stupidedi_registration.rb always, and the master loader too when one is present (so the rebuilt registration's constants are actually required; otherwise require "edi" would resolve to a NameError).
-
.run(table_data:, release:, out:, namespace: "Edi", write: true, master_loader: false, logger: nil) ⇒ Object
Generate the full grammar for one release.
-
.validate_namespace!(namespace) ⇒ Object
Validates the output namespace is a single Ruby constant name and returns it.
Class Method Details
.register(out:, namespace: "Edi", write: true, logger: nil) ⇒ Object
Rebuild the whole-tree aggregation artifacts by scanning the live output
tree: stupidedi_registration.rb always, and the master loader too when one
is present (so the rebuilt registration's constants are actually required;
otherwise require "edi" would resolve to a NameError). Useful after adding
or removing releases by other means; run already keeps these current for
the releases it generates. Returns the paths (re)generated.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/stupidedi/schema/generation.rb', line 65 def self.register(out:, namespace: "Edi", write: true, logger: nil) validate_namespace!(namespace) paths = [write_artifact(RegistrationGenerator.new(roots: [out], namespace: namespace), out, write, logger)] master_loader = MasterLoaderGenerator.new(roots: [out], namespace: namespace) if File.exist?(File.join(out, master_loader.output_path)) paths << write_artifact(master_loader, out, write, logger) end paths end |
.run(table_data:, release:, out:, namespace: "Edi", write: true, master_loader: false, logger: nil) ⇒ Object
Generate the full grammar for one release. See Runner for options. master_loader: true also emits a single-require entry file (e.g. edi.rb).
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/stupidedi/schema/generation.rb', line 47 def self.run(table_data:, release:, out:, namespace: "Edi", write: true, master_loader: false, logger: nil) Runner.new( table_data: table_data, release: release, out: out, namespace: namespace, write: write, master_loader: master_loader, logger: logger ).run end |
.validate_namespace!(namespace) ⇒ Object
Validates the output namespace is a single Ruby constant name and returns it. Raises ArgumentError otherwise. See NAMESPACE_FORMAT.
37 38 39 40 41 42 43 |
# File 'lib/stupidedi/schema/generation.rb', line 37 def self.validate_namespace!(namespace) return namespace if namespace.to_s =~ NAMESPACE_FORMAT raise ArgumentError, %(namespace must be a single Ruby constant name like "Edi" ) + %(got #{namespace.inspect}; nested namespaces ("::") are not supported) end |