Class: Shift::Identity

Inherits:
Object
  • Object
show all
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.

Defined Under Namespace

Modules: StringExtension

Class Method Summary collapse

Instance Method Summary collapse

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.

Returns:

  • (Boolean)


40
41
42
# File 'lib/shift/c/identity.rb', line 40

def self.available?
  gem_dependencies.all? {|d| Gem.available?(d) }
end

.compiler_classObject

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

.defaultObject

A default instance without options.



65
66
67
# File 'lib/shift/c/identity.rb', line 65

def self.default
  @default ||= new
end

.gem_dependenciesObject

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

.instructionsObject

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_libsObject

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.

Returns:

  • (String)

    The processed String

Raises:

  • (DependencyError)

    when none of the mapped implementations are available.



108
109
110
# File 'lib/shift/c/identity.rb', line 108

def read(path)
  process(File.read(path)).extend(StringExtension)
end