Sha256: 569b71ebc7c91492860a0606bcd95d459513d24cf1e1f89dc086069c7cc40772

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

class ::RSpec::Core::Formatters::Loader
  def string_const?(str)
    # Incompatible regex (\A flag and \z flag)
    # str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
    str.is_a?(String) && /^[A-Z][a-zA-Z0-9_:]*$/ =~ str
  end

  def underscore(camel_cased_word)
    # string mutation
    word = camel_cased_word.to_s.dup
    word = word.gsub(/::/, '/')
    word = word.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    word = word.gsub(/([a-z\d])([A-Z])/, '\1_\2')
    word = word.tr("-", "_")
    word.downcase
  end

  alias add_without_fix add
  def add(formatter_to_use, *paths)
    paths = paths.map{|p| String === p ? file_at(p) : p }
    add_without_fix(formatter_to_use, *paths)
  end

  def custom_formatter(formatter_ref)
    if Class === formatter_ref
      formatter_ref
    elsif string_const?(formatter_ref)
      # retry not supported on opal
      # begin
      #   formatter_ref.gsub(/^::/, '').split('::').inject(Object) { |a, e| a.const_get e }
      # rescue NameError
      #   require(path_for(formatter_ref)) ? retry : raise
      # end
      while true
        begin
          return formatter_ref.gsub(/^::/, '').split('::').inject(Object) { |a, e| a.const_get e }
        rescue NameError
          raise unless require(path_for(formatter_ref))
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
opal-rspec-0.8.0 lib-opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.8.0.alpha3 lib-opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.8.0.alpha2 lib-opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.8.0.alpha1 lib-opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.7.1 lib-opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.7.0 lib-opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.7.0.rc.2 lib-opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.7.0.rc.1 lib-opal/opal/rspec/fixes/rspec/core/formatters/loader.rb