Class: Chassis::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/chassis/repo.rb,
lib/chassis/repo/delegation.rb,
lib/chassis/repo/record_map.rb

Defined Under Namespace

Modules: Delegation Classes: RecordMap

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



27
28
29
# File 'lib/chassis/repo.rb', line 27

def default
  @default ||= new
end

Instance Method Details

#find(klass, id) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
# File 'lib/chassis/repo.rb', line 32

def find(klass, id)
  raise ArgumentError, "id cannot be nil!" if id.nil?
  super
end

#query!(klass, selector) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chassis/repo.rb', line 45

def query!(klass, selector)
  result = query klass, selector
  no_results = result.respond_to?(:empty?) ? result.empty? : result.nil?

  if no_results && block_given?
    yield klass, selector
  elsif no_results
    fail NoQueryResultError, selector
  end

  result
end

#save(record) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/chassis/repo.rb', line 37

def save(record)
  if record.id
    update record
  else
    create record
  end
end