Class: Bike::Storage::Temp

Inherits:
Bike::Storage show all
Defined in:
lib/_storage/temp.rb

Overview

Author

Akira FUNAI

Copyright

Copyright © 2009 Akira FUNAI

Instance Attribute Summary

Attributes inherited from Bike::Storage

#sd

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Bike::Storage

#initialize, instance, #last, #navi, #order, #select

Constructor Details

This class inherits a constructor from Bike::Storage

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/_storage/temp.rb', line 8

def self.available?
  true
end

Instance Method Details

#build(v) ⇒ Object



21
22
23
24
# File 'lib/_storage/temp.rb', line 21

def build(v)
  @val = v
  self
end

#clearObject



26
27
28
29
# File 'lib/_storage/temp.rb', line 26

def clear
  @val = {}
  self
end

#delete(id) ⇒ Object



42
43
44
45
# File 'lib/_storage/temp.rb', line 42

def delete(id)
  @val.delete id
  id
end

#move(old_id, new_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/_storage/temp.rb', line 47

def move(old_id, new_id)
  rex = /\A#{old_id}/
  val.keys.each {|id|
    if id =~ rex
      to_id = id.sub(rex, new_id)
      @val[to_id] = @val.delete id
    end
  }
  new_id
end

#persistent?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/_storage/temp.rb', line 12

def persistent?
  false
end

#store(id, v, ext = :unused) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/_storage/temp.rb', line 31

def store(id, v, ext = :unused)
  if new_id?(id, v)
    old_id = id
    id = new_id v
    return if val[id] # duplicate id
    move(old_id, id) unless old_id == :new_id
  end
  val[id] = v
  id
end

#val(id = nil) ⇒ Object



16
17
18
19
# File 'lib/_storage/temp.rb', line 16

def val(id = nil)
  @val ||= {}
  id ? @val[id] : @val
end