Class: Teleport::Config

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/teleport/config.rb

Overview

This class parses Telfile, and includes DSL and the models.

Defined Under Namespace

Classes: Apt, DSL, Role, Server

Constant Summary collapse

RUBIES =
["2.0.0", "1.9.3", "1.9.2", "REE", "1.8.7"]

Constants included from Constants

Constants::DATA, Constants::DIR, Constants::FILES, Constants::GEM, Constants::PUBKEY, Constants::RUBYGEMS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = "Telfile") ⇒ Config

Returns a new instance of Config.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/teleport/config.rb', line 10

def initialize(file = "Telfile")
  @roles = []
  @servers = []
  @apt = []
  @packages = []
  @recipes = []
  @callbacks = { }

  @dsl = DSL.new(self)
  @dsl.instance_eval(File.read(file), file)

  @user ||= Util.whoami
  @ruby ||= RUBIES.first

  sanity_check_gemfiles
end

Instance Attribute Details

#aptObject

Returns the value of attribute apt.



8
9
10
# File 'lib/teleport/config.rb', line 8

def apt
  @apt
end

#callbacksObject

Returns the value of attribute callbacks.



8
9
10
# File 'lib/teleport/config.rb', line 8

def callbacks
  @callbacks
end

#dslObject

Returns the value of attribute dsl.



8
9
10
# File 'lib/teleport/config.rb', line 8

def dsl
  @dsl
end

#packagesObject

Returns the value of attribute packages.



8
9
10
# File 'lib/teleport/config.rb', line 8

def packages
  @packages
end

#recipesObject

Returns the value of attribute recipes.



8
9
10
# File 'lib/teleport/config.rb', line 8

def recipes
  @recipes
end

#rolesObject

Returns the value of attribute roles.



8
9
10
# File 'lib/teleport/config.rb', line 8

def roles
  @roles
end

#rubyObject

Returns the value of attribute ruby.



8
9
10
# File 'lib/teleport/config.rb', line 8

def ruby
  @ruby
end

#serversObject

Returns the value of attribute servers.



8
9
10
# File 'lib/teleport/config.rb', line 8

def servers
  @servers
end

#ssh_keyObject

Returns the value of attribute ssh_key.



8
9
10
# File 'lib/teleport/config.rb', line 8

def ssh_key
  @ssh_key
end

#ssh_optionsObject

Returns the value of attribute ssh_options.



8
9
10
# File 'lib/teleport/config.rb', line 8

def ssh_options
  @ssh_options
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'lib/teleport/config.rb', line 8

def user
  @user
end

Instance Method Details

#role(n) ⇒ Object



27
28
29
# File 'lib/teleport/config.rb', line 27

def role(n)
  @roles.find { |i| i.name == n.to_sym }
end

#sanity_check_gemfilesObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/teleport/config.rb', line 35

def sanity_check_gemfiles
  files = ["files"] + @roles.map { |i| "files_#{i.name}" }
  files.each do |i|
    gemfile = "#{i}/Gemfile"
    lock = "#{gemfile}.lock"
    if File.exists?(gemfile) && !File.exists?(lock)
      Util.fatal "Hm. I found #{gemfile}, but you forgot to create #{lock}."
    end
  end
end

#server(n) ⇒ Object



31
32
33
# File 'lib/teleport/config.rb', line 31

def server(n)
  @servers.find { |i| i.name == n.to_s }
end