redis_monitor 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a8d5a1c405c057ecdd004a3311792975a2817e4
4
- data.tar.gz: b28d9a3b18b26bb9d0cf5f292e0ca5d8d2d533d7
3
+ metadata.gz: 6bfd5c7207c7570d9c7e902752ccd64f5630c965
4
+ data.tar.gz: 5292f747d52d970b75b61323bba55975d7cd1410
5
5
  SHA512:
6
- metadata.gz: fb4cfb34c575b90efc0b87164a20578b8bf30c5dac35bb3592dccd50a82a412adf416b2f3b65709e22a453ca50d5ff1b55726cdf468753529c42679a02ea0b17
7
- data.tar.gz: 84b833ac4f52990241ba7ca870def1dd25cf319d53a4bff0df73cc9e422bd2969a98a32eebcb0586dd2786d87c1b8b2ce9cb0d9f8cacab2884c8547376a05ff7
6
+ metadata.gz: 7483993062c4a562904bc4f61a52a64b013914657698c0a961781d00b9a6c2600d0dfca4e93b8d8c1dbefcfbff0c7a0e07987050aa01137a98356eb6ef9ae00f
7
+ data.tar.gz: 03987d561f9a6036afa897f0fed88f92f19ea5b3ddc71cdb9b4775e848c1be79c5691703abee25daff971b4d52c3da9c83dc1dbda750f596412868be446fbc02
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # RedisMonitor
2
2
 
3
- TODO: Write a gem description
4
-
5
3
  ## Installation
6
4
 
7
5
  Add this line to your application's Gemfile:
@@ -18,7 +16,13 @@ Or install it yourself as:
18
16
 
19
17
  ## Usage
20
18
 
21
- TODO: Write usage instructions here
19
+ $ redis_monitor --http-port http_port --host host --port port
20
+
21
+ Then browse http://localhost:http_port
22
+
23
+ For more information about the parameters:
24
+
25
+ $ redis_monitor --help
22
26
 
23
27
  ## Contributing
24
28
 
@@ -27,3 +31,7 @@ TODO: Write usage instructions here
27
31
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
32
  4. Push to the branch (`git push origin my-new-feature`)
29
33
  5. Create new Pull Request
34
+
35
+ Please write meaningful test, ff you need to execute them:
36
+
37
+ $ rspec spec
@@ -1,14 +1,31 @@
1
1
  require 'modules/backend'
2
+ require 'errors/errors'
2
3
 
3
4
  module RedisMonitor
4
5
  module Controllers
5
6
  class BaseController
6
7
  attr_accessor :context, :params
7
8
 
9
+ include RedisMonitor::Helpers::BaseHelper
10
+ include RedisMonitor::Helpers::LayoutsHelper
11
+
8
12
  def initialize(opts = {})
9
13
  @context = opts.delete(:context)
10
14
  @params = opts
11
15
  end
16
+
17
+ def execute(action)
18
+ begin
19
+ send(action)
20
+ rescue RedisMonitor::Errors::RedisNotAvailable
21
+ redis_not_available
22
+ end
23
+ end
24
+
25
+ def redis_not_available
26
+ haml 'errors/redis_not_available'.to_sym, layout: main_layout,
27
+ locals: {host: Backend.host, port: Backend.port}
28
+ end
12
29
  end
13
30
  end
14
31
  end
@@ -5,7 +5,7 @@ module RedisMonitor
5
5
  include RedisMonitor::Helpers::LayoutsHelper
6
6
 
7
7
  def index
8
- context.haml 'info/info'.to_sym, :layout => main_layout, :locals => {:info => Backend.info}
8
+ haml 'info/info'.to_sym, layout: main_layout, locals: {info: Backend.info}
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1 @@
1
+ require 'errors/redis_not_available'
@@ -0,0 +1,7 @@
1
+ module RedisMonitor
2
+ module Errors
3
+ class RedisNotAvailable < Exception
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module RedisMonitor
2
+ module Helpers
3
+ module BaseHelper
4
+ def haml(*arguments)
5
+ context.haml(*arguments)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,5 @@
1
1
  require 'redis'
2
+ require 'errors/errors'
2
3
 
3
4
  module RedisMonitor
4
5
  class Backend
@@ -7,8 +8,26 @@ module RedisMonitor
7
8
  @@port = arguments[:redis_port]
8
9
  end
9
10
 
11
+ def self.host
12
+ @@host
13
+ end
14
+
15
+ def self.port
16
+ @@port
17
+ end
18
+
19
+ def self.ensure_connected(redis)
20
+ begin
21
+ redis.ping
22
+ rescue Redis::CannotConnectError => e
23
+ raise RedisMonitor::Errors::RedisNotAvailable
24
+ end
25
+ end
26
+
10
27
  def self.redis
11
- Redis.new(:host => @@host, :port => @@port)
28
+ redis = Redis.new(:host => host, :port => port)
29
+ ensure_connected(redis)
30
+ redis
12
31
  end
13
32
 
14
33
  def self.info
@@ -1,8 +1,10 @@
1
+ require 'helpers/base_helper'
1
2
  require 'helpers/layouts_helper'
2
3
 
3
4
  module RedisMonitor
4
5
  module Helpers
5
6
  module AllHelpers
7
+ include BaseHelper
6
8
  include LayoutsHelper
7
9
  end
8
10
  end
@@ -7,7 +7,7 @@ module RedisMonitor
7
7
 
8
8
  def self.included(server)
9
9
  server.get('/'){ redirect '/info' }
10
- server.get('/info'){ InfoController.new(context: self).index }
10
+ server.get('/info'){ InfoController.new(context: self).execute(:index) }
11
11
  end
