redis-shelf 0.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rack"
4
+ gem "redis"
5
+ gem "thin"
6
+ gem "haml"
data/LICENSE ADDED
File without changes
data/Manifest ADDED
@@ -0,0 +1,13 @@
1
+ Gemfile
2
+ LICENSE
3
+ Manifest
4
+ README.mdown
5
+ Rakefile
6
+ config.ru
7
+ config/redis.sample.yml
8
+ lib/rack/redis-shelf.rb
9
+ lib/redis-shelf/server.rb
10
+ public/css/style.css
11
+ public/style.css
12
+ redis-shelf.gemspec
13
+ views/show.haml
data/README.mdown ADDED
@@ -0,0 +1,22 @@
1
+ # Redis Shelf
2
+
3
+ A simple rack app to browse redis
4
+
5
+ ## Instructions
6
+
7
+ First install gems
8
+
9
+ # required:
10
+ bundle install
11
+
12
+ Start the server
13
+
14
+ rackup -s thin
15
+
16
+ Keys are browsed using "localhost:3000/this/is/a/key", which resolves to the redis key "this:is:a:key"
17
+
18
+
19
+ ## TODO:
20
+
21
+ * nicer interface (html)
22
+ * fix issue where webrick uses full request_uri
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rake'
2
+ require 'echoe'
3
+
4
+ path = File.expand_path("../lib", __FILE__)
5
+ $:.unshift(path) unless $:.include?(path)
6
+
7
+ Echoe.new('redis-shelf', '0.1.pre') do |p|
8
+ p.description = 'Redis key browser'
9
+ p.url = 'http://github.com/jhsu/redis-shelf'
10
+ p.author = 'Joseph Hsu'
11
+ p.email = 'jhsu@josephhsu.com'
12
+ end
@@ -0,0 +1,3 @@
1
+ host: localhost
2
+ port: 6379
3
+ db: 0
data/config.ru ADDED
@@ -0,0 +1,9 @@
1
+ #\ -s thin -p 9292
2
+
3
+ $LOAD_PATH.unshift ::File.expand_path(::File.dirname(__FILE__) + '/lib')
4
+ require 'redis-shelf/server'
5
+
6
+ use Rack::Static, :urls => ["/favicon"]
7
+ use Rack::Static, :urls => ["/css"], :root => "public"
8
+ app = Rack::RedisShelfServer.new(:host => "localhost", :port => 6379, :db => 7)
9
+ run app
@@ -0,0 +1,47 @@
1
+ require 'redis'
2
+
3
+ module Rack
4
+ class RedisShelf
5
+ F = ::File
6
+
7
+ attr_accessor :config
8
+
9
+ def initialize(conf={})
10
+ self.config = {:host => "localhost", :port => 6379, :db => 0}.merge(conf)
11
+ end
12
+
13
+ def connection
14
+ ::Redis.new(self.config)
15
+ end
16
+
17
+ def parse(key)
18
+ if key.empty?
19
+ ""
20
+ else
21
+ key.gsub(/^\/|\/$/,'').gsub(/[\s]+/,'').gsub('/',':')
22
+ end
23
+ end
24
+
25
+ def fetch(key)
26
+ key = parse(key)
27
+ if !key.empty?
28
+ case self.connection.type(key)
29
+ when "string" || "none"
30
+ connection.get(key) || ""
31
+ when "list"
32
+ connection.lrange(key, 0, -1)
33
+ else
34
+ ""
35
+ end
36
+ else
37
+ ""
38
+ end
39
+ end
40
+
41
+ def http_response(key)
42
+ value = fetch(key)
43
+ code = value ? 200 : 404
44
+ [value, code]
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ require 'haml'
2
+ require 'rack'
3
+
4
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '/rack/redis-shelf'))
5
+
6
+ module Rack
7
+ class RedisShelfServer
8
+ F = ::File
9
+ def initialize(conf={})
10
+ @shelf = RedisShelf.new(conf)
11
+ end
12
+
13
+ def call(env)
14
+ header = {"Content-Type" => "text/html"}
15
+ key = env["REQUEST_URI"]
16
+
17
+ key = @shelf.parse(key)
18
+ history(key)
19
+ values, code = @shelf.http_response(key)
20
+ content = render("show", :values => values, :key => key, :history => history, :redis => @shelf.connection)
21
+
22
+ [code, header, [content]]
23
+ end
24
+
25
+ def view_dir
26
+ F.expand_path(F.join(F.dirname(__FILE__), "..", "..", "/views" ))
27
+ end
28
+
29
+ def render(view, opts={})
30
+ ::Haml::Engine.new(F.read("#{view_dir}/#{view}.haml")).render(Object.new, opts)
31
+ end
32
+
33
+ def history(key=nil)
34
+ if key
35
+ @shelf.connection.lpush("history", key) unless key.empty?
36
+ else
37
+ @shelf.connection.lrange("history",0,10)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,11 @@
1
+ #history {
2
+ overflow: auto;
3
+ }
4
+
5
+ #history li {
6
+ float: left;
7
+ }
8
+
9
+ #history li a {
10
+ display: block;
11
+ }
data/public/style.css ADDED
@@ -0,0 +1,14 @@
1
+ #history {
2
+ overflow: auto;
3
+ margin: 0;
4
+ padding: 0;
5
+ }
6
+
7
+ #history li {
8
+ float: left;
9
+ }
10
+
11
+ #history li a {
12
+ display: block;
13
+ padding: 4px 8px;
14
+ }
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{redis-shelf}
5
+ s.version = "0.1.pre"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Joseph Hsu"]
9
+ s.date = %q{2010-07-28}
10
+ s.description = %q{Redis key browser}
11
+ s.email = %q{jhsu@josephhsu.com}
12
+ s.extra_rdoc_files = ["LICENSE", "README.mdown", "lib/rack/redis-shelf.rb", "lib/redis-shelf/server.rb"]
13
+ s.files = ["Gemfile", "LICENSE", "Manifest", "README.mdown", "Rakefile", "config.ru", "config/redis.sample.yml", "lib/rack/redis-shelf.rb", "lib/redis-shelf/server.rb", "public/css/style.css", "public/style.css", "redis-shelf.gemspec", "views/show.haml"]
14
+ s.homepage = %q{http://github.com/jhsu/redis-shelf}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Redis-shelf", "--main", "README.mdown"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{redis-shelf}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Redis key browser}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
data/views/show.haml ADDED
@@ -0,0 +1,23 @@
1
+ %html
2
+ %head
3
+ %link{:href => "/css/style.css", :rel => "stylesheet", :media => "screen"}
4
+
5
+ %body
6
+ %h2= key
7
+
8
+ %ul#history
9
+ - history.each do |key|
10
+ %li
11
+ %a{:href => "./#{key}"}= key
12
+
13
+
14
+ #values
15
+ - if values.is_a?(String)
16
+ = values
17
+ - else
18
+ %ul
19
+ - values.each do |value|
20
+ %li.value= value
21
+
22
+ #config
23
+ = "#{redis.client.host}:#{redis.client.port} db: #{redis.client.db}"
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-shelf
3
+ version: !ruby/object:Gem::Version
4
+ hash: -673414397
5
+ prerelease: true
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - pre
10
+ version: 0.1.pre
11
+ platform: ruby
12
+ authors:
13
+ - Joseph Hsu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-28 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Redis key browser
23
+ email: jhsu@josephhsu.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE
30
+ - README.mdown
31
+ - lib/rack/redis-shelf.rb
32
+ - lib/redis-shelf/server.rb
33
+ files:
34
+ - Gemfile
35
+ - LICENSE
36
+ - Manifest
37
+ - README.mdown
38
+ - Rakefile
39
+ - config.ru
40
+ - config/redis.sample.yml
41
+ - lib/rack/redis-shelf.rb
42
+ - lib/redis-shelf/server.rb
43
+ - public/css/style.css
44
+ - public/style.css
45
+ - redis-shelf.gemspec
46
+ - views/show.haml
47
+ has_rdoc: true
48
+ homepage: http://github.com/jhsu/redis-shelf
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --line-numbers
54
+ - --inline-source
55
+ - --title
56
+ - Redis-shelf
57
+ - --main
58
+ - README.mdown
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 11
76
+ segments:
77
+ - 1
78
+ - 2
79
+ version: "1.2"
80
+ requirements: []
81
+
82
+ rubyforge_project: redis-shelf
83
+ rubygems_version: 1.3.7
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Redis key browser
87
+ test_files: []
88
+