Class: Luban::Deployment::Configuration::Server

Inherits:
SSHKit::Host
  • Object
show all
Defined in:
lib/luban/deployment/configuration/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rolesObject (readonly)

Returns the value of attribute roles.



7
8
9
# File 'lib/luban/deployment/configuration/server.rb', line 7

def roles
  @roles
end

Class Method Details

.create(host, **properties) ⇒ Object



9
10
11
12
13
14
# File 'lib/luban/deployment/configuration/server.rb', line 9

def self.create(host, **properties)
  server = host.is_a?(Server) ? host : Server.new(host)
  server.add_properties(properties) unless properties.empty?
  server.ssh_options ||= {}
  server
end

Instance Method Details

#[](key) ⇒ Object Also known as: fetch



45
46
47
# File 'lib/luban/deployment/configuration/server.rb', line 45

def [](key)
  properties[key] 
end

#[]=(key, value) ⇒ Object Also known as: set



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/luban/deployment/configuration/server.rb', line 50

def []=(key, value)
  if respond_to?("#{key}=")
    send("#{key}=", value)
  else
    pval = properties[key]
    if pval.is_a? Hash and value.is_a? Hash
      pval.merge!(value)
    elsif pval.is_a? Set and value.is_a? Set
      pval.merge(value)
    elsif pval.is_a? Array and value.is_a? Array
      pval.concat value
    else
      properties[key] = value
    end
  end 
end

#add_cronjob(cronjob) ⇒ Object Also known as: cronjob=



85
86
87
# File 'lib/luban/deployment/configuration/server.rb', line 85

def add_cronjob(cronjob)
  cronjobs.add(cronjob)
end

#add_cronjobs(cronjobs) ⇒ Object Also known as: cronjobs=



80
81
82
# File 'lib/luban/deployment/configuration/server.rb', line 80

def add_cronjobs(cronjobs)
  cronjobs.each { |cronjob| add_cronjob(cronjob) }
end

#add_properties(_properties) ⇒ Object



68
69
70
# File 'lib/luban/deployment/configuration/server.rb', line 68

def add_properties(_properties)
  _properties.each { |k, v| self[k] = v }
end

#add_role(role) ⇒ Object



33
34
35
# File 'lib/luban/deployment/configuration/server.rb', line 33

def add_role(role)
  roles.add(role.to_sym)
end

#add_roles(roles) ⇒ Object Also known as: roles=



28
29
30
# File 'lib/luban/deployment/configuration/server.rb', line 28

def add_roles(roles)
  roles.each { |role| add_role(role) }
end

#cronjobsObject



76
77
78
# File 'lib/luban/deployment/configuration/server.rb', line 76

def cronjobs
  self[:cronjobs]
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/luban/deployment/configuration/server.rb', line 37

def has_role?(role)
  roles.include? role.to_sym
end

#local?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/luban/deployment/configuration/server.rb', line 16

def local?
  super or (properties.has_key?(:local) ? properties[:local] : localhost?)
end

#localhost?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/luban/deployment/configuration/server.rb', line 20

def localhost?
  hostname == 'localhost' or hostname == `hostname -f`.chomp
end

#primary?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/luban/deployment/configuration/server.rb', line 72

def primary?
  self[:primary]
end

#propertiesObject



41
42
43
# File 'lib/luban/deployment/configuration/server.rb', line 41

def properties
  @properties ||= { :roles => Set.new, :cronjobs => Set.new }
end