Skip to content

Commit

Permalink
syntax fixes for 1.8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
elucid committed Sep 8, 2011
1 parent 1b8d685 commit c40394d
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ gemspec
group :development do
gem 'rake'
gem 'redcarpet'
gem 'yard', git: 'https://github.com/lsegal/yard.git'
gem 'yard', :git => 'https://github.com/lsegal/yard.git'
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ end
require 'yard'
YARD::Rake::YardocTask.new

task default: :spec
task :default => :spec
4 changes: 2 additions & 2 deletions boffin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Gem::Specification.new do |s|
s.summary = 'Hit tracking library for Ruby using Redis'
s.has_rdoc = 'yard'
s.rubyforge_project = 'boffin'
s.files = `git ls-files`.split(?\n)
s.test_files = `git ls-files -- spec/*`.split(?\n)
s.files = `git ls-files`.split(/\n/)
s.test_files = `git ls-files -- spec/*`.split(/\n/)
s.require_paths = ['lib']

s.add_dependency 'redis', '>= 2.2'
Expand Down
6 changes: 3 additions & 3 deletions lib/boffin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module Boffin

# The way Time should be formatted for each interval type
INTERVAL_FORMATS = {
hours: '%F-%H',
days: '%F',
months: '%Y-%m' }
:hours => '%F-%H',
:days => '%F',
:months => '%Y-%m' }

# Different interval types
INTERVAL_TYPES = INTERVAL_FORMATS.keys
Expand Down
8 changes: 4 additions & 4 deletions lib/boffin/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def multiunion(ks, weights, unit, size, opts = {})
weights.keys.each { |t| union(ks, t, unit, size, opts) }
keys = weights.keys.map { |t| ks.hits_union(t, unit, size) }
zfetch(ks.hits_union_multi(weights, unit, size), keys, {
weights: weights.values
:weights => weights.values
}.merge(opts))
end

Expand All @@ -194,8 +194,8 @@ def multiunion(ks, weights, unit, size, opts = {})
# @see #zrange
def zfetch(storkey, keys, opts = {})
zrangeopts = {
counts: opts.delete(:counts),
order: (opts.delete(:order) || :desc).to_sym }
:counts => opts.delete(:counts),
:order => (opts.delete(:order) || :desc).to_sym }
if redis.zcard(storkey) == 0
redis.zunionstore(storkey, keys, opts)
redis.expire(storkey, @config.cache_expire_secs)
Expand All @@ -213,7 +213,7 @@ def zfetch(storkey, keys, opts = {})
# option is `true` it returns an array of pairs where the first value is
# the member, and the second value is the member's score.
def zrange(key, opts)
args = [key, 0, -1, opts[:counts] ? { withscores: true } : {}]
args = [key, 0, -1, opts[:counts] ? { :withscores => true } : {}]
result = case opts[:order]
when :asc then redis.zrange(*args)
when :desc then redis.zrevrange(*args)
Expand Down
10 changes: 5 additions & 5 deletions lib/boffin/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module Utils

# Number of seconds for a single value of each unit
SECONDS_IN_UNIT = {
hours: SECONDS_IN_HOUR,
days: SECONDS_IN_DAY,
months: SECONDS_IN_MONTH
:hours => SECONDS_IN_HOUR,
:days => SECONDS_IN_DAY,
:months => SECONDS_IN_MONTH
}

module_function
Expand Down Expand Up @@ -157,14 +157,14 @@ def object_as_member(obj)
# @return [String] A string that can be used as a member in {Keyspace#hits}.
# @see #object_as_identifier
def object_as_session_identifier(obj)
object_as_identifier(obj, namespace: true)
object_as_identifier(obj, :namespace => true)
end

# @param [#as_member, #id, #to_s] obj
# @return [String] A string that can be used as part of a Redis key
# @see #object_as_identifier
def object_as_key(obj)
object_as_identifier(obj, encode: true)
object_as_identifier(obj, :encode => true)
end

end
Expand Down
4 changes: 2 additions & 2 deletions spec/boffin/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
end

it 'can be sent a hash' do
conf = Boffin::Config.new(namespace: 'hello')
conf = Boffin::Config.new(:namespace => 'hello')
conf.namespace.should == 'hello'
end
end

