Class: InstanceAgent::CodeDeployPlugin::ApplicationSpecification::RangeInfo
- Inherits:
-
Object
- Object
- InstanceAgent::CodeDeployPlugin::ApplicationSpecification::RangeInfo
- Defined in:
- lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb
Overview
Helper Class for storing the range of a context
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#high_sensitivity ⇒ Object
readonly
Returns the value of attribute high_sensitivity.
-
#low_sensitivity ⇒ Object
readonly
Returns the value of attribute low_sensitivity.
Instance Method Summary collapse
- #ensure_parts(input, split_on) ⇒ Object
- #get_category_number(category) ⇒ Object
- #get_category_numbers(parts) ⇒ Object
- #get_category_range(range) ⇒ Object
-
#get_range ⇒ Object
format s#[-s#][:c#.c#*] (# means a number).
- #getSensitivityNumber(sensitivity) ⇒ Object
-
#initialize(range) ⇒ RangeInfo
constructor
A new instance of RangeInfo.
Constructor Details
#initialize(range) ⇒ RangeInfo
Returns a new instance of RangeInfo.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 10 def initialize(range) parts = ensure_parts(range, ":") sensitivity_parts = ensure_parts(parts[0], "-") @low_sensitivity = getSensitivityNumber(sensitivity_parts[0]) if sensitivity_parts.length == 2 @high_sensitivity = getSensitivityNumber(sensitivity_parts[1]) if @high_sensitivity < @low_sensitivity raise AppSpecValidationException, "invalid sensitivity range in #{range}" end else @high_sensitivity = @low_sensitivity end if parts.length == 2 @categories = get_category_numbers(parts[1].split(",")) end end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 8 def categories @categories end |
#high_sensitivity ⇒ Object (readonly)
Returns the value of attribute high_sensitivity.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 8 def high_sensitivity @high_sensitivity end |
#low_sensitivity ⇒ Object (readonly)
Returns the value of attribute low_sensitivity.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 8 def low_sensitivity @low_sensitivity end |
Instance Method Details
#ensure_parts(input, split_on) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 27 def ensure_parts(input, split_on) num_parts = 1 if input.include?(split_on) num_parts = 2 end parts = input.split(split_on, 2) if parts.length != num_parts raise AppSpecValidationException, "invalid range part #{input}" end parts.each do |part| if part.nil? || part.eql?('') raise AppSpecValidationException, "invalid range part #{input}" end end parts end |
#get_category_number(category) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 57 def get_category_number(category) if category.nil? || category.length < 2 || !category.start_with?('c') raise AppSpecValidationException, "invalid category #{category}" end c_level = category.sub('c', '') c_level.chars.each do |digit| if (digit.ord < '0'.ord) || (digit.ord > '9'.ord) raise AppSpecValidationException, "invalid category #{category}" end end level = c_level.to_i if level > 1023 raise AppSpecValidationException, "invalid category #{category}" end level end |
#get_category_numbers(parts) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 83 def get_category_numbers(parts) temp_categories = []; parts.each do |part| if part.include? "." temp_categories.concat get_category_range(ensure_parts(part, ".")) else temp_categories << get_category_number(part) end end if !temp_categories.sort!.uniq!.nil? raise AppSpecValidationException, "duplicate categories" end temp_categories end |
#get_category_range(range) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 74 def get_category_range(range) low = get_category_number(range[0]) high = get_category_number(range[1]) if (high < low) raise AppSpecValidationException, "invalid category range #{range[0]}.#{range[1]}" end (low..high).to_a end |
#get_range ⇒ Object
format s#[-s#][:c#.c#*] (# means a number)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 99 def get_range range = "s" + @low_sensitivity.to_s if (@low_sensitivity != @high_sensitivity) range = range + "-s" + @high_sensitivity.to_s end if @categories range = range + ":" index = 0 while index < @categories.length if (index != 0) range = range + "," end low = @categories[index] low_index = index high = @categories[index] index += 1 while (@categories[index] == low + (index - low_index)) high += 1 index += 1 end if (low == high) range = range + "c" + low.to_s else range = range + "c" + low.to_s + ".c" + high.to_s end end end range end |
#getSensitivityNumber(sensitivity) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb', line 44 def getSensitivityNumber(sensitivity) if sensitivity.nil? || sensitivity.length < 2 || !sensitivity.start_with?('s') raise AppSpecValidationException, "invalid sensitivity #{sensitivity}" end s_level = sensitivity.sub('s', '') s_level.chars.each do |digit| if (digit.ord < '0'.ord) || (digit.ord > '9'.ord) raise AppSpecValidationException, "invalid sensitivity #{sensitivity}" end end s_level.to_i end |