Skip to content

Commit

Permalink
Use Sumary classes in TransactionSetBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
tcd committed Jan 2, 2020
1 parent 2cd33f3 commit cca92f0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
53 changes: 28 additions & 25 deletions lib/eddy/build/transaction_set_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ def constructor()
def declarations()
decs = ""
self.summary.components.each do |comp|
if comp.key?(:loop_id)
if comp[:repeat] == 1
decs << "@#{comp[:loop_id].downcase} = Eddy::Segments::#{comp[:loop_id].upcase}.new(store)\n"
case comp
when Eddy::Schema::SegmentSummary
decs << "@#{comp.id.downcase} = Eddy::Segments::#{comp.id.upcase}.new(store)\n"
when Eddy::Schema::LoopSummary
if comp.repeat == 1
decs << "@#{comp.loop_id.downcase} = Eddy::Segments::#{comp.loop_id.upcase}.new(store)\n"
else
decs << "@l_#{comp[:loop_id].downcase} = Eddy::TransactionSets::#{self.summary.normalized_name}::Loops::#{comp[:loop_id].upcase}.new(store)\n"
decs << "@l_#{comp.loop_id.downcase} = Eddy::TransactionSets::#{self.summary.normalized_name}::Loops::#{comp.loop_id.upcase}.new(store)\n"
end
else
decs << "@#{comp[:id].downcase} = Eddy::Segments::#{comp[:id].upcase}.new(store)\n"
end
end
return decs
Expand All @@ -114,14 +115,15 @@ def super_call()
super_call = "super(\n"
super_call << " store,\n"
self.summary.components.each do |comp|
if comp.key?(:loop_id)
if comp[:repeat] == 1
super_call << " @#{comp[:loop_id].downcase},\n"
case comp
when Eddy::Schema::SegmentSummary
super_call << " @#{comp.id.downcase},\n"
when Eddy::Schema::LoopSummary
if comp.repeat == 1
super_call << " @#{comp.loop_id.downcase},\n"
else
super_call << " @l_#{comp[:loop_id].downcase},\n"
super_call << " @l_#{comp.loop_id.downcase},\n"
end
else
super_call << " @#{comp[:id].downcase},\n"
end
end
super_call << ")"
Expand All @@ -132,15 +134,16 @@ def super_call()

# @return [String]
def accessors()
defs = self.summary.components.map do |c|
if c.key?(:loop_id)
if c[:repeat] == 1
Eddy::Build::TransactionSetBuilder.segment_accessor(c[:loop_id])
defs = self.summary.components.map do |comp|
case comp
when Eddy::Schema::SegmentSummary
Eddy::Build::TransactionSetBuilder.segment_accessor(comp.id)
when Eddy::Schema::LoopSummary
if comp.repeat == 1
Eddy::Build::TransactionSetBuilder.segment_accessor(comp.loop_id)
else
Eddy::Build::TransactionSetBuilder.loop_accessor(c, self.summary.normalized_name)
Eddy::Build::TransactionSetBuilder.loop_accessor(comp, self.summary.normalized_name)
end
else
Eddy::Build::TransactionSetBuilder.segment_accessor(c[:id])
end
end
return defs.join("\n\n")
Expand All @@ -162,12 +165,12 @@ def #{upper}()
RB
end

# @param summary [Hash] LoopSummary
# @param summary [Eddy::Schema::LoopSummary]
# @param t_set_name [String]
# @return [String]
def self.loop_accessor(summary, t_set_name)
upper = summary[:loop_id].upcase
lower = summary[:loop_id].downcase
upper = summary.loop_id.upcase
lower = summary.loop_id.downcase
return <<~RB.strip
# (see Eddy::TransactionSets::#{t_set_name}::Loops::#{upper})
#{self.loop_components(summary, t_set_name)}
Expand All @@ -183,14 +186,14 @@ def L_#{upper}(&block)
RB
end

# @param summary [Hash] LoopSummary
# @param summary [Eddy::Schema::LoopSummary]
# @param t_set_name [String]
# @return [String]
def self.loop_components(summary, t_set_name)
comps = []
summary[:components].each do |comp|
summary.components.each do |comp|
if comp.key?(:loop_id)
comps << "# @yieldparam [Eddy::TransactionSets::TS#{t_set_name}::Loops#{comp[:loop_id].upcase}] l_#{comp[:id].downcase}"
comps << "# @yieldparam [Eddy::TransactionSets::#{t_set_name}::Loops::#{comp[:loop_id].upcase}] l_#{comp[:loop_id].downcase}"
else
comps << "# @yieldparam [Eddy::Segments::#{comp[:id].upcase}] #{comp[:id].downcase}"
end
Expand Down
3 changes: 1 addition & 2 deletions lib/eddy/schema/transaction_set_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def self.create(params = {})
summary.id = params[:id]
summary.name = params[:name]
summary.functional_group = params[:functional_group]
# summary.process_components(params[:components])
summary.components = params[:components]
summary.process_components(params[:components])
return summary
end

Expand Down
20 changes: 20 additions & 0 deletions test/eddy/build/transaction_set_builder/ts810_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "test_helper"

module BuildTest
module TransactionSetBuilderTest
class TS810Test < Minitest::Test

def setup
@summary = Eddy::Schema::TransactionSetSummary.from_file(file_fixture("schema/810.edi.yml"))
@ts810 = File.read(File.join(Eddy::Util.root_dir, "lib/definitions/transaction_sets/manual/810/810.rb")).strip
@loops = File.read(File.join(Eddy::Util.root_dir, "lib/definitions/transaction_sets/manual/810/loops.rb")).strip
end

def test_transaction_set_builder
have = Eddy::Build::TransactionSetBuilder.from_summary(@summary).ginny_class.render()
assert_equal(@ts810, have)
end

end
end
end

0 comments on commit cca92f0

Please sign in to comment.