Sha256: 7355570e8504aa9335c2e7ae9585f568ce312651900914d12b74299e65437d28

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      module V1
        class Gemfile
          module Services
            class ReplaceFileContent
              include ConvenientService::Standard::V1::Config

              attr_reader :path, :content

              step :validate_path, in: :path
              step :validate_content, in: :content
              step Services::AssertFileExists, in: :path
              step :result, in: :path

              def initialize(path:, content:)
                @path = path
                @content = content
              end

              def result
                ::File.write(path, content)

                success
              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

              def validate_content
                return failure(content: "Content is `nil`") if content.nil?

                success
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
convenient_service-0.17.0 lib/convenient_service/examples/standard/v1/gemfile/services/replace_file_content.rb
convenient_service-0.16.0 lib/convenient_service/examples/standard/v1/gemfile/services/replace_file_content.rb
convenient_service-0.15.0 lib/convenient_service/examples/standard/v1/gemfile/services/replace_file_content.rb
convenient_service-0.14.0 lib/convenient_service/examples/standard/v1/gemfile/services/replace_file_content.rb