summaryrefslogtreecommitdiff
path: root/lib/leap/platform.rb
blob: 89b1bc1a117af7b3ffa8ec0e2873303275b5b646 (plain)
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
require 'versionomy'

module Leap

  class Platform
    class << self
      #
      # configuration
      #

      attr_reader :version
      attr_reader :compatible_cli
      attr_accessor :facts
      attr_accessor :paths
      attr_accessor :node_files
      attr_accessor :monitor_username
      attr_accessor :reserved_usernames

      def define(&block)
        # some sanity defaults:
        @reserved_usernames = []
        self.instance_eval(&block)
      end

      def version=(version)
        @version = Versionomy.parse(version)
      end

      def compatible_cli=(range)
        @compatible_cli = range
        @minimum_cli_version = Versionomy.parse(range.first)
        @maximum_cli_version = Versionomy.parse(range.last)
      end

      #
      # return true if the cli_version is compatible with this platform.
      #
      def compatible_with_cli?(cli_version)
        cli_version = Versionomy.parse(cli_version)
        cli_version >= @minimum_cli_version && cli_version <= @maximum_cli_version
      end

      #
      # return true if the platform version is within the specified range.
      #
      def version_in_range?(range)
        if range.is_a? String
          range = range.split('..')
        end
        minimum_platform_version = Versionomy.parse(range.first)
        maximum_platform_version = Versionomy.parse(range.last)
        @version >= minimum_platform_version && @version <= maximum_platform_version
      end
    end

  end

end