Sha256: 520846cb4ba24c09bf2f1850f4399d24ca49b8b0f8b62037f140a0595a6ab606

Contents?: true

Size: 893 Bytes

Versions: 4

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      class Gemfile
        module Services
          class ReadFileContent
            include ConvenientService::Standard::Config

            attr_reader :path

            step :validate_path, in: :path
            step Services::AssertFileExists, in: :path
            step Services::AssertFileNotEmpty, in: :path
            step :result, in: :path, out: :content

            def initialize(path:)
              @path = path
            end

            def result
              success(content: ::File.read(path))
            end

            private

            def validate_path
              return error("Path is `nil`") if path.nil?
              return error("Path is empty") if path.empty?

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