File: install.rb

package info (click to toggle)
ruby-librarian 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 624 kB
  • sloc: ruby: 6,109; makefile: 11
file content (99 lines) | stat: -rw-r--r-- 1,980 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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

        create_install_path
        install_manifests(manifests)
      end

      def create_install_path
        install_path.rmtree if install_path.exist? && destructive?
        install_path.mkpath
      end

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

      def sorted_manifests
        ManifestSet.sort(lock.manifests)
      end

      def destructive?
        environment.config_db.local['destructive'] == 'true'
      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