Sha256: 13b74990bfcad25e30d3885ec3c56dc2bb9380ba74f97807525eb7c6940c3c87

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

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

module Dsu
  module Presenters
    module Project
      class UsePresenter < BasePresenterEx
        include Defaultable

        attr_reader :project_name

        delegate :description, to: :project, prefix: true, allow_nil: true

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

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

          self.project_name = project_name
        end

        def respond(response:)
          return false unless response

          project.default! if make_default? && project&.present?
          project.use! if project&.present?
        end

        def already_current_project?
          project&.current_project?
        end

        def project_does_not_exist?
          !project.exist?
        end

        def project_errors
          return false unless project.persisted?

          project.errors.full_messages
        end

        private

        attr_writer :project_name

        def project
          @project ||= Models::Project.find_or_initialize(project_name: project_name)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dsu-3.0.5 lib/dsu/presenters/project/use_presenter.rb
dsu-3.0.4 lib/dsu/presenters/project/use_presenter.rb
dsu-3.0.3 lib/dsu/presenters/project/use_presenter.rb
dsu-3.0.1 lib/dsu/presenters/project/use_presenter.rb
dsu-3.0.0 lib/dsu/presenters/project/use_presenter.rb
dsu-3.0.0.beta.3 lib/dsu/presenters/project/use_presenter.rb
dsu-3.0.0.beta.2 lib/dsu/presenters/project/use_presenter.rb
dsu-3.0.0.beta.1 lib/dsu/presenters/project/use_presenter.rb
dsu-3.0.0.beta.0 lib/dsu/presenters/project/use_presenter.rb