forked from redhat-openstack/openstack-puppet-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request redhat-openstack#182 from mhaskel/MODULES-2212
MODULES-2212 - Add use_exact_match parameter for subsettings
- Loading branch information
Showing
5 changed files
with
144 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,103 @@ | ||
module Puppet | ||
module Util | ||
module Util | ||
|
||
class SettingValue | ||
class SettingValue | ||
|
||
def initialize(setting_value, subsetting_separator = ' ', default_quote_char = nil) | ||
@setting_value = setting_value | ||
@subsetting_separator = subsetting_separator | ||
def initialize(setting_value, subsetting_separator = ' ', default_quote_char = nil) | ||
@setting_value = setting_value | ||
@subsetting_separator = subsetting_separator | ||
|
||
default_quote_char ||= '' | ||
default_quote_char ||= '' | ||
|
||
if @setting_value | ||
unquoted, @quote_char = unquote_setting_value(setting_value) | ||
@subsetting_items = unquoted.scan(Regexp.new("(?:(?:[^\\#{@subsetting_separator}]|\\.)+)")) # an item can contain escaped separator | ||
@subsetting_items.map! { |item| item.strip } | ||
@quote_char = default_quote_char if @quote_char.empty? | ||
else | ||
@subsetting_items = [] | ||
@quote_char = default_quote_char | ||
end | ||
end | ||
if @setting_value | ||
unquoted, @quote_char = unquote_setting_value(setting_value) | ||
@subsetting_items = unquoted.scan(Regexp.new("(?:(?:[^\\#{@subsetting_separator}]|\\.)+)")) # an item can contain escaped separator | ||
@subsetting_items.map! { |item| item.strip } | ||
@quote_char = default_quote_char if @quote_char.empty? | ||
else | ||
@subsetting_items = [] | ||
@quote_char = default_quote_char | ||
end | ||
end | ||
|
||
def unquote_setting_value(setting_value) | ||
quote_char = "" | ||
if (setting_value.start_with?('"') and setting_value.end_with?('"')) | ||
quote_char = '"' | ||
elsif (setting_value.start_with?("'") and setting_value.end_with?("'")) | ||
quote_char = "'" | ||
end | ||
|
||
unquoted = setting_value | ||
|
||
def unquote_setting_value(setting_value) | ||
quote_char = "" | ||
if (setting_value.start_with?('"') and setting_value.end_with?('"')) | ||
quote_char = '"' | ||
elsif (setting_value.start_with?("'") and setting_value.end_with?("'")) | ||
quote_char = "'" | ||
if (quote_char != "") | ||
unquoted = setting_value[1, setting_value.length - 2] | ||
end | ||
|
||
[unquoted, quote_char] | ||
end | ||
|
||
unquoted = setting_value | ||
def get_value | ||
|
||
result = "" | ||
first = true | ||
|
||
@subsetting_items.each { |item| | ||
result << @subsetting_separator unless first | ||
result << item | ||
first = false | ||
} | ||
|
||
if (quote_char != "") | ||
unquoted = setting_value[1, setting_value.length - 2] | ||
@quote_char + result + @quote_char | ||
end | ||
|
||
[unquoted, quote_char] | ||
end | ||
def get_subsetting_value(subsetting, use_exact_match=:false) | ||
|
||
def get_value | ||
|
||
result = "" | ||
first = true | ||
|
||
@subsetting_items.each { |item| | ||
result << @subsetting_separator unless first | ||
result << item | ||
first = false | ||
} | ||
|
||
@quote_char + result + @quote_char | ||
end | ||
value = nil | ||
|
||
@subsetting_items.each { |item| | ||
if(use_exact_match == :false and item.start_with?(subsetting)) | ||
value = item[subsetting.length, item.length - subsetting.length] | ||
break | ||
elsif(use_exact_match == :true and item.eql?(subsetting)) | ||
return true | ||
end | ||
} | ||
|
||
def get_subsetting_value(subsetting) | ||
|
||
value = nil | ||
|
||
@subsetting_items.each { |item| | ||
if(item.start_with?(subsetting)) | ||
value = item[subsetting.length, item.length - subsetting.length] | ||
break | ||
value | ||
end | ||
|
||
def add_subsetting(subsetting, subsetting_value, use_exact_match=:false) | ||
|
||
new_item = subsetting + (subsetting_value || '') | ||
found = false | ||
|
||
@subsetting_items.map! { |item| | ||
if use_exact_match == :false and item.start_with?(subsetting) | ||
value = new_item | ||
found = true | ||
elsif use_exact_match == :true and item.eql?(subsetting) | ||
value = new_item | ||
found = true | ||
else | ||
value = item | ||
end | ||
|
||
value | ||
} | ||
|
||
unless found | ||
@subsetting_items.push(new_item) | ||
end | ||
} | ||
|
||
value | ||
end | ||
|
||
def add_subsetting(subsetting, subsetting_value) | ||
|
||
new_item = subsetting + (subsetting_value || '') | ||
found = false | ||
|
||
@subsetting_items.map! { |item| | ||
if item.start_with?(subsetting) | ||
value = new_item | ||
found = true | ||
end | ||
|
||
def remove_subsetting(subsetting, use_exact_match=:false) | ||
if use_exact_match == :false | ||
@subsetting_items = @subsetting_items.map { |item| item.start_with?(subsetting) ? nil : item }.compact | ||
else | ||
value = item | ||
@subsetting_items = @subsetting_items.map { |item| item.eql?(subsetting) ? nil : item }.compact | ||
end | ||
|
||
value | ||
} | ||
|
||
unless found | ||
@subsetting_items.push(new_item) | ||
end | ||
end | ||
|
||
def remove_subsetting(subsetting) | ||
@subsetting_items = @subsetting_items.map { |item| item.start_with?(subsetting) ? nil : item }.compact | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters