Module: Subledger::Domain::Roles::Collectable::CollectableClass

Defined in:
lib/subledger/domain/roles/collectable.rb

Instance Method Summary collapse

Instance Method Details

#collect(args, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/subledger/domain/roles/collectable.rb', line 11

def collect args, &block
  limit = args[:limit] ||= 25 unless block_given?

  validate args

  store           = args[:store]
  client          = args[:client]
  anchor          = args[:anchor]
  action          = args[:action]
  collection_name =  CollectionName.with_state( args.
                                                  merge :klass => self )

  args[:collection_name] = collection_name

  unless anchor
    anchor = args[:anchor] = client.send collection_name, args

    anchor.read if [:preceding, :following].include? action
  end

  validate_criterion args

  if block_given?
    collect_with_block args, &block
  else
    store.collect args
  end
end