Class: Bank::Result

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/bank/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(db, collection) ⇒ Result

Returns a new instance of Result.



16
17
18
19
# File 'lib/bank/result.rb', line 16

def initialize(db, collection)
  self.db = db
  self.collection = collection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &blk) ⇒ Object



38
39
40
# File 'lib/bank/result.rb', line 38

def method_missing(*args, &blk)
  DatasetMethods.include?(args[0]) ? new(db.send(*args, &blk)) : super
end

Instance Method Details

#allObject



29
30
31
# File 'lib/bank/result.rb', line 29

def all
  collection.convert(raw)
end

#each(&blk) ⇒ Object



21
22
23
# File 'lib/bank/result.rb', line 21

def each(&blk)
  raw.each { |result| blk.call(collection.convert(result)) }
end

#grep(*args, &block) ⇒ Object



36
# File 'lib/bank/result.rb', line 36

def grep(*args, &block)     new(db.grep(*args, &block)) end

#group_by(*args, &block) ⇒ Object



35
# File 'lib/bank/result.rb', line 35

def group_by(*args, &block) new(db.group_by(*args, &block)) end

#rawObject



25
26
27
# File 'lib/bank/result.rb', line 25

def raw
  db.all
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/bank/result.rb', line 42

def respond_to?(method)
  DatasetMethods.include?(method) || super
end

#select(*args, &block) ⇒ Object

db overrides for Enumerable-clashing methods



34
# File 'lib/bank/result.rb', line 34

def select(*args, &block)   new(db.select(*args, &block)) end