Sha256: 2e508a369848cc20b177197b3303e70f5d2ae22e6377959e774e8d8010c0bc2a

Contents?: true

Size: 972 Bytes

Versions: 7

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Rails
      module Gemfile
        module Services
          class ReplaceFileContent
            include RailsService::Config

            attribute :path, :string
            attribute :content, :string

            validates :path, presence: true if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?

            validate :content_not_nil if ConvenientService::Dependencies.support_has_result_params_validations_using_active_model_validations?

            step Services::AssertFileExists, in: :path
            step :result, in: :path

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

              success
            end

            private

            def content_not_nil
              errors.add(:content, "can't be nil") if content.nil?
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb
convenient_service-0.11.0 lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb
convenient_service-0.10.1 lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb
convenient_service-0.10.0 lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb
convenient_service-0.9.0 lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb
convenient_service-0.8.0 lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb
convenient_service-0.7.0 lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb