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
232 233 234 235 236 237 238 |
# File 'lib/seahorse/model/shapes.rb', line 232 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.
243 244 245 |
# File 'lib/seahorse/model/shapes.rb', line 243 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.
274 275 276 277 |
# File 'lib/seahorse/model/shapes.rb', line 274 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.
249 250 251 252 253 254 255 |
# File 'lib/seahorse/model/shapes.rb', line 249 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 225 226 227 228 |
# File 'lib/seahorse/model/shapes.rb', line 222 def payload_member if payload @payload_member ||= member(payload) else nil end end |