module Detroit::BasicUtils

Common utility methods included in all tools.

Public Instance Methods

apply_naming_policy(name, ext) click to toggle source
# File lib/detroit/basic_utils.rb, line 48
def apply_naming_policy(name, ext)
  naming_policy.each do |policy|
    case policy.to_s
    when /^low/, /^down/
      name = name.downcase
    when /^up/
      name = name.upcase
    when /^cap/
      name = name.capitalize
    when /^ext/
      name = name + ".#{ext}"
    end
  end
  name
end
config() click to toggle source

Configuration.

# File lib/detroit/basic_utils.rb, line 32
def config
  @config ||= Config.new(root)
end
naming_policy() click to toggle source
# File lib/detroit/basic_utils.rb, line 37
def naming_policy
  @naming_policy ||= (
    if config.naming_policy
      Array(config.naming_policy)
    else
      ['down', 'ext']
    end
  )
end
root() click to toggle source

Project root directory.

# File lib/detroit/basic_utils.rb, line 14
def root
  @root ||= (
    path = nil
    home = File.expand_path('~')

    while dir != home && dir != '/'
      if Dir[root_pattern].first
        path = dir
        break
      end
      dir = File.dirname(dir)
    end

    Pathname.new(path || Dir.pwd)
  )
end
root_pattern() click to toggle source

Glob for finding root of a project.

# File lib/detroit/basic_utils.rb, line 9
def root_pattern
  "{.index,.git,.hg,.svn,_darcs}"
end