Module: Gitoe::Repo::Query

Included in:
RestfulRugged
Defined in:
lib/gitoe/repo/repo.rb

Overview

instance methods, enable querying of instances

Instance Method Summary collapse

Instance Method Details

#create(arg) ⇒ Object



15
16
17
18
19
# File 'lib/gitoe/repo/repo.rb', line 15

def create arg
  id  = instances[:by_id].size
  instances[:by_id][id] = self.new arg
  instances[:by_arg][arg] = id
end

#destroy(id) ⇒ Object

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/gitoe/repo/repo.rb', line 21

def destroy id
  raise NotImplementedError # TODO
end

#find(id) ⇒ Object



25
26
27
28
# File 'lib/gitoe/repo/repo.rb', line 25

def find id
  id = Integer(id) unless id.is_a? Integer
  instances[:by_id][id] or raise "repo not found"
end

#id_for(arg) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/gitoe/repo/repo.rb', line 30

def id_for arg
  existing = instances[:by_arg][arg]
  if existing
    existing
  else
    create arg
  end
end

#instancesObject



8
9
10
11
12
13
# File 'lib/gitoe/repo/repo.rb', line 8

def instances
  @instances ||= {
    :by_arg => {}, # arg => id
    :by_id  => {}, # id  => instance
  }
end