Class: LeapCli::Leapfile

Inherits:
Object show all
Defined in:
lib/leap_cli/leapfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLeapfile

Returns a new instance of Leapfile.



21
22
23
# File 'lib/leap_cli/leapfile.rb', line 21

def initialize
  @vagrant_network = '10.5.5.0/24'
end

Instance Attribute Details

#custom_vagrant_vm_lineObject

Returns the value of attribute custom_vagrant_vm_line.



15
16
17
# File 'lib/leap_cli/leapfile.rb', line 15

def custom_vagrant_vm_line
  @custom_vagrant_vm_line
end

#environmentObject

Returns the value of attribute environment.



19
20
21
# File 'lib/leap_cli/leapfile.rb', line 19

def environment
  @environment
end

#leap_versionObject

Returns the value of attribute leap_version.



16
17
18
# File 'lib/leap_cli/leapfile.rb', line 16

def leap_version
  @leap_version
end

#logObject

Returns the value of attribute log.



17
18
19
# File 'lib/leap_cli/leapfile.rb', line 17

def log
  @log
end

#platform_directory_pathObject

Returns the value of attribute platform_directory_path.



13
14
15
# File 'lib/leap_cli/leapfile.rb', line 13

def platform_directory_path
  @platform_directory_path
end

#provider_directory_pathObject

Returns the value of attribute provider_directory_path.



14
15
16
# File 'lib/leap_cli/leapfile.rb', line 14

def provider_directory_path
  @provider_directory_path
end

#vagrant_networkObject

Returns the value of attribute vagrant_network.



18
19
20
# File 'lib/leap_cli/leapfile.rb', line 18

def vagrant_network
  @vagrant_network
end

Instance Method Details

#environment_filterObject

The way the Leapfile handles pinning of environment (self.environment) is a little tricky. If self.environment is nil, then there is no pin. If self.environment is ‘default’, then there is a pin to the default environment. The problem is that an environment of nil is used to indicate the default environment in node properties.

This method returns the environment tag as needed when filtering nodes.



33
34
35
36
37
38
39
# File 'lib/leap_cli/leapfile.rb', line 33

def environment_filter
  if self.environment == 'default'
    nil
  else
    self.environment
  end
end

#load(search_directory = nil) ⇒ Object



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
# File 'lib/leap_cli/leapfile.rb', line 41

def load(search_directory=nil)
  directory = File.expand_path(find_in_directory_tree('Leapfile', search_directory))
  if directory == '/'
    return nil
  else
    #
    # set up paths
    #
    @provider_directory_path = directory
    begin
      # load leaprc first, so that we can potentially access which environment is pinned in Leapfile
      # but also load leaprc last, so that it can override what is set in Leapfile.
      read_settings(leaprc_path)
    rescue StandardError
    end
    read_settings(directory + '/Leapfile')
    read_settings(leaprc_path)
    @platform_directory_path = File.expand_path(@platform_directory_path || '../leap_platform', @provider_directory_path)

    #
    # load the platform
    #
    platform_file = "#{@platform_directory_path}/platform.rb"
    unless File.exists?(platform_file)
      Util.bail! "ERROR: The file `#{platform_file}` does not exist. Please check the value of `@platform_directory_path` in `Leapfile` or `~/.leaprc`."
    end
    require "#{@platform_directory_path}/platform.rb"
    if !Leap::Platform.compatible_with_cli?(LeapCli::VERSION) ||
       !Leap::Platform.version_in_range?(LeapCli::COMPATIBLE_PLATFORM_VERSION)
      Util.bail! "This leap command (v#{LeapCli::VERSION}) " +
                 "is not compatible with the platform #{@platform_directory_path} (v#{Leap::Platform.version}).\n   " +
                 "You need either leap command #{Leap::Platform.compatible_cli.first} to #{Leap::Platform.compatible_cli.last} or " +
                 "platform version #{LeapCli::COMPATIBLE_PLATFORM_VERSION.first} to #{LeapCli::COMPATIBLE_PLATFORM_VERSION.last}"
    end
    unless @allow_production_deploy.nil?
      Util::log 0, :warning, "in Leapfile: @allow_production_deploy is no longer supported."
    end
    unless @platform_branch.nil?
      Util::log 0, :warning, "in Leapfile: @platform_branch is no longer supported."
    end
    @valid = true
    return @valid
  end
end

#set(property, value) ⇒ Object



86
87
88
# File 'lib/leap_cli/leapfile.rb', line 86

def set(property, value)
  edit_leaprc(property, value)
end

#unset(property) ⇒ Object



90
91
92
# File 'lib/leap_cli/leapfile.rb', line 90

def unset(property)
  edit_leaprc(property)
end

#valid?Boolean

Returns:



94
95
96
# File 'lib/leap_cli/leapfile.rb', line 94

def valid?
  !!@valid
end