Class: OsCtld::DB::PooledList
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from List
Instance Method Summary collapse
- #contains?(id, pool = nil) ⇒ Boolean
-
#each_by_ids(ids, pool = nil) {|object| ... } ⇒ Object
Iterate objects matching ids and pool.
-
#find(id, pool = nil) {|object| ... } ⇒ any
Find object by ‘id` and `pool`.
-
#select_by_ids(ids, pool = nil) {|object| ... } ⇒ Array
Select objects matching ids and pool.
Methods inherited from List
#add, #count, #each, #get, instance, #remove, #sync
Instance Method Details
#contains?(id, pool = nil) ⇒ Boolean
40 41 42 |
# File 'lib/osctld/db/pooled_list.rb', line 40 def contains?(id, pool = nil) !find(id, pool).nil? end |
#each_by_ids(ids, pool = nil) {|object| ... } ⇒ Object
Iterate objects matching ids and pool
75 76 77 78 79 80 81 82 |
# File 'lib/osctld/db/pooled_list.rb', line 75 def each_by_ids(ids, pool = nil) select_by_ids(ids, pool) do |obj| yield(obj) false end nil end |
#find(id, pool = nil) {|object| ... } ⇒ any
Find object by ‘id` and `pool`.
There are two ways to specify a pool:
- use the `pool` argument
- when `pool` is `nil` and `id` contains a colon, it is parsed as
`<pool>:<id>`
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/osctld/db/pooled_list.rb', line 24 def find(id, pool = nil, &block) obj_id = DB::ObjectId.new(id, pool) sync do obj = objects.detect { |v| obj_id.match?(v) } if block block.call(obj) else obj end end end |
#select_by_ids(ids, pool = nil) {|object| ... } ⇒ Array
Select objects matching ids and pool
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/osctld/db/pooled_list.rb', line 50 def select_by_ids(ids, pool = nil, &block) if ids.nil? return get.each(&block) if block return get end obj_ids = ids.map { |id| DB::ObjectId.new(id, pool) } get.select do |obj| next(false) if obj_ids.detect { |obj_id| obj_id.match?(obj) }.nil? if block block.call(obj) else true end end end |