Sha256: 44d05e3c896ef19612cef5c8c327dc3593bf5407824e0e8113a3cb7ea951f72b

Contents?: true

Size: 1.97 KB

Versions: 6

Compression:

Stored size: 1.97 KB

Contents

require "librarian/manifest_set"
require "librarian/spec_change_set"
require "librarian/action/base"

module Librarian
  module Action
    class Install < Base

      def run
        check_preconditions

        perform_installation
      end

    private

      def check_preconditions
        check_specfile
        check_lockfile
        check_consistent
      end

      def check_specfile
        raise Error, "#{specfile_name} missing!" unless specfile_path.exist?
      end

      def check_lockfile
        raise Error, "#{lockfile_name} missing!" unless lockfile_path.exist?
      end

      def check_consistent
        raise Error, "#{specfile_name} and #{lockfile_name} are out of sync!" unless spec_consistent_with_lock?
      end

      def perform_installation
        manifests = sorted_manifests

        cache_manifests(manifests)
        create_install_path
        install_manifests(manifests)
      end

      def cache_manifests(manifests)
        manifests.each do |manifest|
          manifest.source.cache!([manifest])
        end
      end

      def create_install_path
        install_path.mkpath unless install_path.exist?
      end

      def install_manifests(manifests)
        manifests.each do |manifest|
          manifest.install!
        end
      end

      def sorted_manifests
        ManifestSet.sort(lock.manifests)
      end

      def specfile_name
        environment.specfile_name
      end

      def specfile_path
        environment.specfile_path
      end

      def lockfile_name
        environment.lockfile_name
      end

      def lockfile_path
        environment.lockfile_path
      end

      def spec
        environment.spec
      end

      def lock
        environment.lock
      end

      def spec_change_set(spec, lock)
        SpecChangeSet.new(environment, spec, lock)
      end

      def spec_consistent_with_lock?
        spec_change_set(spec, lock).same?
      end

      def install_path
        environment.install_path
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
librarian-0.0.15 lib/librarian/action/install.rb
librarian-0.0.14 lib/librarian/action/install.rb
librarian-0.0.13 lib/librarian/action/install.rb
librarian-0.0.12 lib/librarian/action/install.rb
librarian-0.0.11 lib/librarian/action/install.rb
librarian-0.0.10 lib/librarian/action/install.rb