Class: Shift::Identity
- Inherits:
-
Object
- Object
- Shift::Identity
- Defined in:
- lib/shift/c/identity.rb
Overview
Returns the input unaltered. The purpose is mainly to inherit from this when defining other, more useful compilers.
Direct Known Subclasses
ClosureCompiler, CoffeeScript, RDiscount, Redcarpet, Sass, UglifyJS, YUICompressor
Defined Under Namespace
Modules: StringExtension
Class Method Summary collapse
-
.available? ⇒ Boolean
Wether the requirements are met in the current environment.
-
.compiler_class ⇒ Object
The class of the wrapped compiler, or false if none is used.
-
.default ⇒ Object
A default instance without options.
-
.gem_dependencies ⇒ Object
A list of Rubygems needed for the component to work.
-
.instructions ⇒ Object
One-liner on what the user must have/do to make it available.
- .new(*prms) ⇒ Object
-
.require_libs ⇒ Object
A list of things to be required on initialization.
Instance Method Summary collapse
-
#initialize(*prms) ⇒ Identity
constructor
Create a new instance.
-
#process(str) ⇒ Object
(also: #compress, #compile, #transform)
Process the supplied string, returning the resulting
String
(with a #write method attached to it). -
#process_plain(str) ⇒ Object
Process the supplied string, returning the resulting
String
. -
#read(path) ⇒ String
Read and process a file.
Constructor Details
#initialize(*prms) ⇒ Identity
Create a new instance. Ignores the given options.
80 81 82 83 84 |
# File 'lib/shift/c/identity.rb', line 80 def initialize(*prms) if self.class.compiler_class @engine = self.class.compiler_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.
40 41 42 |
# File 'lib/shift/c/identity.rb', line 40 def self.available? gem_dependencies.all? {|d| Gem.available?(d) } end |
.compiler_class ⇒ Object
The class of the wrapped compiler, or false if none is used.
59 60 61 |
# File 'lib/shift/c/identity.rb', line 59 def self.compiler_class false end |
.default ⇒ Object
A default instance without options.
65 66 67 |
# File 'lib/shift/c/identity.rb', line 65 def self.default @default ||= new end |
.gem_dependencies ⇒ Object
A list of Rubygems needed for the component to work.
46 47 48 |
# File 'lib/shift/c/identity.rb', line 46 def self.gem_dependencies [] end |
.instructions ⇒ Object
One-liner on what the user must have/do to make it available. Used in DependencyError.
28 29 30 31 32 33 34 |
# File 'lib/shift/c/identity.rb', line 28 def self.instructions if gem_dependencies.any? 'gem install ' + gem_dependencies.join(' ') else 'Google it :)' end end |
.new(*prms) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/shift/c/identity.rb', line 69 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.
52 53 54 |
# File 'lib/shift/c/identity.rb', line 52 def self.require_libs gem_dependencies end |
Instance Method Details
#process(str) ⇒ Object Also known as: compress, compile, transform
Process the supplied string, returning the resulting String
(with a #write method attached to it).
88 89 90 |
# File 'lib/shift/c/identity.rb', line 88 def process(str) process_plain(str).extend(StringExtension) end |
#process_plain(str) ⇒ Object
Process the supplied string, returning the resulting String
.
97 98 99 |
# File 'lib/shift/c/identity.rb', line 97 def process_plain(str) str.dup end |
#read(path) ⇒ String
Read and process a file.
108 109 110 |
# File 'lib/shift/c/identity.rb', line 108 def read(path) process(File.read(path)).extend(StringExtension) end |