lib/docman/builders/builder.rb in docman-0.0.5 vs lib/docman/builders/builder.rb in docman-0.0.6

- old
+ new

@@ -1,62 +1,62 @@ -require 'yaml' +require 'docman/commands/command' module Docman module Builders - class Builder - @@subclasses = {} + class Builder < Docman::Command + @@builders = {} + @@build_results = {} - def self.create(type, root, build_type, info) - c = @@subclasses[type] + + def self.create(params = nil, context = nil, caller = nil) + c = @@builders[params['handler']] if c - c.new(root, build_type, info) + c.new(params, context, caller, 'builder') else raise "Bad builder type: #{type}" end end def self.register_builder(name) - @@subclasses[name] = self + @@builders[name] = self end - def initialize(root, build_type, info) - @root = root - @build_type = build_type - @info = info - @before_build_actions = @build_type['before_build_actions'].nil? ? [] : @build_type['before_build_actions'] - @after_build_actions = @build_type['after_build_actions'].nil? ? [] : @build_type['after_build_actions'] - @before_build_actions << 'clean_if_changed' + def config + super + add_action('before_execute', {'type' => :clean_changed}) end - def before_build_action_clean_if_changed - if File.directory? @info['full_build_path'] - FileUtils.rm_r @info['full_build_path'] if @info.need_rebuild? + def validate_command + raise "Please provide 'context'" if @context.nil? + raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info + end + + before_execute do + #TODO: rebuld if config changed. + if @context.need_rebuild? + log("Need rebuild") + else + log("Rebuild not needed") + raise NoChangesError, 'This version already deployed' unless changed? end + end - def do - perform(@before_build_actions, 'before_build_action') - # Dispatch to corresponding method. - @info.write_info(self.send("#{@build_type['type']}")) - perform(@after_build_actions, 'after_build_action') + after_execute do + @execute_result = @context.write_info(@execute_result) end - def perform(actions, method_prefix) - unless actions.nil? - actions.each do |action| - method = "#{method_prefix}_#{action}" - self.send(method) - end - end + def changed? + false end - def repo?(path) - File.directory? File.join(path, '.git') + def describe + "Build: #{properties_info}" end - def after_build_action_git_commit - message = "name: #{@info['name']} updated, state: #{@info['state']}" - GitUtil.commit(@root['full_build_path'], @info['full_build_path'], message) + def prefix + "#{@context['name']} - #{self.class.name}" end + end end end