Module: Loader::Utils

Extended by:
Utils
Included in:
Fetcher, Utils
Defined in:
lib/loader/utils.rb

Instance Method Summary collapse

Instance Method Details

#pwdObject



12
13
14
15
16
17
18
19
20
# File 'lib/loader/utils.rb', line 12

def pwd
  if !!ENV['BUNDLE_GEMFILE']
    ENV['BUNDLE_GEMFILE'].split(File::Separator)[0..-2].join(File::Separator)
  elsif defined?(Rails) && Rails.respond_to?(:root) && Rails.root
    Rails.root.to_s
  else
    Dir.pwd
  end
end

#require(file_path) ⇒ Object



6
7
8
9
10
# File 'lib/loader/utils.rb', line 6

def require(file_path)
  Kernel.require(file_path)
rescue LoadError
  Kernel.load(file_path)
end

#underscore(camel_cased_word) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/loader/utils.rb', line 24

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