lib/convenient_service/examples/standard/gemfile/services/format.rb in convenient_service-0.6.0 vs lib/convenient_service/examples/standard/gemfile/services/format.rb in convenient_service-0.7.0
- old
+ new
@@ -14,25 +14,64 @@
class Format
include ConvenientService::Standard::Config
attr_reader :path
- step Services::ReadFileContent, in: :path, out: :content
- step Services::StripComments, in: :content, out: :content_without_comments
- step Services::ParseContent, in: {content: :content_without_comments}, out: :parsed_content
- step Services::FormatHeader, in: :parsed_content, out: {formatted_content: :formatted_header_content}
- step Services::FormatBody, in: :parsed_content, out: {formatted_content: :formatted_body_content}
+ step :validate_path,
+ in: :path
+ step Services::ReadFileContent,
+ in: :path,
+ out: :content
+
+ step Services::StripComments,
+ in: :content,
+ out: :content_without_comments
+
+ step Services::ParseContent,
+ in: {content: :content_without_comments},
+ out: :parsed_content
+
+ step Services::FormatHeader,
+ in: :parsed_content,
+ out: {formatted_content: :formatted_header_content}
+
+ step Services::FormatBody,
+ in: :parsed_content,
+ out: {formatted_content: :formatted_body_content}
+
+ step Services::MergeSections,
+ in: [
+ {header: :formatted_header_content},
+ {body: :formatted_body_content}
+ ],
+ out: :merged_sections
+
+ step Services::ReplaceFileContent,
+ in: [
+ :path,
+ {content: :merged_sections}
+ ]
+
before :result do
@progressbar = ::ProgressBar.create(title: "Formatting", total: steps.count)
end
- after :step do |step_result|
+ after :step do |step|
@progressbar.increment
end
def initialize(path:)
@path = path
+ end
+
+ private
+
+ def validate_path
+ return failure(path: "Path is `nil`") if path.nil?
+ return failure(path: "Path is empty") if path.empty?
+
+ success
end
end
end
end
end