Class: Jinx::ReferenceEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/jinx/resource/reference_enumerator.rb
Overview
A ReferenceEnumerator iterates over domain property references.
Instance Attribute Summary collapse
-
#property ⇒ <Property>
readonly
The current property.
-
#subject ⇒ Resource
(also: #on, #from)
readonly
The domain object containing the references.
Instance Method Summary collapse
-
#each {|obj, from, property| ... } ⇒ (Resource, Resource, Property)
The (visited, visiting, property) tuples.
-
#initialize(on = nil, properties = nil) ⇒ ReferenceEnumerator
constructor
A new instance of ReferenceEnumerator.
Methods included from Enumerable
#collection?, #compact, #compact_map, #detect_value, #detect_with_value, #difference, #empty?, #enumerate, #filter, #first, #flatten, #hashify, #intersect, #join, #last, #partial_sort, #partial_sort_by, #pp_s, #pretty_print, #pretty_print_cycle, #qp, #size, #to_compact_hash, #to_compact_hash_with_index, #to_enum, #to_series, #transform, #transitive_closure, #union
Constructor Details
#initialize(on = nil, properties = nil) ⇒ ReferenceEnumerator
26 27 28 29 |
# File 'lib/jinx/resource/reference_enumerator.rb', line 26 def initialize(on=nil, properties=nil) @subject = on @properties = properties end |
Instance Attribute Details
#property ⇒ <Property> (readonly)
22 23 24 |
# File 'lib/jinx/resource/reference_enumerator.rb', line 22 def property @property end |
#subject ⇒ Resource (readonly) Also known as: on, from
15 16 17 |
# File 'lib/jinx/resource/reference_enumerator.rb', line 15 def subject @subject end |
Instance Method Details
#each {|obj, from, property| ... } ⇒ (Resource, Resource, Property)
Returns the (visited, visiting, property) tuples.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jinx/resource/reference_enumerator.rb', line 37 def each return if @subject.nil? @properties.enumerate do |prop| @property = prop # the reference(s) to visit refs = @subject.send(prop.attribute) # associate each reference to visit with the current visited attribute refs.enumerate { |ref| yield(ref) } end end |