Sha256: 7b56686d2cb38dee2487ba4c2060c6b32dd7cf94e4fe3175b9012e42e501eda1

Contents?: true

Size: 1.53 KB

Versions: 22

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require_relative '../../models/project'
require_relative '../base_presenter_ex'

module Dsu
  module Presenters
    module Project
      class RenamePresenter < BasePresenterEx
        delegate :project_name, :description, to: :project

        def initialize(project_name:, new_project_name:, new_project_description:, options: {})
          super(options: options)

          raise ArgumentError, 'project_name is blank' if project_name.blank?
          raise ArgumentError, 'new_project_name is blank' if new_project_name.blank?

          @project = Models::Project.find_or_initialize(project_name: project_name)

          @new_project = Models::Project.new(project_name: new_project_name.strip,
            description: new_project_description&.strip, options: options).tap(&:validate)
        end

        def respond(response:)
          return false unless response
          return false if new_project.invalid?

          project.rename!(new_project_name: new_project_name, new_project_description: new_project_description)
        end

        def project_does_not_exist?
          !project.exist?
        end

        def new_project_already_exists?
          new_project.exist?
        end

        def new_project_name
          new_project.project_name
        end

        def new_project_description
          new_project.description
        end

        def new_project_errors
          new_project.errors.full_messages
        end

        private

        attr_reader :new_project, :project
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
dsu-3.0.5 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.4 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.3 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.1 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.beta.3 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.beta.2 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.beta.1 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.beta.0 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.12 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.11 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.10 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.9 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.8 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.7 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.6 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.5 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.4 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.3 lib/dsu/presenters/project/rename_presenter.rb
dsu-3.0.0.alpha.2 lib/dsu/presenters/project/rename_presenter.rb