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



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

def [](key)
  properties[key] 
end

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/luban/deployment/configuration/server.rb', line 42

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=



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

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

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



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

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

#add_properties(_properties) ⇒ Object



60
61
62
# File 'lib/luban/deployment/configuration/server.rb', line 60

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

#add_role(role) ⇒ Object



25
26
27
# File 'lib/luban/deployment/configuration/server.rb', line 25

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

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



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

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

#cronjobsObject



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

def cronjobs
  self[:cronjobs]
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#primary?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/luban/deployment/configuration/server.rb', line 64

def primary?
  self[:primary]
end

#propertiesObject



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

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