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
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
A default instance without options.
# File lib/shift/interface.rb, line 63 def self.default @default ||= new end
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
A list of Rubygems needed for the interface to work.
# File lib/shift/interface.rb, line 31 def self.gem_dependencies [] end
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
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
# 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
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
A list of things to be required on initialization.
# File lib/shift/interface.rb, line 37 def self.require_libs gem_dependencies end
The format typically produced by the generator.
# File lib/shift/interface.rb, line 50 def self.target_format false end
Public Instance Methods
Process the supplied string, returning the resulting ‘String`.
# File lib/shift/interface.rb, line 86 def process(str) str.dup end
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