Class: Gapic::PathPattern::ResourceIdSegment
- Inherits:
-
Object
- Object
- Gapic::PathPattern::ResourceIdSegment
- Defined in:
- lib/gapic/path_pattern/segment.rb
Overview
A ResourceId segment in a path pattern. ResourceId segments can be simple, with one resource name or complex, with multiple resource names divided by separators
Instance Attribute Summary collapse
-
#pattern ⇒ String
readonly
The pattern of the segment, for the positional segment it is also a pattern of its resource.
-
#resource_names ⇒ Array<String>
readonly
The resource names in this segment.
-
#resource_patterns ⇒ Array<String>
readonly
The resource patterns associated with the resource_names of this segment.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.create_simple(name) ⇒ ResourceIdSegment
Initialization helper to create a simple resource without a pattern.
Instance Method Summary collapse
-
#arguments ⇒ Array<String>
Names of the segment's arguments.
-
#expected_path_for_dummy_values(start_index) ⇒ String
Returns a segment's pattern filled with dummy values names of the values are generated starting from the index provided.
-
#initialize(type, pattern, resource_names, resource_patterns = []) ⇒ ResourceIdSegment
constructor
A new instance of ResourceIdSegment.
-
#nontrivial_resource_pattern? ⇒ Boolean
Whether the segment provides a nontrivial resource pattern.
-
#path_string ⇒ String
Path string for this segment.
-
#pattern_template ⇒ String
A pattern template for this segment.
-
#positional? ⇒ Boolean
Whether the segment is positional.
-
#provides_arguments? ⇒ Boolean
Whether the segment provides arguments.
-
#resource_pattern? ⇒ Boolean
Whether the segment provides a resource pattern.
Constructor Details
#initialize(type, pattern, resource_names, resource_patterns = []) ⇒ ResourceIdSegment
Returns a new instance of ResourceIdSegment.
128 129 130 131 132 133 |
# File 'lib/gapic/path_pattern/segment.rb', line 128 def initialize type, pattern, resource_names, resource_patterns = [] @type = type @pattern = pattern @resource_names = resource_names @resource_patterns = resource_patterns end |
Instance Attribute Details
#pattern ⇒ String (readonly)
Returns The pattern of the segment, for the positional segment it is also a pattern of its resource.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/gapic/path_pattern/segment.rb', line 122 class ResourceIdSegment attr_reader :type attr_reader :pattern attr_reader :resource_names attr_reader :resource_patterns def initialize type, pattern, resource_names, resource_patterns = [] @type = type @pattern = pattern @resource_names = resource_names @resource_patterns = resource_patterns end ## # Whether the segment is positional # @return [Boolean] def positional? false end ## # Whether the segment provides a resource pattern # @return [Boolean] def resource_pattern? resource_patterns.any? end ## # Whether the segment provides a nontrivial resource pattern # @return [Boolean] def nontrivial_resource_pattern? resource_patterns.any? { |res_pattern| !res_pattern.match?(/^\*+$/) } end ## # Whether the segment provides arguments # @return [Boolean] def provides_arguments? true end ## # Names of the segment's arguments # @return [Array<String>] def arguments resource_names end ## # Returns a segment's pattern filled with dummy values # names of the values are generated starting from the index provided # @param start_index [Integer] a starting index for dummy value generation # @return [String] a pattern filled with dummy values def expected_path_for_dummy_values start_index return "value#{start_index}" if type == :simple_resource_id resource_names.each_with_index.reduce pattern do |exp_path, (res_name, index)| exp_path.sub "{#{res_name}}", "value#{start_index + index}" end end ## # Path string for this segment # @return [String] def path_string type == :simple_resource_id ? "\#{#{resource_names[0]}}" : pattern.gsub("{", "\#{") end ## # A pattern template for this segment # @return [String] def pattern_template "*" end ## # Initialization helper to create a simple resource without a pattern # @param name [String] resource name # @return [ResourceIdSegment] def self.create_simple name ResourceIdSegment.new :simple_resource_id, "{#{name}}", [name] end # @private def == other return false unless other.is_a? self.class (type == other.type && pattern == other.pattern && resource_names == other.resource_names && resource_patterns == other.resource_patterns) end end |
#resource_names ⇒ Array<String> (readonly)
Returns The resource names in this segment.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/gapic/path_pattern/segment.rb', line 122 class ResourceIdSegment attr_reader :type attr_reader :pattern attr_reader :resource_names attr_reader :resource_patterns def initialize type, pattern, resource_names, resource_patterns = [] @type = type @pattern = pattern @resource_names = resource_names @resource_patterns = resource_patterns end ## # Whether the segment is positional # @return [Boolean] def positional? false end ## # Whether the segment provides a resource pattern # @return [Boolean] def resource_pattern? resource_patterns.any? end ## # Whether the segment provides a nontrivial resource pattern # @return [Boolean] def nontrivial_resource_pattern? resource_patterns.any? { |res_pattern| !res_pattern.match?(/^\*+$/) } end ## # Whether the segment provides arguments # @return [Boolean] def provides_arguments? true end ## # Names of the segment's arguments # @return [Array<String>] def arguments resource_names end ## # Returns a segment's pattern filled with dummy values # names of the values are generated starting from the index provided # @param start_index [Integer] a starting index for dummy value generation # @return [String] a pattern filled with dummy values def expected_path_for_dummy_values start_index return "value#{start_index}" if type == :simple_resource_id resource_names.each_with_index.reduce pattern do |exp_path, (res_name, index)| exp_path.sub "{#{res_name}}", "value#{start_index + index}" end end ## # Path string for this segment # @return [String] def path_string type == :simple_resource_id ? "\#{#{resource_names[0]}}" : pattern.gsub("{", "\#{") end ## # A pattern template for this segment # @return [String] def pattern_template "*" end ## # Initialization helper to create a simple resource without a pattern # @param name [String] resource name # @return [ResourceIdSegment] def self.create_simple name ResourceIdSegment.new :simple_resource_id, "{#{name}}", [name] end # @private def == other return false unless other.is_a? self.class (type == other.type && pattern == other.pattern && resource_names == other.resource_names && resource_patterns == other.resource_patterns) end end |
#resource_patterns ⇒ Array<String> (readonly)
Returns The resource patterns associated with the resource_names of this segment.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/gapic/path_pattern/segment.rb', line 122 class ResourceIdSegment attr_reader :type attr_reader :pattern attr_reader :resource_names attr_reader :resource_patterns def initialize type, pattern, resource_names, resource_patterns = [] @type = type @pattern = pattern @resource_names = resource_names @resource_patterns = resource_patterns end ## # Whether the segment is positional # @return [Boolean] def positional? false end ## # Whether the segment provides a resource pattern # @return [Boolean] def resource_pattern? resource_patterns.any? end ## # Whether the segment provides a nontrivial resource pattern # @return [Boolean] def nontrivial_resource_pattern? resource_patterns.any? { |res_pattern| !res_pattern.match?(/^\*+$/) } end ## # Whether the segment provides arguments # @return [Boolean] def provides_arguments? true end ## # Names of the segment's arguments # @return [Array<String>] def arguments resource_names end ## # Returns a segment's pattern filled with dummy values # names of the values are generated starting from the index provided # @param start_index [Integer] a starting index for dummy value generation # @return [String] a pattern filled with dummy values def expected_path_for_dummy_values start_index return "value#{start_index}" if type == :simple_resource_id resource_names.each_with_index.reduce pattern do |exp_path, (res_name, index)| exp_path.sub "{#{res_name}}", "value#{start_index + index}" end end ## # Path string for this segment # @return [String] def path_string type == :simple_resource_id ? "\#{#{resource_names[0]}}" : pattern.gsub("{", "\#{") end ## # A pattern template for this segment # @return [String] def pattern_template "*" end ## # Initialization helper to create a simple resource without a pattern # @param name [String] resource name # @return [ResourceIdSegment] def self.create_simple name ResourceIdSegment.new :simple_resource_id, "{#{name}}", [name] end # @private def == other return false unless other.is_a? self.class (type == other.type && pattern == other.pattern && resource_names == other.resource_names && resource_patterns == other.resource_patterns) end end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
123 124 125 |
# File 'lib/gapic/path_pattern/segment.rb', line 123 def type @type end |
Class Method Details
.create_simple(name) ⇒ ResourceIdSegment
Initialization helper to create a simple resource without a pattern
201 202 203 |
# File 'lib/gapic/path_pattern/segment.rb', line 201 def self.create_simple name ResourceIdSegment.new :simple_resource_id, "{#{name}}", [name] end |
Instance Method Details
#arguments ⇒ Array<String>
Names of the segment's arguments
166 167 168 |
# File 'lib/gapic/path_pattern/segment.rb', line 166 def arguments resource_names end |
#expected_path_for_dummy_values(start_index) ⇒ String
Returns a segment's pattern filled with dummy values names of the values are generated starting from the index provided
175 176 177 178 179 180 181 |
# File 'lib/gapic/path_pattern/segment.rb', line 175 def expected_path_for_dummy_values start_index return "value#{start_index}" if type == :simple_resource_id resource_names.each_with_index.reduce pattern do |exp_path, (res_name, index)| exp_path.sub "{#{res_name}}", "value#{start_index + index}" end end |
#nontrivial_resource_pattern? ⇒ Boolean
Whether the segment provides a nontrivial resource pattern
152 153 154 |
# File 'lib/gapic/path_pattern/segment.rb', line 152 def nontrivial_resource_pattern? resource_patterns.any? { |res_pattern| !res_pattern.match?(/^\*+$/) } end |
#path_string ⇒ String
Path string for this segment
186 187 188 |
# File 'lib/gapic/path_pattern/segment.rb', line 186 def path_string type == :simple_resource_id ? "\#{#{resource_names[0]}}" : pattern.gsub("{", "\#{") end |
#pattern_template ⇒ String
A pattern template for this segment
193 194 195 |
# File 'lib/gapic/path_pattern/segment.rb', line 193 def pattern_template "*" end |
#positional? ⇒ Boolean
Whether the segment is positional
138 139 140 |
# File 'lib/gapic/path_pattern/segment.rb', line 138 def positional? false end |
#provides_arguments? ⇒ Boolean
Whether the segment provides arguments
159 160 161 |
# File 'lib/gapic/path_pattern/segment.rb', line 159 def provides_arguments? true end |
#resource_pattern? ⇒ Boolean
Whether the segment provides a resource pattern
145 146 147 |
# File 'lib/gapic/path_pattern/segment.rb', line 145 def resource_pattern? resource_patterns.any? end |