Module: Jsus::Util

Defined in:
lib/jsus/util.rb,
lib/jsus/util/tree.rb,
lib/jsus/util/logger.rb,
lib/jsus/util/mixins.rb,
lib/jsus/util/validator.rb,
lib/jsus/util/compressor.rb,
lib/jsus/util/documenter.rb,
lib/jsus/util/file_cache.rb,
lib/jsus/util/inflection.rb,
lib/jsus/util/code_generator.rb,
lib/jsus/util/post_processor.rb,
lib/jsus/util/validator/base.rb,
lib/jsus/util/validator/mooforge.rb,
lib/jsus/util/post_processor/base.rb,
lib/jsus/util/post_processor/mooltie8.rb,
lib/jsus/util/post_processor/semicolon.rb,
lib/jsus/util/mixins/operates_on_sources.rb,
lib/jsus/util/post_processor/moocompat12.rb

Overview

Utility namespace.

Defined Under Namespace

Modules: CodeGenerator, Compressor, Inflection, Mixins, PostProcessor, Validator Classes: Documenter, FileCache, Logger, Tree, Watcher

Class Method Summary collapse

Class Method Details

.read_file(filename) ⇒ Object

Reads file in UTF-8 encoding in a safe way. Some ruby versions mess up the encodings and some spill out lots of warnings unless you do the right thing



37
38
39
40
# File 'lib/jsus/util.rb', line 37

def read_file(filename)
  mode_string = RUBY_VERSION =~ /^1.9/ ? 'r:utf-8' : 'r'
  File.open(filename, mode_string) {|f| f.read }
end

.try_load(gemname, lib = nil) ⇒ Boolean

Tries to load given gem.

Parameters:

  • gemname (String)

    gem name

  • lib (String, nil) (defaults to: nil)

    path to load. When set to nil, uses gemname param

Returns:

  • (Boolean)

    true if that lib could be required, false otherwise



23
24
25
26
27
28
29
30
31
32
# File 'lib/jsus/util.rb', line 23

def try_load(gemname, lib = nil)
  required_file = lib || gemname
  begin
    require(required_file)
    true
  rescue LoadError
    Jsus.logger.error %{ERROR: missing file #{required_file}}
    false
  end
end