Sha256: 807da8a3efe024a231ad19740e35bea3c500423a76baf3f19d71fe93fbf4c2e7

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

require 'erb'
require 'fileutils'

module TapeBoxer
  class InvalidAction < StandardError; end
  class ActionError < StandardError; end
  class UnspecifiedOption < StandardError; end

  class Action < Struct.new(:name, :proc, :description); end
  class RegisteredModule < Struct.new(:name, :klass); end

  def self.register_module(name, klass)
    self.registered_modules[name] = RegisteredModule.new(name, klass)
  end

  def self.registered_modules
    @modules ||= Hash.new
  end

  class ExecutionModule
    attr_reader :opts
    def initialize(opts)
      @opts = opts
    end

    def self.actions
      @actions
    end

    def self.action(name, opts = '', doc = '')
      @actions ||= Hash.new
      @actions[name.to_sym] = Action.new(name, opts, doc)
    end

    # Set or return module_name
    def self.module_name(name = nil)
      @module_name = (name || @module_name)
    end

    def actions
      self.class.actions
    end

    def fe_app?
      !Dir["#{local_dir}/gulpfile.*"].empty?
    end

    def rails_app?
      !Dir["#{local_dir}/config.ru"].empty?
    end

    def execute_action(action)
      action = action.to_sym
      unless actions.include?(action)
        raise InvalidAction, "#{action} is not a valid action!"
      end

      unless system("ansible-playbook --version >/dev/null")
        raise InvalidAction, "ansible-playbook must be on your PATH to use this tool"
      end

      self.instance_eval &actions[action].proc
    end

    protected

    def require_opt(name)
      unless opts[name.to_sym]
        raise UnspecifiedOption, "Option --#{name} must be specified to do this!"
      end
    end

    private
    def tape_dir
      File.realpath(File.join(__dir__, '../'))
    end

    def local_dir
      Dir.pwd
    end

    def tapefiles_dir
      local_dir + '/taperole'
    end

    def tapecfg_dir
      local_dir + '/.tape'
    end
  end
end

Dir[File.dirname(__FILE__) + "/tape/*.rb"].each {|file| require file }

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
taperole-1.3.2 lib/tape.rb
taperole-1.3.1 lib/tape.rb
taperole-1.3.0 lib/tape.rb