Sha256: 7f2f3887857df3ea36e09157a1f77fc16077321be5b2f7da79d0ccafda782b93

Contents?: true

Size: 814 Bytes

Versions: 5

Compression:

Stored size: 814 Bytes

Contents

# -*- encoding: utf-8 -*-

module Webgen

  # Namespace for classes and methods that provide common functionality.
  module Common

    autoload :Sitemap, 'webgen/common/sitemap'

    # Return the constant object for the given absolute constant +name+.
    def self.const_for_name(name)
      name.split('::').inject(Object) {|b,n| b.const_get(n)}
    end

    # Return the error line by inspecting the backtrace of the given +error+ instance.
    def self.error_line(error)
      (error.is_a?(::SyntaxError) ? error.message : error.backtrace[0]).scan(/:(\d+)/).first.first.to_i rescue nil
    end

    # Return the file name where the error occured.
    def self.error_file(error)
      (error.is_a?(::SyntaxError) ? error.message : error.backtrace[0]).scan(/(?:^|\s)(.*?):(\d+)/).first.first
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
webgen-0.5.17 lib/webgen/common.rb
webgen-0.5.15 lib/webgen/common.rb
webgen-0.5.14 lib/webgen/common.rb
webgen-0.5.13 lib/webgen/common.rb
webgen-0.5.12 lib/webgen/common.rb