Skip to content

Commit

Permalink
+ Redis lib only loaded if the Redis backend is used
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Oct 26, 2011
1 parent b2ca60a commit a18fcc5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions server/lib/picky/backends/redis.rb
Expand Up @@ -9,7 +9,10 @@ class Redis < Backend
attr_reader :client

def initialize options = {}
require 'redis'
@client = options[:client] || ::Redis.new(:db => (options[:db] || 15))
rescue LoadError => e
warn_gem_missing 'redis', 'the Redis client'
end

# Returns an object that on #initial, #load returns an object that responds to:
Expand Down
2 changes: 1 addition & 1 deletion server/lib/picky/extensions/object.rb
Expand Up @@ -16,7 +16,7 @@ def exclaim text
# Puts a text that informs the user of a missing gem.
#
def warn_gem_missing gem_name, message
warn "#{gem_name} gem missing!\nTo use #{message}, you need to:\n 1. Add the following line to Gemfile:\n gem '#{gem_name}'\n 2. Then, run:\n bundle update\n"
warn "#{gem_name} gem missing!\nTo use #{message}, you need to:\n 1. Add the following line to Gemfile:\n gem '#{gem_name}'\n or\n require '#{gem_name}'\n for example on top of your app.rb/application.rb\n 2. Then, run:\n bundle update\n"
end

# Indents each line by <tt>amount=2</tt> spaces.
Expand Down
2 changes: 1 addition & 1 deletion server/spec/lib/extensions/object_spec.rb
Expand Up @@ -24,7 +24,7 @@

describe 'warn_gem_missing' do
it 'should warn right' do
object.should_receive(:warn).once.with "gnorf gem missing!\nTo use gnarble gnarf, you need to:\n 1. Add the following line to Gemfile:\n gem 'gnorf'\n 2. Then, run:\n bundle update\n"
object.should_receive(:warn).once.with "gnorf gem missing!\nTo use gnarble gnarf, you need to:\n 1. Add the following line to Gemfile:\n gem 'gnorf'\n or\n require 'gnorf'\n for example on top of your app.rb/application.rb\n 2. Then, run:\n bundle update\n"

object.warn_gem_missing 'gnorf', 'gnarble gnarf'
end
Expand Down
2 changes: 1 addition & 1 deletion server/spec/lib/sources/delicious_spec.rb
Expand Up @@ -19,7 +19,7 @@
@source.should_receive(:require).any_number_of_times.and_raise LoadError
end
it "warns & exits" do
@source.should_receive(:warn).once.with "www-delicious gem missing!\nTo use the delicious source, you need to:\n 1. Add the following line to Gemfile:\n gem 'www-delicious'\n 2. Then, run:\n bundle update\n"
@source.should_receive(:warn).once.with "www-delicious gem missing!\nTo use the delicious source, you need to:\n 1. Add the following line to Gemfile:\n gem 'www-delicious'\n or\n require 'www-delicious'\n for example on top of your app.rb/application.rb\n 2. Then, run:\n bundle update\n"
@source.should_receive(:exit).once.with 1

@source.check_gem
Expand Down
1 change: 1 addition & 0 deletions server/test_project/app/application.rb
@@ -1,5 +1,6 @@
# encoding: utf-8
#
require 'redis'
require File.expand_path '../logging', __FILE__

class ChangingItem
Expand Down

0 comments on commit a18fcc5

Please sign in to comment.