Sha256: 989f9b0571e26f98f464900eea181ddd28d8e32c00fedca8226d02490a97351d

Contents?: true

Size: 864 Bytes

Versions: 2

Compression:

Stored size: 864 Bytes

Contents

require 'pathname'

module Airake #:nodoc:
  
  module Commands #:nodoc:
    
    # Base command 
    class Base 
      
      # Process command options array
      def process(command)
        command.compact.join(" ")
      end
      
      # Escape any spacing
      def escape(command)
        command.to_s.gsub(" ", "\\ ")
      end
      
      # Get relative path
      def relative_path(path, from)
        Pathname.new(path).relative_path_from(Pathname.new(from))
      end      
      
      def with_options(options, defaults = {}) 
        options.each do |key, value|
          instance_variable_set("@#{key}", value)
        end
        
        defaults.each do |key, value|
          existing = instance_variable_get("@#{key}")
          instance_variable_set("@#{key}", value) unless existing
        end
      end
      
    end
    
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
airake-0.2.8 lib/airake/commands/base.rb
airake-0.2.7 lib/airake/commands/base.rb