Sha256: b94ebf7e37ddc6f947b9d0745b667fb846dd7732cff9cffbf799927a96bff765

Contents?: true

Size: 985 Bytes

Versions: 5

Compression:

Stored size: 985 Bytes

Contents

# frozen_string_literal: true

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

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

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

            validate :content_not_nil if ConvenientService::Dependencies.support_has_j_send_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

5 entries across 5 versions & 1 rubygems

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