Class: DefaultRepository

Inherits:
Object
  • Object
show all
Defined in:
app/repositories/default_repository.rb

Direct Known Subclasses

GamesRepository, ItemsRepository, StatsRepository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ DefaultRepository

Returns a new instance of DefaultRepository


4
5
6
# File 'app/repositories/default_repository.rb', line 4

def initialize(klass)
  @klass = klass
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass


2
3
4
# File 'app/repositories/default_repository.rb', line 2

def klass
  @klass
end

Instance Method Details

#allObject


8
9
10
# File 'app/repositories/default_repository.rb', line 8

def all
  klass.all
end

#create(attributes = {}) ⇒ Object


16
17
18
# File 'app/repositories/default_repository.rb', line 16

def create(attributes = {})
  klass.create(attributes)
end

#find(attributes) ⇒ Object


24
25
26
# File 'app/repositories/default_repository.rb', line 24

def find(attributes)
  find_all(attributes).first
end

#find_all(attributes) ⇒ Object


20
21
22
# File 'app/repositories/default_repository.rb', line 20

def find_all(attributes)
  klass.where(attributes)
end

#find_or_initialize(attributes) ⇒ Object


28
29
30
# File 'app/repositories/default_repository.rb', line 28

def find_or_initialize(attributes)
  find_all(attributes).first_or_initialize
end

#new(attributes = {}) ⇒ Object


12
13
14
# File 'app/repositories/default_repository.rb', line 12

def new(attributes = {})
  klass.new(attributes)
end