summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/constant_inflector.rb
blob: 8f93e32558c7331bc515f77b8f7d36d7b0fd72e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Created on 2008-02-12
# Copyright Luke Kanies

# A common module for converting between constants and
# file names.
module Puppet::Util::ConstantInflector
  def file2constant(file)
    # LAK:NOTE See http://snurl.com/21zf8  [groups_google_com]
    x = file.split("/").collect { |name| name.capitalize }.join("::").gsub(/_+(.)/) { |term| $1.capitalize }
  end

  def constant2file(constant)
    constant.to_s.gsub(/([a-z])([A-Z])/) { |term| $1 + "_#{$2}" }.gsub("::", "/").downcase
  end
end