Class: Seahorse::Model::Shapes::Structure
- Defined in:
- lib/seahorse/model/shapes.rb
Instance Attribute Summary collapse
-
#member_names ⇒ Array<Symbol>
readonly
Returns a list of members names.
-
#payload ⇒ String?
readonly
Returns the name of the payload member if set.
-
#required ⇒ Array<Symbol>
readonly
Returns a list of required members names.
Attributes inherited from Shape
#definition, #documentation, #location, #location_name, #name, #shape_map, #type
Instance Method Summary collapse
-
#initialize(definition, options = {}) ⇒ Structure
constructor
A new instance of Structure.
- #member(name) ⇒ Shape
-
#member?(name) ⇒ Boolean
Returns ‘true` if this structure has a member with the given name.
-
#member_by_location_name(location_name) ⇒ Array<Symbol,Shape>?
Searches the structure members for a shape with the given serialized name.
-
#members ⇒ Enumerable<Symbol,Shape>
Returns an enumerator that yields member names and shapes.
- #payload_member ⇒ Shape?
Methods inherited from Shape
#inspect, #metadata, new, #with
Constructor Details
#initialize(definition, options = {}) ⇒ Structure
Returns a new instance of Structure.
202 203 204 205 206 207 208 209 210 |
# File 'lib/seahorse/model/shapes.rb', line 202 def initialize(definition, = {}) super @members = {} @member_refs = {} @member_names = {} compute_member_names compute_required_member_names @member_names = @member_names.values end |
Instance Attribute Details
#member_names ⇒ Array<Symbol> (readonly)
Returns a list of members names.
213 214 215 |
# File 'lib/seahorse/model/shapes.rb', line 213 def member_names @member_names end |
#payload ⇒ String? (readonly)
Returns the name of the payload member if set.
219 220 221 |
# File 'lib/seahorse/model/shapes.rb', line 219 def payload @payload end |
#required ⇒ Array<Symbol> (readonly)
Returns a list of required members names.
216 217 218 |
# File 'lib/seahorse/model/shapes.rb', line 216 def required @required end |
Instance Method Details
#member(name) ⇒ Shape
228 229 230 231 232 233 234 |
# File 'lib/seahorse/model/shapes.rb', line 228 def member(name) if ref = @member_refs[name.to_sym] @members[name] ||= shape_for(ref) else raise ArgumentError, "no such member :#{name}" end end |
#member?(name) ⇒ Boolean
Returns ‘true` if this structure has a member with the given name.
239 240 241 |
# File 'lib/seahorse/model/shapes.rb', line 239 def member?(name) @member_refs.key?(name.to_sym) end |
#member_by_location_name(location_name) ⇒ Array<Symbol,Shape>?
Searches the structure members for a shape with the given serialized name.
If found, the shape will be returned with its symbolized member name.
If no shape is found with the given serialized name, then nil is returned.
270 271 272 273 |
# File 'lib/seahorse/model/shapes.rb', line 270 def member_by_location_name(location_name) @by_location_name ||= index_members_by_location_name @by_location_name[location_name] end |
#members ⇒ Enumerable<Symbol,Shape>
Returns an enumerator that yields member names and shapes.
245 246 247 248 249 250 251 |
# File 'lib/seahorse/model/shapes.rb', line 245 def members Enumerator.new do |y| member_names.map do |member_name| y.yield(member_name, member(member_name)) end end end |
#payload_member ⇒ Shape?
222 223 224 |
# File 'lib/seahorse/model/shapes.rb', line 222 def payload_member @payload_member ||= member(payload) end |