Class: Jinx::ReferenceEnumerator
- Includes:
- Enumerable, Collection
- 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
#enumerate, #pp_s, #pretty_print, #pretty_print_cycle, #qp, #to_enum, #transitive_closure
Methods included from Collection
#compact, #compact_map, #detect_value, #detect_with_value, #difference, #empty?, #filter, #first, #flatten, #hashify, #intersect, #join, #last, #partial_sort, #partial_sort!, #partial_sort_by, #size, #to_compact_hash, #to_compact_hash_with_index, #to_series, #transform, #union
Constructor Details
#initialize(on = nil, properties = nil) ⇒ ReferenceEnumerator
Returns a new instance of ReferenceEnumerator.
25 26 27 28 |
# File 'lib/jinx/resource/reference_enumerator.rb', line 25 def initialize(on=nil, properties=nil) @subject = on @properties = properties end |
Instance Attribute Details
#property ⇒ <Property> (readonly)
Returns the current property.
21 22 23 |
# File 'lib/jinx/resource/reference_enumerator.rb', line 21 def property @property end |
#subject ⇒ Resource (readonly) Also known as: on, from
Returns the domain object containing the references.
14 15 16 |
# File 'lib/jinx/resource/reference_enumerator.rb', line 14 def subject @subject end |
Instance Method Details
#each {|obj, from, property| ... } ⇒ (Resource, Resource, Property)
Returns the (visited, visiting, property) tuples.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jinx/resource/reference_enumerator.rb', line 36 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 |