describe '#merge' do
it 'copies the existing instance' do
newconf = subject.merge(namespace: 'carsten')
newconf = subject.merge(:namespace => 'carsten')
newconf.namespace.should == 'carsten'
subject.namespace.should == 'boffin'
end
Expand Down
8 changes: 4 additions & 4 deletions spec/boffin/hit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
it 'stores hit data under the appropriate keys' do
Boffin::Hit.new(@tracker, :tests, @ditty, [nil, @user])
[:hours, :days, :months].each do |interval|
@tracker.top(:tests, interval => 1, counts: true).
@tracker.top(:tests, interval => 1, :counts => true).
should == [['1', 1]]
@tracker.top(:tests, interval => 1, counts: true, unique: true).
@tracker.top(:tests, interval => 1, :counts => true, :unique => true).
should == [['1', 1]]
end
@tracker.hit_count(:tests, @ditty).should == 1
Expand All @@ -29,9 +29,9 @@
Boffin::Hit.new(@tracker, :tests, @ditty, [nil, @user])
Boffin::Hit.new(@tracker, :tests, @ditty, [nil, @user])
[:hours, :days, :months].each do |interval|
@tracker.top(:tests, interval => 1, counts: true).
@tracker.top(:tests, interval => 1, :counts => true).
should == [['1', 2]]
@tracker.top(:tests, interval => 1, counts: true, unique: true).
@tracker.top(:tests, interval => 1, :counts => true, :unique => true).
should == [['1', 1]]
end
@tracker.hit_count_for_session_id(:tests, @ditty, @user).should == 2
Expand Down
2 changes: 1 addition & 1 deletion spec/boffin/keyspace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

describe '#hits_union_multi' do
specify do
@ks.hits_union_multi({ views: 1, likes: 3 }, :days, 5).
@ks.hits_union_multi({ :views => 1, :likes => 3 }, :days, 5).
should == 'b:mock_ditty:views_1_likes_3:hits:current.days_5'
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/boffin/trackable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
end

it 'delegates ::top_ids to the Tracker instance' do
MockTrackableInjected.top_ids(:views, days: 1).should == ['1']
MockTrackableInjected.top_ids(:views, :days => 1).should == ['1']
end

it 'delegates #hit_count to the Tracker instance' do
Expand Down
24 changes: 12 additions & 12 deletions spec/boffin/tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@

describe '#hit' do
it 'throws an error if the hit type is not in the list' do
-> { @tracker.hit(:view, @instance1) }.
lambda { @tracker.hit(:view, @instance1) }.
should raise_error Boffin::UndefinedHitTypeError
end
end

describe '#hit_count' do
it 'throws an error if the hit type is not in the list' do
-> { @tracker.hit_count(:view, @instance1) }.
lambda { @tracker.hit_count(:view, @instance1) }.
should raise_error Boffin::UndefinedHitTypeError
end

Expand All @@ -77,7 +77,7 @@

describe '#uhit_count' do
it 'throws an error if the hit type is not in the list' do
-> { @tracker.uhit_count(:view, @instance1) }.
lambda { @tracker.uhit_count(:view, @instance1) }.
should raise_error Boffin::UndefinedHitTypeError
end

Expand All @@ -92,7 +92,7 @@

describe '#hit_count_for_session_id' do
it 'throws an error if the hit type is not in the list' do
-> { @tracker.hit_count_for_session_id(:view, @instance1, 'sess.1') }.
lambda { @tracker.hit_count_for_session_id(:view, @instance1, 'sess.1') }.
should raise_error Boffin::UndefinedHitTypeError
end

Expand All @@ -107,32 +107,32 @@

describe '#top' do
it 'throws an error if passed hit type is invalid' do
-> { @tracker.top(:view, days: 3) }.
lambda { @tracker.top(:view, :days => 3) }.
should raise_error Boffin::UndefinedHitTypeError
end

it 'throws an error if passed weights with hit type that is invalid' do
-> { @tracker.top({ view: 1 }, days: 3) }.
lambda { @tracker.top({ :view => 1 }, :days => 3) }.
should raise_error Boffin::UndefinedHitTypeError
end

it 'returns ids ordered by hit counts of weighted totals' do
ids = @tracker.top({ views: 1, likes: 2 }, days: 3)
ids = @tracker.top({ :views => 1, :likes => 2 }, :days => 3)
ids.should == ['300', '200', '100']
end

it 'returns ids ordered by total counts of a specific hit type' do
ids = @tracker.top(:views, days: 3)
ids = @tracker.top(:views, :days => 3)
ids.should == ['300', '100', '200']
end

it 'returns ids in ascending order when passed { order: "asc" } as an option' do
ids = @tracker.top(:views, days: 3, order: 'asc')
ids = @tracker.top(:views, :days => 3, :order => 'asc')
ids.should == ['200', '100', '300']
end

