Class: Sprinkle::Deployment::Deployment

Inherits:
Object
  • Object
show all
Defined in:
lib/sprinkle/deployment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Deployment

:nodoc:



49
50
51
52
53
54
# File 'lib/sprinkle/deployment.rb', line 49

def initialize(&block) #:nodoc:
  @defaults = {}
  @style = nil
  self.instance_eval(&block)
  raise 'No delivery mechanism defined' unless @style
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

:nodoc:



67
68
69
70
71
72
73
# File 'lib/sprinkle/deployment.rb', line 67

def method_missing(sym, *args, &block) #:nodoc:
  if Sprinkle::Package::Package.installer_methods.include?(sym)
    @defaults[sym] = block
  else
    super sym, *args, &block
  end
end

Instance Attribute Details

#defaultsObject

:nodoc:



47
48
49
# File 'lib/sprinkle/deployment.rb', line 47

def defaults
  @defaults
end

#styleObject

:nodoc:



47
48
49
# File 'lib/sprinkle/deployment.rb', line 47

def style
  @style
end

Instance Method Details

#active_policiesObject

:nodoc:



75
76
77
78
79
80
81
82
# File 'lib/sprinkle/deployment.rb', line 75

def active_policies #:nodoc:
  if role=Sprinkle::OPTIONS[:only_role]
    role=role.to_sym
    POLICIES.select {|x| [x.roles].flatten.include?(role) }
  else
    POLICIES
  end
end

#delivery(type, &block) ⇒ Object

Specifies which Sprinkle::Actors to use for delivery. Although all actors jobs are the same: to run remote commands on a server, you may have a personal preference. The block you pass is used to configure the actor. For more information on what configuration options are available, view the corresponding Sprinkle::Actors page.



61
62
63
64
65
# File 'lib/sprinkle/deployment.rb', line 61

def delivery(type, &block) #:doc:
  type=type.to_s.titleize
  type="SSH" if type=="Ssh"
  @style = ("Sprinkle::Actors::" + type).constantize.new(&block)
end

#processObject

:nodoc:



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/sprinkle/deployment.rb', line 84

def process #:nodoc:
  active_policies.each do |policy|
    policy.process(self)
  end
rescue Sprinkle::Errors::RemoteCommandFailure => e
  e.print_summary
  exit 1
rescue Sprinkle::Errors::TransferFailure => e
  e.print_summary
  exit 2
ensure
  # do any cleanup our actor may need to close network sockets, etc
  @style.teardown if @style.respond_to?(:teardown)        
end