Module: Sideload::Redis

Extended by:
Redis
Included in:
Redis
Defined in:
lib/sideload/redis.rb

Instance Method Summary collapse

Instance Method Details

#dbObject



9
10
11
# File 'lib/sideload/redis.rb', line 9

def db
  @redis || db!
end

#db!(**config) ⇒ Object



5
6
7
# File 'lib/sideload/redis.rb', line 5

def db!(**config)
  @redis = ::Redis.new(**config)
end

#delete(full_path, target) ⇒ Object



30
31
32
# File 'lib/sideload/redis.rb', line 30

def delete(full_path, target)
  db.del(File.join(full_path, target))
end

#read(path) ⇒ Object



13
14
15
16
17
# File 'lib/sideload/redis.rb', line 13

def read(path)
  return db.keys(path + "*").map do |key|
    [key.sub(path, ""), db.get(key)]
  end.to_h
end

#with(path, fname) {|path, fname| ... } ⇒ Object

Yields:

  • (path, fname)


19
20
21
# File 'lib/sideload/redis.rb', line 19

def with(path, fname)
  yield(path, fname)
end

#write(full_path, target, content) ⇒ Object



23
24
25
26
27
28
# File 'lib/sideload/redis.rb', line 23

def write(full_path, target, content)
  if block_given? && !yield(content)
    raise ValidationError.new(self, "#{full_path}/#{target}", content)
  end
  db.set(File.join(full_path, target), content)
end