12
12
  end
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module RedisMonitor
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,3 +1,8 @@
1
1
  body {
2
2
  padding-top: 60px;
3
+ }
4
+
5
+ .message_centered {
6
+ text-align: center;
7
+ padding-top: 20%;
3
8
  }
@@ -0,0 +1,2 @@
1
+ .message_centered
2
+ Can't connect to a redis instance in host: #{host} and port: #{port}
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = %w(javiyu7@gmail.com)
11
11
  spec.description = %q{Get general information of a running redis instance}
12
12
  spec.summary = %q{Get general information of a running redis instance}
13
- spec.homepage = ''
13
+ spec.homepage = 'https://github.com/javiyu/redis_monitor'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe BaseController do
4
+ before :each do
5
+ @context = double(:context)
6
+ @controller = BaseController.new(context: @context)
7
+ end
8
+
9
+ describe 'execute method' do
10
+ it 'should not raise error if the action executed raised RedisNotAvailable' do
11
+ @controller.stub(:action) { raise RedisNotAvailable }
12
+ @controller.should_receive(:redis_not_available)
13
+ expect{ @controller.execute(:action) }.not_to raise_error
14
+ end
15
+ end
16
+
17
+ describe 'redis_not_available method' do
18
+ it 'should render redis not available error page' do
19
+ Backend.stub(:host)
20
+ Backend.stub(:port)
21
+ @context.should_receive(:haml).with('errors/redis_not_available'.to_sym, anything)
22
+ @controller.redis_not_available
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe InfoController do
4
+ before :each do
5
+ @context = double(:context)
6
+ @controller = InfoController.new(context: @context)
7
+ end
8
+
9
+ describe 'index action' do
10
+ before :each do
11
+ Backend.stub(:info){ {} }
12
+ end
13
+
14
+ it 'should not fail' do
15
+ @context.stub(:haml)
16
+ expect{ @controller.index }.not_to raise_error
17
+ end
18
+
19
+ it 'should render info page' do
20
+ @context.should_receive(:haml).with('info/info'.to_sym, anything)
21
+ @controller.index
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Backend do
4
+ before :each do
5
+ Backend.stub(:host)
6
+ Backend.stub(:port)
7
+ end
8
+
9
+ describe 'ensure_connected method' do
10
+ it 'should raise RedisNotAvailable if redis throws an exception' do
11
+ redis = double(:redis)
12
+ redis.stub(:ping){ raise Redis::CannotConnectError }
13
+ expect{ Backend.ensure_connected(redis) }.to raise_error RedisNotAvailable
14
+ end
15
+ end
16
+
17
+ describe 'redis method' do
18
+ it 'should call to ensure_connected' do
19
+ Backend.should_receive(:ensure_connected)
20
+ Backend.redis
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.order = 'random'
11
+ end
12
+
13
+ require 'modules/helpers'
14
+ require 'modules/controllers'
15
+ require 'modules/backend'
16
+
17
+ include RedisMonitor
18
+ include RedisMonitor::Controllers
19
+ include RedisMonitor::Errors
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Jimenez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-10 00:00:00.000000000 Z
11
+ date: 2013-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -117,6 +117,7 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - .gitignore
120
+ - .rspec
120
121
  - Gemfile
121
122
  - LICENSE.txt
122
123
  - README.md
@@ -124,6 +125,9 @@ files:
124
125
  - bin/redis_monitor
125
126
  - lib/controllers/base_controller.rb
126
127
  - lib/controllers/info_controller.rb
128
+ - lib/errors/errors.rb
129
+ - lib/errors/redis_not_available.rb
130
+ - lib/helpers/base_helper.rb
127
131
  - lib/helpers/layouts_helper.rb
128
132
  - lib/modules/backend.rb
129
133
  - lib/modules/controllers.rb
@@ -135,11 +139,15 @@ files:
135
139
  - lib/server/server.rb
136
140
  - lib/static/styles/bootstrap.min.css
137
141
  - lib/static/styles/custom.css
138
- - lib/views/algo.haml
142
+ - lib/views/errors/redis_not_available.haml
139
143
  - lib/views/info/info.haml
140
144
  - lib/views/layouts/main.haml
141
145
  - redis_monitor.gemspec
142
- homepage: ''
146
+ - spec/controllers/base_controller_spec.rb
147
+ - spec/controllers/info_controller_spec.rb
148
+ - spec/modules/backend_spec.rb
149
+ - spec/spec_helper.rb
150
+ homepage: https://github.com/javiyu/redis_monitor
143
151
  licenses:
144
152
  - MIT
145
153
  metadata: {}
@@ -163,4 +171,8 @@ rubygems_version: 2.0.6
163
171
  signing_key:
164
172
  specification_version: 4
165
173
  summary: Get general information of a running redis instance
166
- test_files: []
174
+ test_files:
175
+ - spec/controllers/base_controller_spec.rb
176
+ - spec/controllers/info_controller_spec.rb
177
+ - spec/modules/backend_spec.rb
178
+ - spec/spec_helper.rb
data/lib/views/algo.haml DELETED
@@ -1,45 +0,0 @@
1
- %table.table.table-striped
2
- %thead
3
- %tr
4
- %th
5
- Student
6
- %th
7
- First name
8
- %th
9
- Last name
10
- %th
11
- Grade
12
-
13
- %tbody
14
- %tr
15
- %td
16
- Example
17
- %td
18
- Example
19
- %td
20
- Example
21
- %td
22
- Example
23
-
24
- %tr
25
- %td
26
- Example
27
- %td
28
- Example
29
- %td
30
- Example
31
- %td
32
- Example
33
-
34
- %tr
35
- %td
36
- Example
37
- %td
38
- Example
39
- %td
40
- Example
41
- %td
42
- Example
43
-
44
-
45
- = info