Class: Squad::Collection
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(resource, ids) ⇒ Collection
constructor
A new instance of Collection.
- #to_json ⇒ Object
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
#each ⇒ Object
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_json ⇒ Object
346 347 348 |
# File 'lib/squad.rb', line 346 def to_json JSON.dump(self.map { |e| e.to_hash }) end |