it 'returns ids and counts when passed { counts: true } as an option' do
ids = @tracker.top(:views, days: 3, counts: true)
ids = @tracker.top(:views, :days => 3, :counts => true)
ids.should == [
['300', 12],
['100', 8],
Expand All @@ -141,7 +141,7 @@
end

it 'returns ids based on unique hit data when passed { unique: true } as an option' do
ids = @tracker.top(:views, days: 3, counts: true, unique: true)
ids = @tracker.top(:views, :days => 3, :counts => true, :unique => true)
ids.should == [
['300', 7],
['200', 5],
Expand All @@ -159,4 +159,4 @@
@tracker.keyspace(true).unique_namespace?.should be_true
end
end
end
end
28 changes: 14 additions & 14 deletions spec/boffin/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,42 @@
end

describe '::extract_time_unit' do
specify { subject.extract_time_unit(hours: 6).should == [:hours, 6] }
specify { subject.extract_time_unit(days: 2).should == [:days, 2] }
specify { subject.extract_time_unit(months: 3).should == [:months, 3] }
specify { subject.extract_time_unit(:hours => 6).should == [:hours, 6] }
specify { subject.extract_time_unit(:days => 2).should == [:days, 2] }
specify { subject.extract_time_unit(:months => 3).should == [:months, 3] }

it 'throws an error if no time unit pair exists in the hash' do
lambda { subject.extract_time_unit(fun: 'times') }.
lambda { subject.extract_time_unit(:fun => 'times') }.
should raise_error ArgumentError
end
end

describe '::time_ago' do
before { @time = Time.local(2011, 2, 15, 12) }

specify { subject.time_ago(@time, hours: 6).should == Time.local(2011, 2, 15, 6) }
specify { subject.time_ago(@time, days: 5).should == Time.local(2011, 2, 10, 12) }
specify { subject.time_ago(@time, months: 1).should == Time.local(2011, 1, 16, 12) } # A "month" is 30 days
specify { subject.time_ago(@time, :hours => 6).should == Time.local(2011, 2, 15, 6) }
specify { subject.time_ago(@time, :days => 5).should == Time.local(2011, 2, 10, 12) }
specify { subject.time_ago(@time, :months => 1).should == Time.local(2011, 1, 16, 12) } # A "month" is 30 days

it 'throws an error if no time unit pair exists in the hash' do
lambda { subject.time_ago(@time, fun: 'fail') }.
lambda { subject.time_ago(@time, :fun => 'fail') }.
should raise_error ArgumentError
end
end

describe '::time_ago_range' do
before { @time = Time.local(2011, 2, 15, 12) }

specify { subject.time_ago_range(@time, hours: 6).size.should == 6 }
specify { subject.time_ago_range(@time, months: 1).size.should == 1 }
specify { subject.time_ago_range(@time, :hours => 6).size.should == 6 }
specify { subject.time_ago_range(@time, :months => 1).size.should == 1 }

specify do
subject.time_ago_range(@time, days: 2).
subject.time_ago_range(@time, :days => 2).
should == [Time.local(2011, 2, 14, 12), Time.local(2011, 2, 15, 12)]
end

specify do
subject.time_ago_range(@time, days: 3).
subject.time_ago_range(@time, :days => 3).
should == [
Time.local(2011, 2, 13, 12),
Time.local(2011, 2, 14, 12),
Expand All @@ -88,13 +88,13 @@
end

it 'ranges from n days away upto @time' do
times = subject.time_ago_range(@time, days: 4)
times = subject.time_ago_range(@time, :days => 4)
times.first.should == Time.local(2011, 2, 12, 12)
times.last.should == @time
end

it 'throws an error if no time unit pair exists in the hash' do
lambda { subject.time_ago_range(@time, fun: 'crash') }.
lambda { subject.time_ago_range(@time, :fun => 'crash') }.
should raise_error ArgumentError
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/boffin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MockEmptyDitty < MockDitty; end
end

it 'accepts a hash' do
Boffin.config(namespace: 'trendy')
Boffin.config(:namespace => 'trendy')
Boffin.config.namespace.should == 'trendy'
end

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$redis = if ENV['DEBUG']
require 'logger'
Redis.connect(logger: Logger.new(STDERR))
Redis.connect(:logger => Logger.new(STDERR))
else
Redis.connect
end
Expand Down

0 comments on commit c40394d

Please sign in to comment.