Class: Jinx::ReferenceEnumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jinx/resource/reference_enumerator.rb

Overview

A ReferenceEnumerator iterates over domain property references.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#subjectResource (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.

Yields:

  • (obj, from, property)

    operates on the visited domain object

Yield Parameters:

  • obj (Resource)

    the visited domain object

  • from (Resource)

    the visiting domain object

  • property (Property)

    the visiting property



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