-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check in new loop implementation before regenerating transaction sets
- Loading branch information
Showing
23 changed files
with
988 additions
and
707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "ginny" | ||
|
||
module Eddy | ||
module Build | ||
module Loop | ||
# Generate Ruby code from JSON/YAML EDI definitions. | ||
class Base | ||
|
||
# @return [Eddy::Summary::Loop] | ||
attr_accessor :summary | ||
# @return [String] (nil) | ||
attr_accessor :folder | ||
# Namespace the Loop is within. | ||
# @return [String] | ||
attr_accessor :t_set_id | ||
|
||
# @param summary [Eddy::Summary::Loop] | ||
# @param t_set_id [String] | ||
# @param folder [String] (nil) | ||
# @return [void] | ||
def initialize(summary, t_set_id, folder: nil) | ||
self.summary = summary | ||
self.t_set_id = t_set_id | ||
self.folder = folder | ||
end | ||
|
||
# @return [String] | ||
def render() | ||
return self.ginny_class.render() | ||
end | ||
|
||
# @return [Ginny::Class] | ||
def ginny_class() | ||
return Ginny::Class.create({ | ||
classify_name: false, | ||
parent: "Eddy::Models::Loop::Base", | ||
name: "Base", | ||
description: summary.doc_comment(header: true), | ||
body: <<~STR.strip, | ||
# @param store [Eddy::Data::Store] | ||
# @return [void] | ||
def initialize(store) | ||
@repeat_limit = #{self.summary.repeat_limit} | ||
super(store, Repeat) | ||
end | ||
# Add a repeat of loop #{self.summary.id}. | ||
# | ||
# @yieldparam [Eddy::TransactionSets::#{self.t_set_id}::Loops::#{self.summary.id}::Repeat] rep | ||
# @return [void] | ||
def repeat(&block) | ||
super(&block) | ||
end | ||
STR | ||
}) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "ginny" | ||
|
||
module Eddy | ||
module Build | ||
module Loop | ||
# Generate Ruby code for an EDI loop. | ||
# | ||
# @param summary [Eddy::Summary::Loop] | ||
# @param t_set_id [String] | ||
# @return [String] | ||
def self.render(summary, t_set_id) | ||
base = Eddy::Build::Loop::Base.new(summary, t_set_id).render() | ||
repeat = Eddy::Build::Loop::Repeat.new(summary, t_set_id).render() | ||
return Ginny.mod(("\n" + base + "\n\n" + repeat + "\n"), "Eddy", "TransactionSets", t_set_id, "Loops", summary.id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
require "ginny" | ||
|
||
module Eddy | ||
module Build | ||
module Loop | ||
# Generate Ruby code from JSON/YAML EDI definitions. | ||
class Repeat | ||
|
||
# @return [Eddy::Summary::Loop] | ||
attr_accessor :summary | ||
# Namespace the Loop is within. | ||
# @return [String] | ||
attr_accessor :t_set_id | ||
|
||
# @param summary [Eddy::Summary::Loop] | ||
# @param t_set_id [String] | ||
# @return [void] | ||
def initialize(summary, t_set_id) | ||
self.summary = summary | ||
self.t_set_id = t_set_id | ||
end | ||
|
||
# @return [String] | ||
def render() | ||
return self.ginny_class.render() | ||
end | ||
|
||
# @return [Ginny::Class] | ||
def ginny_class() | ||
return Ginny::Class.create({ | ||
classify_name: false, | ||
parent: "Eddy::Models::Loop::Repeat", | ||
name: "Repeat", | ||
description: "(see Eddy::TransactionSets::#{t_set_id}::Loops::#{self.summary.id}::Base)", | ||
body: <<~STR.strip, | ||
# @param store [Eddy::Data::Store] | ||
# @return [void] | ||
def initialize(store) | ||
#{self.declarations()} | ||
super( | ||
store, | ||
#{self.super_call()} | ||
) | ||
end | ||
#{self.accessors()} | ||
STR | ||
}) | ||
end | ||
|
||
# @return [String] | ||
def repeat_method() | ||
params = self.summary.components.map do |comp| | ||
case comp | ||
when Eddy::Summary::Segment then "# @yieldparam [Eddy::Segments::#{comp.id.upcase}] #{comp.id.downcase}" | ||
when Eddy::Summary::Loop then "# @yieldparam [Eddy::TransactionSets::#{t_set_id}::Loops::#{comp.id.upcase}::Base] #{comp.var_name}" | ||
end | ||
end.compact.join("\n") | ||
return <<~RB | ||
# Add a repeat of loop #{self.summary.id}. | ||
# | ||
#{params} | ||
# @return [void] | ||
def repeat(&block) | ||
super(&block) | ||
end | ||
RB | ||
end | ||
|
||
# @return [String] | ||
def super_call() | ||
return self.summary.components.map do |comp| | ||
case comp | ||
when Eddy::Summary::Segment then " @#{comp.id.downcase}," | ||
when Eddy::Summary::Loop then " @#{comp.var_name}," | ||
end | ||
end.compact.join("\n ") | ||
end | ||
|
||
# @return [String] | ||
def declarations() | ||
self.summary.components.map do |comp| | ||
case comp | ||
when Eddy::Summary::Segment then " @#{comp.id.downcase} = Eddy::Segments::#{comp.id.upcase}.new(store)" | ||
when Eddy::Summary::Loop then " @#{comp.var_name} = Eddy::TransactionSets::#{t_set_id}::Loops::#{comp.id.upcase}::Base.new(store)" | ||
end | ||
end.compact.join("\n") | ||
end | ||
|
||
# @return [String] | ||
def accessors() | ||
defs = self.summary.components.map do |comp| | ||
if comp.is_a?(Eddy::Summary::Loop) && comp.repeat_limit > 1 | ||
self.class.loop_accessor(comp, self.t_set_id) | ||
else | ||
self.class.segment_accessor(comp.id) | ||
end | ||
end | ||
return defs.join("\n\n") | ||
end | ||
|
||
# @param segment_id [String] | ||
# @return [String] | ||
def self.segment_accessor(segment_id) | ||
upper = segment_id.upcase | ||
lower = segment_id.downcase | ||
return <<~RB.strip | ||
# (see Eddy::Segments::#{upper}) | ||
# | ||
# @yieldparam [Eddy::Segments::#{upper}] #{lower} | ||
# @return [Eddy::Segments::#{upper}] | ||
def #{upper}() | ||
yield(@#{lower}) if block_given? | ||
return @#{lower} | ||
end | ||
RB | ||
end | ||
|
||
# @param summary [Eddy::Summary::Loop] | ||
# @param t_set_id [String] | ||
# @return [String] | ||
def self.loop_accessor(summary, t_set_id) | ||
return <<~RB.strip | ||
# (see Eddy::TransactionSets::#{t_set_id}::Loops::#{summary.id.upcase}::Base) | ||
# | ||
# @yieldparam [Eddy::TransactionSets::#{t_set_id}::Loops::#{summary.id.upcase}::Repeat] | ||
# @return [void] | ||
def #{summary.var_name.upcase}() | ||
if block_given? | ||
@#{summary.var_name}.repeat() | ||
else | ||
raise Eddy::Errors::Error, "No block given in loop iteration" | ||
end | ||
return nil | ||
end | ||
RB | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.