Sha256: 180ca55c1aa123e2af6496df1d0755a8897a9c67f93e589aa14e4a458f5a7fb7

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      class Gemfile
        module Services
          class ReplaceFileContent
            include ConvenientService::Standard::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 error("Path is `nil`") if path.nil?
              return error("Path is empty") if path.empty?

              success
            end

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

              success
            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/gemfile/services/replace_file_content.rb
convenient_service-0.16.0 lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb
convenient_service-0.15.0 lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb
convenient_service-0.14.0 lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb