Module: Epiphy::Repository::Helper

Included in:
ClassMethods
Defined in:
lib/epiphy/repository/helper.rb

Overview

Give repository useful helper class to query data. Only support ‘find_by` at this moment.

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#find_by(**option) ⇒ Object

Find the first record matching the

Parameters:

  • Keyword

    argument [field_name: value]

Raises:

  • Epiphy::Model::EntityNotFound if not found

Since:

  • 0.2.0



17
18
19
20
21
22
23
24
25
26
# File 'lib/epiphy/repository/helper.rb', line 17

def find_by(**option)
  begin
    query do |r|
      r.filter(option).nth(0)
    end
  rescue RethinkDB::RqlRuntimeError => e
    #raise RethinkDB::RqlRuntimeError
    raise Epiphy::Model::EntityNotFound if e.message.include?("Index out of bounds")
  end
end