Method: ObjectLoader.load_blocks

Defined in:
lib/object_loader/object_loader.rb

.load_blocks(path) {|pending_object| ... } ⇒ PendingObject

Loads all object blocks from a specific path.

Parameters:

  • path (String)

    The path to load all object blocks from.

Yields:

  • (pending_object)

Returns:

  • (PendingObject)

    The pending object which contains the blocks.

Since:

  • 1.0.0



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/object_loader/object_loader.rb', line 94

def ObjectLoader.load_blocks(path)
  path = File.expand_path(path)

  unless File.file?(path)
    raise(ObjectNotFound,"#{path.dump} doest not exist",caller)
  end

  # prevent circular loading of objects
  unless is_pending?
    # push on the new pending object
    queue.unshift(PendingObject.new(path))

    begin
      load(path)
    rescue Exception => e
      # if any error is encountered, pop off the object
      queue.shift
      raise(e)
    end
  end

  # pop off and return the pending object
  pending_object = queue.shift

  yield pending_object if block_given?
  return pending_object
end