Class: ActiveTriples::ParentStrategy::Ancestors

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_triples/persistence_strategies/parent_strategy.rb

Overview

An enumerable over the ancestors of an resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Ancestors

Returns a new instance of Ancestors.

Parameters:



145
146
147
# File 'lib/active_triples/persistence_strategies/parent_strategy.rb', line 145

def initialize(source)
  @source = source
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



141
142
143
# File 'lib/active_triples/persistence_strategies/parent_strategy.rb', line 141

def source
  @source
end

Instance Method Details

#each {|RDFSource| ... } ⇒ Enumerator<RDFSource>

Yields:

  • (RDFSource)

    gives each ancestor to the block

Returns:

Raises:



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/active_triples/persistence_strategies/parent_strategy.rb', line 154

def each
  raise NilParentError if 
    !source.persistence_strategy.respond_to?(:parent) || 
    source.persistence_strategy.parent.nil?
  
  current = source.persistence_strategy.parent
  
  if block_given?
    loop do
      yield current
      
      break unless (current.persistence_strategy.respond_to?(:parent) && 
                    current.persistence_strategy.parent)
      break if current.persistence_strategy.parent == current

      current = current.persistence_strategy.parent
    end
  end
  to_enum
end