diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-03 23:18:39 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-03 23:18:39 -0700 |
commit | a0115458cd27e1b9e6c05f56fdff88dc1ccca0d9 (patch) | |
tree | 4d5430fd015b2b0eb3b893d35d5ce7ab06246245 /lib/chef/mixin | |
parent | 288a37ae2f6a3999b380efe77c1459baf13d5ccb (diff) | |
download | chef-a0115458cd27e1b9e6c05f56fdff88dc1ccca0d9.tar.gz |
Fix hyphenated LWRP nameshyphenated-lwrp
Diffstat (limited to 'lib/chef/mixin')
-rw-r--r-- | lib/chef/mixin/convert_to_class_name.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/chef/mixin/convert_to_class_name.rb b/lib/chef/mixin/convert_to_class_name.rb index 19f229fdd3..14676e5ed4 100644 --- a/lib/chef/mixin/convert_to_class_name.rb +++ b/lib/chef/mixin/convert_to_class_name.rb @@ -23,9 +23,7 @@ class Chef extend self def convert_to_class_name(str) - str = str.dup - str.gsub!(/[^A-Za-z0-9_]/,'_') - str.gsub!(/^(_+)?/,'') + str = normalize_snake_case_name(str) rname = nil regexp = %r{^(.+?)(_(.+))?$} @@ -51,6 +49,13 @@ class Chef str end + def normalize_snake_case_name(str) + str = str.dup + str.gsub!(/[^A-Za-z0-9_]/,'_') + str.gsub!(/^(_+)?/,'') + str + end + def snake_case_basename(str) with_namespace = convert_to_snake_case(str) with_namespace.split("::").last.sub(/^_/, '') @@ -58,7 +63,8 @@ class Chef def filename_to_qualified_string(base, filename) file_base = File.basename(filename, ".rb") - base.to_s + (file_base == 'default' ? '' : "_#{file_base}") + str = base.to_s + (file_base == 'default' ? '' : "_#{file_base}") + normalize_snake_case_name(str) end # Copied from rails activesupport. In ruby >= 2.0 const_get will just do this, so this can |