Class: Shift::Interface
- Inherits:
-
Object
- Object
- Shift::Interface
- Defined in:
- lib/shift/interface.rb
Overview
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.
Direct Known Subclasses
ClosureCompiler, CoffeeScript, Echo, RDiscount, Redcarpet, Sass, UglifyJS, YUICompressor, ZlibReader, ZlibWriter
Class Method Summary collapse
-
.available? ⇒ Boolean
Wether the requirements are met in the current environment.
-
.default ⇒ Object
A default instance without options.
-
.engine_class ⇒ Object
The class of the wrapped generator, or false if none is used.
-
.gem_dependencies ⇒ Object
A list of Rubygems needed for the interface to work.
-
.instructions ⇒ Object
One-liner on what the user can do to make it available.
-
.keep_extension? ⇒ Boolean
Whether to leave the old extension as is and append, like something.css => something.css.gzip.
- .new(*prms) ⇒ Object
-
.require_libs ⇒ Object
A list of things to be required on initialization.
-
.target_format ⇒ Object
The format typically produced by the generator.
Instance Method Summary collapse
-
#initialize(*prms) ⇒ Interface
constructor
Create a new instance with the given options.
-
#process(str) ⇒ Object
(also: #compress, #compile, #transform)
Process the supplied string, returning the resulting
String
. -
#rename(file) ⇒ String
Get the default filename of a transformed file.
Constructor Details
#initialize(*prms) ⇒ Interface
Create a new instance with the given options.
78 79 80 81 82 |
# File 'lib/shift/interface.rb', line 78 def initialize(*prms) if self.class.engine_class @engine = self.class.engine_class.new(*prms) end end |
Class Method Details
.available? ⇒ Boolean
Wether the requirements are met in the current environment. Typically checks if the required gems and/or command line stuff is available.
25 26 27 |
# File 'lib/shift/interface.rb', line 25 def self.available? gem_dependencies.all? {|d| Gem.available?(d) } end |
.default ⇒ Object
A default instance without options.
63 64 65 |
# File 'lib/shift/interface.rb', line 63 def self.default @default ||= new end |
.engine_class ⇒ Object
The class of the wrapped generator, or false if none is used.
44 45 46 |
# File 'lib/shift/interface.rb', line 44 def self.engine_class false end |
.gem_dependencies ⇒ Object
A list of Rubygems needed for the interface to work.
31 32 33 |
# File 'lib/shift/interface.rb', line 31 def self.gem_dependencies [] end |
.instructions ⇒ Object
One-liner on what the user can do to make it available. Used in DependencyError.
13 14 15 16 17 18 19 |
# 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? ⇒ Boolean
Whether to leave the old extension as is and append, like something.css => something.css.gzip
57 58 59 |
# File 'lib/shift/interface.rb', line 57 def self.keep_extension? false end |
.new(*prms) ⇒ Object
67 68 69 70 71 72 73 74 |
# 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 |
.require_libs ⇒ Object
A list of things to be required on initialization.
37 38 39 |
# File 'lib/shift/interface.rb', line 37 def self.require_libs gem_dependencies end |
.target_format ⇒ Object
The format typically produced by the generator.
50 51 52 |
# File 'lib/shift/interface.rb', line 50 def self.target_format false end |
Instance Method Details
#process(str) ⇒ Object Also known as: compress, compile, transform
Process the supplied string, returning the resulting String
.
86 87 88 |
# File 'lib/shift/interface.rb', line 86 def process(str) str.dup end |
#rename(file) ⇒ String
Get the default filename of a transformed file.
97 98 99 100 101 102 103 104 105 106 107 108 |
# 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 |