lib/eddy/build/segment_builder.rb in eddy-0.5.1 vs lib/eddy/build/segment_builder.rb in eddy-0.6.0

- old
+ new

@@ -4,11 +4,11 @@ module Eddy module Build # Generate Ruby code from JSON/YAML EDI definitions. class SegmentBuilder - # @return [Eddy::Schema::SegmentSummary] + # @return [Eddy::Summary::Segment] attr_accessor :summary # @return [String] (nil) attr_accessor :folder # A hash of element names that appear more than once in the segment. # @return [Hash{String => Integer}] @@ -22,22 +22,22 @@ # @param path [String] Path to a JSON or YAML file containing a valid Segment definition. # @param (see #initialize) # @return [Eddy::Build::SegmentBuilder] def self.from_file(path, **kwargs) - raise Eddy::Errors::Error, "Invalid segment definition" unless Eddy::Schema.valid_segment_data?(path) + raise Eddy::Errors::Error, "Invalid segment definition" unless Eddy::Summary.valid_segment_data?(path) data = Eddy::Util.read_json_or_yaml(path) sb = Eddy::Build::SegmentBuilder.new(**kwargs) - sb.summary = Eddy::Schema::SegmentSummary.create(data) + sb.summary = Eddy::Summary::Segment.create(data) return sb end - # @param summary [Eddy::Schema::SegmentSummary] + # @param summary [Eddy::Summary::Segment] # @param (see #initialize) # @return [Eddy::Build::SegmentBuilder] def self.from_summary(summary, **kwargs) - sb = Eddy::Build::SegmentBuilder.new(**kwargs) + sb = new(**kwargs) sb.summary = summary return sb end # Generated the Segment and return the name of the file where it was written. @@ -52,16 +52,21 @@ path = self.folder || File.join(Eddy.config.build_dir, "segments") result = self.ginny_class.generate(path) return result end + # @return [String] + def render() + return self.ginny_class.render() + end + # @return [Ginny::Class] def ginny_class() return Ginny::Class.create({ classify_name: false, modules: ["Eddy", "Segments"], - parent: "Eddy::Segment", + parent: "Eddy::Models::Segment", name: summary.id, description: summary.doc_comment(header: true), body: <<~STR, #{self.constructor()} @@ -114,12 +119,12 @@ Eddy::Build::SegmentBuilder.element_accessor_v2(el, self.duplicate_elements) end return defs.join("\n\n") end - # @param el [Eddy::Schema::ElementSummary] - # @param header [Symbol] (see Eddy::Schema::ElementSummary#doc_comment) + # @param el [Eddy::Summary::Element] + # @param header [Symbol] (see Eddy::Summary::Element#doc_comment) # @return [String] def self.element_accessor_v1(el, header: :summary) return <<~RB.strip #{el.doc_comment(header: header).gsub(/^/, '# ').gsub(/([[:blank:]]+)$/, '')} # @@ -129,10 +134,10 @@ @#{el.ref.downcase}.value = arg end RB end - # @param el [Eddy::Schema::ElementSummary] + # @param el [Eddy::Summary::Element] # @param dupes [Hash] # @param header [Boolean] (false) # @return [String] def self.element_accessor_v2(el, dupes, header: :ref) if dupes.key?(el.name)