Sha256: b2950a828ee5cac75ab3e796ded9de15f59e97e33e63f6db65e4fe634feca0bc

Contents?: true

Size: 1.36 KB

Versions: 42

Compression:

Stored size: 1.36 KB

Contents

require 'erb'
require 'fileutils'
require 'securerandom'

require_relative './config/attributes'
require_relative './config/rash'
require_relative './util'

module Builderator
  ##
  # Base class for integration interfaces
  ##
  class Interface
    class << self
      def command(arg = nil)
        @command = arg unless arg.nil?
        @command
      end

      def from_gem(arg = nil)
        @from_gem = arg unless arg.nil?
        @from_gem || @command
      end

      def template(arg = nil)
        @template = arg unless arg.nil?
        @template
      end
    end

    ## Is vagrant in this bundle?
    def bundled?
      Gem.loaded_specs.key?(self.class.from_gem)
    end

    def which
      return self.class.command if bundled?

      ## Not in the bundle. Use system path
      `which #{self.class.command}`.chomp.tap { |path| fail "Unable to locate a #{self.class.command} executable" if path.empty? }
    end
    alias_method :command, :which

    def directory
      Util.workspace
    end

    def render
      ERB.new(Util.source_path(self.class.template).binread,
              nil, '-', '@output_buffer').result(Config.instance_eval('binding'))
    end

    def source
      fail 'Interface does not provide a source!'
    end

    def write
      directory.mkpath
      source.write(render)
      self
    end

    def clean
      source.unlink
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
builderator-2.1.1 lib/builderator/interface.rb
builderator-2.1.0 lib/builderator/interface.rb
builderator-2.0.4 lib/builderator/interface.rb
builderator-2.0.3 lib/builderator/interface.rb
builderator-2.0.2 lib/builderator/interface.rb
builderator-2.0.1 lib/builderator/interface.rb
builderator-2.0.0 lib/builderator/interface.rb
builderator-1.3.2 lib/builderator/interface.rb
builderator-1.3.1 lib/builderator/interface.rb
builderator-1.3.0 lib/builderator/interface.rb
builderator-1.2.3.pre.beta.1 lib/builderator/interface.rb
builderator-1.2.2 lib/builderator/interface.rb
builderator-1.2.1 lib/builderator/interface.rb
builderator-1.2.0 lib/builderator/interface.rb
builderator-1.1.12 lib/builderator/interface.rb
builderator-1.1.11 lib/builderator/interface.rb
builderator-1.1.10 lib/builderator/interface.rb
builderator-1.1.9 lib/builderator/interface.rb
builderator-1.1.8 lib/builderator/interface.rb
builderator-1.1.7 lib/builderator/interface.rb