Class: Bike::Storage::Sequel
Instance Attribute Summary
#sd
Class Method Summary
collapse
Instance Method Summary
collapse
instance, #last, #navi, #order, #persistent?, #select
Constructor Details
#initialize(sd) ⇒ Sequel
Returns a new instance of Sequel.
45
46
47
48
49
|
# File 'lib/_storage/sequel.rb', line 45
def initialize(sd)
super
@dataset = Bike::Storage::Sequel.db[:bike_main]
@dirname = @sd[:full_name]
end
|
Class Method Details
.available? ⇒ Boolean
41
42
43
|
# File 'lib/_storage/sequel.rb', line 41
def self.available?
self.db
end
|
.db ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/_storage/sequel.rb', line 13
def self.db
if Bike['storage']['Sequel'] && Bike['storage']['Sequel']['uri']
@db ||= ::Sequel.connect Bike['storage']['Sequel']['uri']
self.load_skel unless @db.table_exists? :bike_main
end
@db
end
|
.load_skel ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/_storage/sequel.rb', line 21
def self.load_skel
@db.create_table(:bike_main) {
String :full_name
String :ext
String :owner
String :body
File :binary_body
primary_key :full_name
} unless @db.table_exists? :bike_main
Bike::Storage::File.traverse('/', Bike['skin_dir']) {|entry|
@db[:bike_main].insert(
:full_name => entry[:full_name],
:ext => entry[:ext],
:owner => entry[:val]['_owner'],
:body => entry[:val].ya2yaml(:syck_compatible => true),
:binary_body => (entry[:ext] == 'yaml') ? nil : entry[:val].to_sequel_blob
) unless @db[:bike_main][:full_name => entry[:full_name]]
}
end
|
Instance Method Details
#build(v) ⇒ Object
63
64
65
66
67
|
# File 'lib/_storage/sequel.rb', line 63
def build(v)
clear
v.each {|id, v| store(id, v) } if v
self
end
|
#clear ⇒ Object
69
70
71
72
|
# File 'lib/_storage/sequel.rb', line 69
def clear
@dataset.grep(:full_name, _full_name('%')).delete
self
end
|
#delete(id) ⇒ Object
78
79
80
81
82
|
# File 'lib/_storage/sequel.rb', line 78
def delete(id)
@dataset.filter(_conds(id)).delete &&
@dataset.grep(:full_name, _full_name("#{id}-%")).and(~:ext => 'yaml').delete &&
id
end
|
#move(old_id, new_id) ⇒ Object
84
85
86
|
# File 'lib/_storage/sequel.rb', line 84
def move(old_id, new_id)
rename(old_id, new_id) && new_id
end
|
#store(id, v, ext = nil) ⇒ Object
74
75
76
|
# File 'lib/_storage/sequel.rb', line 74
def store(id, v, ext = nil)
save(id, v, ext)
end
|
#val(id = nil) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/_storage/sequel.rb', line 51
def val(id = nil)
if id
load id
else
_select_all({}).inject({}) {|v, id|
v[id] = load id
v
}
end
end
|