Class: Volley::Dsl::Plan
- Inherits:
-
Object
- Object
- Volley::Dsl::Plan
- Defined in:
- lib/volley/dsl/plan.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#argv ⇒ Object
Returns the value of attribute argv.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#stages ⇒ Object
readonly
Returns the value of attribute stages.
Instance Method Summary collapse
- #action(name, stage = :main, &block) ⇒ Object
- #args ⇒ Object
- #argument(name, opts = { }, &block) ⇒ Object
- #branch ⇒ Object
- #call(options = { }) ⇒ Object
- #command(*args) ⇒ Object
- #config ⇒ Object
- #default(&block) ⇒ Object
- #deploying? ⇒ Boolean
- #file(file) ⇒ Object
- #files(*list) ⇒ Object
-
#initialize(name, o = { }, &block) ⇒ Plan
constructor
A new instance of Plan.
- #load(file) ⇒ Object
- #log(msg) ⇒ Object
- #method_missing(n, *args) ⇒ Object
- #output(tf = true) ⇒ Object
- #publishing? ⇒ Boolean
- #pull(&block) ⇒ Object
- #push(&block) ⇒ Object
- #remote(tf) ⇒ Object
- #run_actions ⇒ Object
- #shellout(*args) ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #usage ⇒ Object
- #version ⇒ Object
- #volley(plan, options = {}, &block) ⇒ Object
Constructor Details
#initialize(name, o = { }, &block) ⇒ Plan
Returns a new instance of Plan.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/volley/dsl/plan.rb', line 16 def initialize(name, o={ }, &block) = { :name => name, :project => nil, :output => false, :encrypt => false, :remote => true, :pack => true, :pack_type => "tgz", }.merge(o) @attributes = OpenStruct.new() raise "project instance must be set" if @attributes.project.nil? @name = name.to_sym @project = [:project] @stopped = false @block = block @files = [] @arguments = { } @argv = [] @stages = { :pre => Volley::Dsl::Stage.new(:pre, :plan => self), :main => Volley::Dsl::Stage.new(:main, :plan => self), :post => Volley::Dsl::Stage.new(:post, :plan => self), } @stage_order = [:pre, :main, :post] instance_eval &block if block_given? if @attributes.remote argument :descriptor, :required => true, :convert => :descriptor else argument :descriptor, :convert => :descriptor, :convert_opts => { :partial => true } end argument :force end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
10 11 12 |
# File 'lib/volley/dsl/plan.rb', line 10 def arguments @arguments end |
#argv ⇒ Object
Returns the value of attribute argv.
6 7 8 |
# File 'lib/volley/dsl/plan.rb', line 6 def argv @argv end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/volley/dsl/plan.rb', line 11 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/volley/dsl/plan.rb', line 7 def name @name end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
8 9 10 |
# File 'lib/volley/dsl/plan.rb', line 8 def project @project end |
#stages ⇒ Object (readonly)
Returns the value of attribute stages.
9 10 11 |
# File 'lib/volley/dsl/plan.rb', line 9 def stages @stages end |
Instance Method Details
#action(name, stage = :main, &block) ⇒ Object
175 176 177 |
# File 'lib/volley/dsl/plan.rb', line 175 def action(name, stage=:main, &block) @stages[stage].action(name, :plan => self, :stage => stage, &block) end |
#args ⇒ Object
113 114 115 |
# File 'lib/volley/dsl/plan.rb', line 113 def args @args = OpenStruct.new(@arguments.inject({ }) { |h, e| (k, v)=e; h[k] = v.value; h }) end |
#argument(name, opts = { }, &block) ⇒ Object
166 167 168 |
# File 'lib/volley/dsl/plan.rb', line 166 def argument(name, opts={ }, &block) @arguments[name.to_sym] = Volley::Dsl::Argument.new(name, opts.merge(:plan => self), &block) end |
#branch ⇒ Object
122 123 124 125 126 |
# File 'lib/volley/dsl/plan.rb', line 122 def branch return args.descriptor.branch if args.descriptor return source.branch if publishing? nil end |
#call(options = { }) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/volley/dsl/plan.rb', line 53 def call(={ }) @mode = @name.to_s =~ /deploy/i ? :deploy : :publish Volley::Log.debug "## #{@project.name}:#@name (#@mode)" @origargs = [:args] data = @origargs process_arguments(data) raise "descriptor must be specified" if @attributes.remote && !args.descriptor Volley::Log.info ">> #{@project.name}:#@name" begin run_actions rescue ExecutionStopped => e Volley::Log.debug "stopping execution at #{e.backtrace.first}" rescue => e Volley::Log.debug "plan#call error: #{e.} at #{e.backtrace.first}" raise e end [branch, version].join(":") end |
#command(*args) ⇒ Object
224 225 226 227 228 229 |
# File 'lib/volley/dsl/plan.rb', line 224 def command(*args) name = args.join(" ").parameterize.to_sym action name do plan.shellout(*args) end end |
#default(&block) ⇒ Object
179 180 181 |
# File 'lib/volley/dsl/plan.rb', line 179 def default(&block) action(:default, :main, &block) end |
#deploying? ⇒ Boolean
76 77 78 |
# File 'lib/volley/dsl/plan.rb', line 76 def @mode == :deploy end |
#file(file) ⇒ Object
207 208 209 |
# File 'lib/volley/dsl/plan.rb', line 207 def file(file) @files << file end |
#files(*list) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/volley/dsl/plan.rb', line 211 def files(*list) list = [*list].flatten list.each {|e| file e} if list.count > 0 #if @files.count > 0 && list.count > 0 # Volley::Log.warn "overriding file list" # Volley::Log.debug "files: #{@files.inspect}" # Volley::Log.debug "new: #{list.inspect}" #end #@files = list if list.count > 0 #@files @files end |
#load(file) ⇒ Object
155 156 157 158 159 160 |
# File 'lib/volley/dsl/plan.rb', line 155 def load(file) Volley::Dsl.file(file) rescue => e Volley::Log.error "failed to load file: #{e.}: #{file} (#{real})" Volley::Log.debug e end |
#log(msg) ⇒ Object
151 152 153 |
# File 'lib/volley/dsl/plan.rb', line 151 def log(msg) Volley::Log.info msg end |
#output(tf = true) ⇒ Object
170 171 172 173 |
# File 'lib/volley/dsl/plan.rb', line 170 def output(tf=true) @attributes.output = tf argument :output, :attr => true, :default => tf, :convert => :boolean end |
#publishing? ⇒ Boolean
80 81 82 |
# File 'lib/volley/dsl/plan.rb', line 80 def publishing? @mode == :publish end |
#pull(&block) ⇒ Object
187 188 189 |
# File 'lib/volley/dsl/plan.rb', line 187 def pull(&block) Volley::Dsl::PullAction.new(:pull_dummy, :plan => self, :stage => :main, &block) end |
#push(&block) ⇒ Object
183 184 185 |
# File 'lib/volley/dsl/plan.rb', line 183 def push(&block) Volley::Dsl::PushAction.new(:push_dummy, :plan => self, :stage => :main, &block) end |
#remote(tf) ⇒ Object
117 118 119 120 |
# File 'lib/volley/dsl/plan.rb', line 117 def remote(tf) raise "remote can only be set to true or false" unless [true, false].include?(tf) @attributes.remote = tf end |
#run_actions ⇒ Object
92 93 94 95 96 97 |
# File 'lib/volley/dsl/plan.rb', line 92 def run_actions @stage_order.each do |stage| @current_stage = stage @stages[stage].call end end |
#shellout(*args) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/volley/dsl/plan.rb', line 231 def shellout(*args) require "mixlib/shellout" opts = args.last.is_a?(Hash) ? args.pop : { } = { :output => @attributes.output, :prepend => ">> ", }.merge(opts) command = ::Mixlib::ShellOut.new(*args) command.run_command command.stdout.lines.each { |l| Volley::Log.info "#{[:prepend]}#{l}" } if [:output] && command.stdout command.stderr.lines.each { |l| Volley::Log.info "#{[:prepend]}#{l}" } if [:output] && command.stderr command.error! { :out => command.stdout, :err => command.stderr } end |
#stop ⇒ Object
99 100 101 102 |
# File 'lib/volley/dsl/plan.rb', line 99 def stop @stopped = true raise ExecutionStopped, "stopped" end |
#stopped? ⇒ Boolean
104 105 106 |
# File 'lib/volley/dsl/plan.rb', line 104 def stopped? @stopped end |
#usage ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/volley/dsl/plan.rb', line 84 def usage out = [] @arguments.each do |n, arg| out << arg.usage end out.join(" ") end |
#version ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/volley/dsl/plan.rb', line 128 def version v = args.descriptor ? args.descriptor.version : nil if v.nil? || v == "latest" v = begin if Volley::Dsl.publisher.latest_version(args.descriptor.project, args.descriptor.branch) elsif publishing? begin source.revision rescue Volley::ScmNotConfigured => e Volley::Log.debug "failed to get version from source, trying publisher" Volley::Dsl.publisher.latest_version(args.descriptor.project, args.descriptor.branch) end end rescue => e Volley::Log.debug "failed to get version? #{v.inspect} : #{e.}" #Volley::Log.debug e v end end v end |
#volley(plan, options = {}, &block) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/volley/dsl/plan.rb', line 191 def volley(plan, ={}, &block) o = { :run => plan, :plan => self, :stage => :main, :descriptor => args.descriptor, :args => {}, }.merge() action = Volley::Dsl::VolleyAction.new("volley-#{plan}", o) #if @current_stage == :post # action.call #else @stages[:main].add action #end end |