Class: Squad::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/squad.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource, ids) ⇒ Collection

Returns a new instance of Collection.



330
331
332
333
# File 'lib/squad.rb', line 330

def initialize(resource, ids)
  @resource = resource 
  @ids      = ids
end

Instance Method Details

#eachObject



335
336
337
338
339
340
341
342
343
344
# File 'lib/squad.rb', line 335

def each
  @ids.each { |id| @resource.redis.queue("HGETALL", @resource.key[id])}

  data = @resource.redis.commit
  return if data.nil?

  data.each_with_index do |atts, idx|
    yield @resource.reproduce(atts + ['id', @ids[idx]])
  end
end

#to_jsonObject



346
347
348
# File 'lib/squad.rb', line 346

def to_json
  JSON.dump(self.map { |e| e.to_hash })
end