Sha256: 00d5251ce93f33849c6d72870faf920affb160248ee52f59671b424f5612bd37

Contents?: true

Size: 893 Bytes

Versions: 1

Compression:

Stored size: 893 Bytes

Contents

module Shift
  
  # Mappings from file names to implementation classes. The
  # classes are listed in order of preference per type.
  #
  MAPPINGS = {
    'echo'    => %w{ Identity },
    'js'      => %w{ UglifyJS ClosureCompiler YUICompressor },
    'coffee'  => %w{ CoffeeScript },
    'sass'    => %w{ Sass },
    'md'      => %w{ RDiscount Redcarpet }
  }

  # @raise [DependencyError] when none of the mapped
  #   implementations are available.
  #
  # @return [Class] The preferred available class associated
  #   with the file or extension.
  #
  def self.best_available_mapping_for(key)
    MAPPINGS[key].each do |kls_name|
      kls = const_get(kls_name)
      return kls if kls.available?
    end
    help = const_get(MAPPINGS[key].first)::INSTRUCTIONS
    raise DependencyError, "no implementation available for " +
      "#{key.inspect}. Possible solution: #{help}"
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shift-0.1.0 lib/shift/mappings.rb