class Shift::Interface

The default Shift interface, from which other interfaces must inherit. Also works as an identity function or echo server, in that it echoes what it is given.

Public Class Methods

available?() click to toggle source

Wether the requirements are met in the current environment. Typically checks if the required gems and/or command line stuff is available.

# File lib/shift/interface.rb, line 25
def self.available?
  gem_dependencies.all? {|d| Gem.available?(d) }
end
default() click to toggle source

A default instance without options.

# File lib/shift/interface.rb, line 63
def self.default
  @default ||= new
end
engine_class() click to toggle source

The class of the wrapped generator, or false if none is used.

# File lib/shift/interface.rb, line 44
def self.engine_class
  false
end
gem_dependencies() click to toggle source

A list of Rubygems needed for the interface to work.

# File lib/shift/interface.rb, line 31
def self.gem_dependencies
  []
end
instructions() click to toggle source

One-liner on what the user can do to make it available. Used in DependencyError.

# File lib/shift/interface.rb, line 13
def self.instructions
  if gem_dependencies.any?
    'gem install ' + gem_dependencies.join(' ')
  else
    'Google it :)'
  end
end
keep_extension?() click to toggle source

Whether to leave the old extension as is and append, like something.css => something.css.gzip

# File lib/shift/interface.rb, line 57
def self.keep_extension?
  false
end
new(*prms) click to toggle source
Calls superclass method
# File lib/shift/interface.rb, line 67
def self.new(*prms)
  unless available?
    raise Shift::DependencyError, "#{self} not available. " +
          "Possible fix: #{instructions}"
  end
  @req ||= require_libs.each {|str| require str }
  super
end
new(*prms) click to toggle source

Create a new instance with the given options.

# File lib/shift/interface.rb, line 78
def initialize(*prms)
  if self.class.engine_class
    @engine = self.class.engine_class.new(*prms)
  end
end
require_libs() click to toggle source

A list of things to be required on initialization.

# File lib/shift/interface.rb, line 37
def self.require_libs
  gem_dependencies
end
target_format() click to toggle source

The format typically produced by the generator.

# File lib/shift/interface.rb, line 50
def self.target_format
  false
end

Public Instance Methods

compile(str)
Alias for: process
compress(str)
Alias for: process
process(str) click to toggle source

Process the supplied string, returning the resulting ‘String`.

# File lib/shift/interface.rb, line 86
def process(str)
  str.dup
end
Also aliased as: compress, compile, transform
rename(file) click to toggle source

Get the default filename of a transformed file. @param [String] file Path of the original file @return [String] default file name for the result.

# File lib/shift/interface.rb, line 97
def rename(file)
  return nil if file.nil?

  unless self.class.keep_extension?
    file = file.is_a?(Symbol) ?
      file.to_s : file.chomp(File.extname(file))
  end
  if self.class.target_format
    file = file + '.' + self.class.target_format.to_s
  end
  file
end
transform(str)
Alias for: process