Skip to content

Commit

Permalink
More updates to build code
Browse files Browse the repository at this point in the history
  • Loading branch information
tcd committed Jan 7, 2020
1 parent 0d34c24 commit 9fc34f8
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 82 deletions.
4 changes: 1 addition & 3 deletions lib/eddy/build/loop/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def initialize(store)
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
# @yieldparam [Eddy::TransactionSets::#{self.t_set_id}::Loops::#{self.summary.id}::Repeat]
# @return [void]
def repeat(&block)
super(&block)
Expand Down
58 changes: 25 additions & 33 deletions lib/eddy/build/transaction_set_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ class TransactionSetBuilder

# @return [Eddy::Summary::TransactionSet]
attr_accessor :summary
# @return [String] (nil)
attr_accessor :folder
# @return [Boolean] (false)
attr_accessor :headers

# @param summary [Eddy::Summary::TransactionSet]
# @param folder [String] (nil)
# @param headers [Boolean] (false)
# @return [void]
def initialize(folder: nil, headers: false)
self.folder = folder
self.headers = headers
def initialize(summary, folder: nil)
self.summary = summary
@folder = folder
end

def_delegators(
Expand All @@ -36,41 +32,37 @@ def initialize(folder: nil, headers: false)
def self.from_file(path, **kwargs)
raise Eddy::Errors::Error, "Invalid transaction set definition" unless Eddy::Summary.valid_transaction_set_data?(path)
data = Eddy::Util.read_json_or_yaml(path)
builder = new(**kwargs)
builder.summary = Eddy::Summary::TransactionSet.create(data)
return builder
return new(Eddy::Summary::TransactionSet.create(data), **kwargs)
end

# @param summary [Eddy::Summary::TransactionSet]
# @param (see #initialize)
# @return [Eddy::Build::TransactionSetBuilder]
def self.from_summary(summary, **kwargs)
builder = new(**kwargs)
builder.summary = summary
return builder
# @return [String]
def folder()
root_path = @folder || File.join(Eddy::Util.root_dir, "build", "transaction_sets")
path = File.join(root_path, self.id.to_s)
FileUtils.mkdir_p(path)
return path
end

# @return [String]
def build()
root_path = self.folder || File.join(Eddy::Util.root_dir, "build", "transaction_sets")
path = File.join(root_path, self.id.to_s)
FileUtils.mkdir_p(path)
File.open(File.join(path, "loops.rb"), "a") { |f| f.write(self.render_loops) }
return self.ginny_class.generate(path)
self.build_loops()
return self.ginny_class.generate(self.folder, "#{self.id}.rb")
end

# @return [String]
def render()
return self.ginny_class.render()
end

# # @return [String]
# def render_loops()
# loops = self.summary.unique_loops.map do |l|
# Eddy::Build::LoopBuilder.from_summary(l, t_set_id: self.normalized_name).ginny_class.render()
# end.join("\n\n")
# return Ginny.mod(("\n" + loops + "\n"), "Eddy", "TransactionSets", self.normalized_name, "Loops")
# end
# @return [String]
def build_loops()
FileUtils.mkdir_p(File.join(self.build_path, "loops"))
self.summary.unique_loops.each do |looop|
File.open(File.join(self.build_path, "loops", "#{looop.normalized_name}.rb"), "a") do |f|
f.write(Eddy::Build::Loop.render(looop, self.normalized_name) + "\n")
end
end
end

# @return [Ginny::Class]
def ginny_class()
Expand Down Expand Up @@ -159,7 +151,7 @@ def self.segment_accessor(segment_id)
return <<~RB.strip
# (see Eddy::Segments::#{upper})
#
# @yieldparam [Eddy::Segments::#{upper}] #{lower}
# @yieldparam [Eddy::Segments::#{upper}]
# @return [Eddy::Segments::#{upper}]
def #{upper}()
yield(@#{lower}) if block_given?
Expand All @@ -177,9 +169,9 @@ def self.loop_accessor(summary, t_set_id)
#
# @yieldparam [Eddy::TransactionSets::#{t_set_id}::Loops::#{summary.id.upcase}::Repeat]
# @return [void]
def #{summary.var_name.upcase}()
def #{summary.var_name.upcase}(&block)
if block_given?
@#{summary.var_name}.repeat()
@#{summary.var_name}.repeat(&block)
else
raise Eddy::Errors::Error, \"No block given in loop iteration\"
end
Expand Down
8 changes: 2 additions & 6 deletions test/eddy/build/loop/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def initialize(store)
super(store, Repeat)
end
# Add a repeat of loop N1.
#
# @yieldparam [Eddy::TransactionSets::TS850::Loops::N1::Repeat] rep
# @yieldparam [Eddy::TransactionSets::TS850::Loops::N1::Repeat]
# @return [void]
def repeat(&block)
super(&block)
Expand Down Expand Up @@ -53,9 +51,7 @@ def initialize(store)
super(store, Repeat)
end
# Add a repeat of loop IT1.
#
# @yieldparam [Eddy::TransactionSets::TS810::Loops::IT1::Repeat] rep
# @yieldparam [Eddy::TransactionSets::TS810::Loops::IT1::Repeat]
# @return [void]
def repeat(&block)
super(&block)
Expand Down
8 changes: 3 additions & 5 deletions test/eddy/build/loop/render/it1_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def initialize(store)
super(store, Repeat)
end
# Add a repeat of loop IT1.
#
# @yieldparam [Eddy::TransactionSets::TS810::Loops::IT1::Repeat] rep
# @yieldparam [Eddy::TransactionSets::TS810::Loops::IT1::Repeat]
# @return [void]
def repeat(&block)
super(&block)
Expand All @@ -58,7 +56,7 @@ def initialize(store)
# (see Eddy::Segments::IT1)
#
# @yieldparam [Eddy::Segments::IT1] it1
# @yieldparam [Eddy::Segments::IT1]
# @return [Eddy::Segments::IT1]
def IT1()
yield(@it1) if block_given?
Expand All @@ -67,7 +65,7 @@ def IT1()
# (see Eddy::Segments::CTP)
#
# @yieldparam [Eddy::Segments::CTP] ctp
# @yieldparam [Eddy::Segments::CTP]
# @return [Eddy::Segments::CTP]
def CTP()
yield(@ctp) if block_given?
Expand Down
10 changes: 4 additions & 6 deletions test/eddy/build/loop/render/n1_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def initialize(store)
super(store, Repeat)
end
# Add a repeat of loop N1.
#
# @yieldparam [Eddy::TransactionSets::TS850::Loops::N1::Repeat] rep
# @yieldparam [Eddy::TransactionSets::TS850::Loops::N1::Repeat]
# @return [void]
def repeat(&block)
super(&block)
Expand All @@ -55,7 +53,7 @@ def initialize(store)
# (see Eddy::Segments::N1)
#
# @yieldparam [Eddy::Segments::N1] n1
# @yieldparam [Eddy::Segments::N1]
# @return [Eddy::Segments::N1]
def N1()
yield(@n1) if block_given?
Expand All @@ -64,7 +62,7 @@ def N1()
# (see Eddy::Segments::N3)
#
# @yieldparam [Eddy::Segments::N3] n3
# @yieldparam [Eddy::Segments::N3]
# @return [Eddy::Segments::N3]
def N3()
yield(@n3) if block_given?
Expand All @@ -73,7 +71,7 @@ def N3()
# (see Eddy::Segments::N4)
#
# @yieldparam [Eddy::Segments::N4] n4
# @yieldparam [Eddy::Segments::N4]
# @return [Eddy::Segments::N4]
def N4()
yield(@n4) if block_given?
Expand Down
10 changes: 5 additions & 5 deletions test/eddy/build/loop/repeat_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(store)
# (see Eddy::Segments::N1)
#
# @yieldparam [Eddy::Segments::N1] n1
# @yieldparam [Eddy::Segments::N1]
# @return [Eddy::Segments::N1]
def N1()
yield(@n1) if block_given?
Expand All @@ -33,7 +33,7 @@ def N1()
# (see Eddy::Segments::N3)
#
# @yieldparam [Eddy::Segments::N3] n3
# @yieldparam [Eddy::Segments::N3]
# @return [Eddy::Segments::N3]
def N3()
yield(@n3) if block_given?
Expand All @@ -42,7 +42,7 @@ def N3()
# (see Eddy::Segments::N4)
#
# @yieldparam [Eddy::Segments::N4] n4
# @yieldparam [Eddy::Segments::N4]
# @return [Eddy::Segments::N4]
def N4()
yield(@n4) if block_given?
Expand Down Expand Up @@ -77,7 +77,7 @@ def initialize(store)
# (see Eddy::Segments::IT1)
#
# @yieldparam [Eddy::Segments::IT1] it1
# @yieldparam [Eddy::Segments::IT1]
# @return [Eddy::Segments::IT1]
def IT1()
yield(@it1) if block_given?
Expand All @@ -86,7 +86,7 @@ def IT1()
# (see Eddy::Segments::CTP)
#
# @yieldparam [Eddy::Segments::CTP] ctp
# @yieldparam [Eddy::Segments::CTP]
# @return [Eddy::Segments::CTP]
def CTP()
yield(@ctp) if block_given?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_segment_accessor
want = <<~RB.strip
# (see Eddy::Segments::CTT)
#
# @yieldparam [Eddy::Segments::CTT] ctt
# @yieldparam [Eddy::Segments::CTT]
# @return [Eddy::Segments::CTT]
def CTT()
yield(@ctt) if block_given?
Expand All @@ -24,9 +24,9 @@ def test_loop_accessor
#
# @yieldparam [Eddy::TransactionSets::TS810::Loops::N1::Repeat]
# @return [void]
def L_N1()
def L_N1(&block)
if block_given?
@l_n1.repeat()
@l_n1.repeat(&block)
else
raise Eddy::Errors::Error, "No block given in loop iteration"
end
Expand Down
26 changes: 13 additions & 13 deletions test/eddy/build/transaction_set_builder/ts810_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def initialize(store)
# (see Eddy::Segments::BIG)
#
# @yieldparam [Eddy::Segments::BIG] big
# @yieldparam [Eddy::Segments::BIG]
# @return [Eddy::Segments::BIG]
def BIG()
yield(@big) if block_given?
Expand All @@ -61,7 +61,7 @@ def BIG()
# (see Eddy::Segments::REF)
#
# @yieldparam [Eddy::Segments::REF] ref
# @yieldparam [Eddy::Segments::REF]
# @return [Eddy::Segments::REF]
def REF()
yield(@ref) if block_given?
Expand All @@ -72,9 +72,9 @@ def REF()
#
# @yieldparam [Eddy::TransactionSets::TS810::Loops::N1::Repeat]
# @return [void]
def L_N1()
def L_N1(&block)
if block_given?
@l_n1.repeat()
@l_n1.repeat(&block)
else
raise Eddy::Errors::Error, "No block given in loop iteration"
end
Expand All @@ -83,7 +83,7 @@ def L_N1()
# (see Eddy::Segments::DTM)
#
# @yieldparam [Eddy::Segments::DTM] dtm
# @yieldparam [Eddy::Segments::DTM]
# @return [Eddy::Segments::DTM]
def DTM()
yield(@dtm) if block_given?
Expand All @@ -94,9 +94,9 @@ def DTM()
#
# @yieldparam [Eddy::TransactionSets::TS810::Loops::IT1::Repeat]
# @return [void]
def L_IT1()
def L_IT1(&block)
if block_given?
@l_it1.repeat()
@l_it1.repeat(&block)
else
raise Eddy::Errors::Error, "No block given in loop iteration"
end
Expand All @@ -105,7 +105,7 @@ def L_IT1()
# (see Eddy::Segments::TDS)
#
# @yieldparam [Eddy::Segments::TDS] tds
# @yieldparam [Eddy::Segments::TDS]
# @return [Eddy::Segments::TDS]
def TDS()
yield(@tds) if block_given?
Expand All @@ -114,7 +114,7 @@ def TDS()
# (see Eddy::Segments::CAD)
#
# @yieldparam [Eddy::Segments::CAD] cad
# @yieldparam [Eddy::Segments::CAD]
# @return [Eddy::Segments::CAD]
def CAD()
yield(@cad) if block_given?
Expand All @@ -125,9 +125,9 @@ def CAD()
#
# @yieldparam [Eddy::TransactionSets::TS810::Loops::SAC::Repeat]
# @return [void]
def L_SAC()
def L_SAC(&block)
if block_given?
@l_sac.repeat()
@l_sac.repeat(&block)
else
raise Eddy::Errors::Error, "No block given in loop iteration"
end
Expand All @@ -136,7 +136,7 @@ def L_SAC()
# (see Eddy::Segments::CTT)
#
# @yieldparam [Eddy::Segments::CTT] ctt
# @yieldparam [Eddy::Segments::CTT]
# @return [Eddy::Segments::CTT]
def CTT()
yield(@ctt) if block_given?
Expand All @@ -148,7 +148,7 @@ def CTT()
end
end
RB
have = Eddy::Build::TransactionSetBuilder.from_summary(@summary).ginny_class.render()
have = Eddy::Build::TransactionSetBuilder.new(@summary).ginny_class.render()
assert_equal(want, have)
end

Expand Down
Loading

0 comments on commit 9fc34f8

Please sign in to comment.