Class: RSpec::Core::Formatters::Loader
- Inherits:
-
Object
- Object
- RSpec::Core::Formatters::Loader
- Defined in:
- opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
Instance Method Summary collapse
- #custom_formatter(formatter_ref) ⇒ Object
- #string_const?(str) ⇒ Boolean
- #underscore(camel_cased_word) ⇒ Object
Instance Method Details
#custom_formatter(formatter_ref) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'opal/opal/rspec/fixes/rspec/core/formatters/loader.rb', line 18 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 |
#string_const?(str) ⇒ Boolean
2 3 4 5 6 |
# File 'opal/opal/rspec/fixes/rspec/core/formatters/loader.rb', line 2 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 |
#underscore(camel_cased_word) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'opal/opal/rspec/fixes/rspec/core/formatters/loader.rb', line 8 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 |