lib/docman/commands/command.rb in docman-0.0.69 vs lib/docman/commands/command.rb in docman-0.0.70
- old
+ new
@@ -51,10 +51,11 @@
if obj.has_key? 'hooks' and obj['hooks'].has_key? @type and not obj['hooks'][@type].nil?
obj['hooks'][@type].each_pair do |name, hooks|
hooks = Marshal::load(Marshal.dump(hooks))
unless context.nil? or hooks.nil?
hooks.each do |hook|
+ hook['order'] = 0 unless hook['order']
hook['context'] = context
end
end
if @hooks[name].nil?
@hooks[name] = hooks
@@ -64,18 +65,20 @@
end
end
end
def add_action(name, hook, context = nil)
+ hook['order'] = 0 unless hook['order']
if @hooks.has_key? name
@hooks[name] << {'type' => hook}
else
@hooks[name] = [hook]
end
end
def run_actions(name)
if @hooks.has_key?(name) and not @hooks[name].nil?
+ @hooks[name].sort_by!{|a| a['order']}
@hooks[name].each do |hook|
next if hook.has_key?('run_on_success_only') and hook['run_on_success_only'] and not @execute_result
context = hook.has_key?('context') ? hook['context'] : @context
Docman::Command.create(hook, context, self).perform
end
\ No newline at end of file