Class: BrighterPlanet::Deploy::Server

Inherits:
Object
  • Object
show all
Includes:
ReadsFromLocalFilesystem
Defined in:
lib/brighter_planet_deploy/server.rb

Defined Under Namespace

Classes: InvalidKey

Constant Summary collapse

PUBLIC =

keys that are published

[:color]
NOT_SAVED =

keys that are not saved

[:local, :status, :rails_root, :public_dir, :private_dir]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ReadsFromLocalFilesystem

#from_private_dir, #from_public_dir, #save, #write

Constructor Details

#initialize(attrs = {}) ⇒ Server

Returns a new instance of Server.



20
21
22
23
24
# File 'lib/brighter_planet_deploy/server.rb', line 20

def initialize(attrs = {})
  attrs.each do |k, v|
    instance_variable_set "@#{k}", v
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/brighter_planet_deploy/server.rb', line 71

def method_missing(method_id, *args)
  if method_id.to_s.end_with?('=') and args.length == 1
    instance_variable_set "@#{method_id.to_s.chomp('=')}", args[0]
  elsif args.length == 0 and not block_given?
    lookup method_id
  else
    super
  end
end

Instance Attribute Details

#environmentObject



55
56
57
# File 'lib/brighter_planet_deploy/server.rb', line 55

def environment
  @environment || lookup(:environment) || local_rails_environment
end

#hostnameObject



60
61
62
# File 'lib/brighter_planet_deploy/server.rb', line 60

def hostname
  @hostname || lookup(:hostname) || local_hostname
end

#private_dirObject



44
45
46
# File 'lib/brighter_planet_deploy/server.rb', line 44

def private_dir
  @private_dir || ::File.join(rails_root, 'config')
end

#public_dirObject



38
39
40
# File 'lib/brighter_planet_deploy/server.rb', line 38

def public_dir
  @public_dir || ::File.join(rails_root, 'public')
end

#rails_rootObject



32
33
34
# File 'lib/brighter_planet_deploy/server.rb', line 32

def rails_root
  @rails_root || local_rails_root
end

#statusObject



50
51
52
# File 'lib/brighter_planet_deploy/server.rb', line 50

def status
  @status || (color == service_model.color ? :active : :standby)
end

Class Method Details

.meObject



15
16
17
# File 'lib/brighter_planet_deploy/server.rb', line 15

def me
  @me ||= new :local => true
end

Instance Method Details

#local?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/brighter_planet_deploy/server.rb', line 26

def local?
  !!@local
end

#not_saved?(k) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/brighter_planet_deploy/server.rb', line 85

def not_saved?(k)
  NOT_SAVED.include? k.to_sym
end

#public?(k) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/brighter_planet_deploy/server.rb', line 81

def public?(k)
  PUBLIC.include? k.to_sym
end

#service_modelObject



64
65
66
67
68
69
# File 'lib/brighter_planet_deploy/server.rb', line 64

def service_model
  case service.to_s.underscore
  when 'cm1'
    Cm1.instance
  end
end