summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-12 16:35:31 -0600
committerLuke Kanies <luke@madstop.com>2008-02-12 16:35:31 -0600
commit3af6827875f4e02b47fe2293280ff9afe811485f (patch)
treeec7d13b046b8cb7ee598444e4e79063f017e5504 /lib/puppet/util
parent7e45553448f2a051594ee4f2fc83ebcfa4a8114a (diff)
downloadpuppet-3af6827875f4e02b47fe2293280ff9afe811485f.tar.gz
puppet-3af6827875f4e02b47fe2293280ff9afe811485f.tar.xz
puppet-3af6827875f4e02b47fe2293280ff9afe811485f.zip
Adding an inflection util class.
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/constant_inflector.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/puppet/util/constant_inflector.rb b/lib/puppet/util/constant_inflector.rb
new file mode 100644
index 000000000..8b083951f
--- /dev/null
+++ b/lib/puppet/util/constant_inflector.rb
@@ -0,0 +1,14 @@
+# 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)
+ 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