Sha256: 8daba85c88498ac9fb7b36dd36e64220912ee004686320124ada938f5a92d587

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Rails
      module V1
        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
end

Version data entries

4 entries across 4 versions & 1 rubygems

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