Module: Detroit::BasicUtils

Included in:
BasicTool
Defined in:
lib/detroit/basic_utils.rb

Overview

Common utility methods included in all tools.

Instance Method Summary collapse

Instance Method Details

#apply_naming_policy(name, ext) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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

#configObject

Configuration.



32
33
34
# File 'lib/detroit/basic_utils.rb', line 32

def config
  @config ||= Config.new(root)
end

#naming_policyObject



37
38
39
40
41
42
43
44
45
# 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

#rootObject

Project root directory.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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_patternObject

Glob for finding root of a project.



9
10
11
# File 'lib/detroit/basic_utils.rb', line 9

def root_pattern
  "{.index,.git,.hg,.svn,_darcs}"
end