popular_stream 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6df6ce9f9726447977830802fe8a7e6f15cb8c00
4
- data.tar.gz: 72253cc504abd85e4893ce25ac9d1310c3b5ddc3
3
+ metadata.gz: 708930f3a23948e3ddeaa0ead9859fd297b5c8bf
4
+ data.tar.gz: 330abf086c97cb67dd827abec0fe79de154b69d5
5
5
  SHA512:
6
- metadata.gz: 3952dc948f1bef9002534db2d36891ad893e05ad5b790d49b6ab27b08e2cb90a217f8c09310c553f057617a99456f00dca7250d39946fd3c6de3ec410baf2b60
7
- data.tar.gz: 5e7cdca746f55e2922ecdaec2ee25e06b1120562bf78222a86983c3c3f0e77221f9b2cce34226f051de3b42b952af032ddd35bba8c22458488032da9dadc01bc
6
+ metadata.gz: 55cfa96f06fb25393f8265791921adc196a707939f6ec6bd66e6616f296d897baf08455a71a154a7f74f883a63152f185fb5970c660af8ee4086f7289716e10c
7
+ data.tar.gz: 0385c246417bf059cda48f3982c4fcc5c1e67936d9d0f69747f20ee8d60d2a4b2f39a5d46829ba0f95dd8174e380c202e6ef1f854df855f75f8e479fac993b43
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ ; EditorConfig is awesome: http://EditorConfig.org
2
+
3
+ ; top-most EditorConfig file
4
+ root = true
5
+
6
+ ; Unix-style newlines with a newline ending every file
7
+ [*]
8
+ indent_style = space
9
+ end_of_line = lf
10
+ insert_final_newline = true
11
+ trim_trailing_whitespace = true
12
+ charset = "utf-8"
13
+
14
+ [*.{yml,rb,rake,coffee,scss,css,ru}]
15
+ indent_style = space
16
+ indent_size = 2
17
+
18
+ [Rakefile]
19
+ indent_style = space
20
+ indent_size = 2
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.1.5
5
+
6
+ script: "bundle exec rake"
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Version 1.1 (Nov. 30, 2014)
2
+
3
+ * Adding ability to get the scores with the results. This will be the default
4
+ in V 2.0.0
5
+
6
+ # Version 1.0 (Nov. 29, 2014)
7
+
8
+ * Extracting code from We Heart It and making it a gem.
9
+
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Popular Stream
2
2
 
3
- # THIS IS NOT READY YET!
3
+ [![Build Status](https://travis-ci.org/nhocki/popular_streams.svg?branch=master)](https://travis-ci.org/nhocki/popular_streams)
4
4
 
5
5
  Simple popular content tracker with a Redis backend.
6
6
 
7
- Mostly taken from the "Popular Stream" code
8
- [here](http://stdout.heyzap.com/2013/04/08/surfacing-interesting-content/) but
9
- bundled up as a gem.
7
+ Mostly taken from the "Popular Stream" code found in the
8
+ [Surfacing Interesting Content](http://stdout.heyzap.com/2013/04/08/surfacing-interesting-content/)
9
+ post but bundled up as a gem.
10
10
 
11
11
  PopularStream tracks an "event" on a group of "fields" and returns the ones that
12
12
  are currently popular.
@@ -18,6 +18,8 @@ The way this works is that "old" votes will count less than newer votes, that wa
18
18
  a tag that was used 20 times today will be more popular than a tag used 30 times
19
19
  last week.
20
20
 
21
+ Once again, thanks to Micah Fivecoate for his post.
22
+
21
23
  ## Installation
22
24
 
23
25
  Add this line to your application's Gemfile:
@@ -34,6 +36,8 @@ Or install it yourself as:
34
36
 
35
37
  $ gem install popular_stream
36
38
 
39
+ This gems requires **Ruby 2.1**.
40
+
37
41
  ## Usage
38
42
 
39
43
  There are two main methods `vote` and `get`. `vote` adds an event to the list
@@ -57,6 +61,9 @@ stream.get # => ['rubygems', 'ruby']
57
61
  # You can pass `limit` and `offset`
58
62
  stream.get(limit: 1, offset: 1) # => ['ruby']
59
63
  stream.get(offset: 10) # => []
64
+
65
+ # You can ask to get the scores as well
66
+ stream.get(with_scores: true) # => [['ruby', 0.00001]]
60
67
  ```
61
68
 
62
69
  ## Seting up & Configuring Redis
@@ -84,3 +91,6 @@ them as needed.
84
91
  3. Commit your changes (`git commit -am 'Add some feature'`)
85
92
  4. Push to the branch (`git push origin my-new-feature`)
86
93
  5. Create a new Pull Request
94
+
95
+ If you're gonna open a Pull Request, please install [EditorConfig](http://editorconfig.org/),
96
+ it will keep most of the basic code styling consistent.
@@ -1,3 +1,3 @@
1
1
  class PopularStream
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -32,8 +32,8 @@ class PopularStream
32
32
  trim
33
33
  end
34
34
 
35
- def get(limit: 20, offset: 0)
36
- redis.zrevrange(name, offset, offset + limit - 1)
35
+ def get(limit: 20, offset: 0, **options)
36
+ redis.zrevrange(name, offset, offset + limit - 1, options)
37
37
  end
38
38
 
39
39
  def clear!
@@ -18,11 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = '~> 2.1'
22
+ spec.add_dependency "redis", "~> 3.1.0"
23
+
21
24
  spec.add_development_dependency "bundler", "~> 1.7"
22
25
  spec.add_development_dependency "rake", "~> 10.0"
23
26
  spec.add_development_dependency "rspec", "~> 3.1.0"
24
27
  spec.add_development_dependency "timecop", "~> 0.7.1"
25
28
  spec.add_development_dependency "fakeredis", "~> 0.5.0"
26
-
27
- spec.add_dependency "redis", "~> 3.1.0"
28
29
  end
@@ -4,6 +4,12 @@ RSpec.describe PopularStream do
4
4
  let(:one_week) { 60 * 60 * 24 * 7 } # 1 week in seconds.
5
5
  let(:stream) { PopularStream.new("popular_stream") }
6
6
 
7
+ # Make a new "Redis" for each test to not leak the doubles.
8
+ before do
9
+ PopularStream.redis = Redis.new
10
+ stream.clear!
11
+ end
12
+
7
13
  describe ".redis" do
8
14
  let(:redis) { double }
9
15
 
@@ -33,41 +39,52 @@ RSpec.describe PopularStream do
33
39
  expect(stream.get(limit: 1, offset: 1)).to eql([ '2' ])
34
40
  expect(stream.get(limit: 1, offset: 2)).to eql([ '1' ])
35
41
  end
36
- end
37
42
 
38
- it "ranks most popular for same time as higher" do
39
- Timecop.freeze do
40
- stream.vote(field: '1')
41
- stream.vote(field: '1')
42
- stream.vote(field: '2')
43
- expect(stream.get).to eql(['1', '2'])
43
+ it "is possible to get the scores if an option is passed" do
44
+ results = stream.get(with_scores: true)
45
+ results.each do |result|
46
+ expect(result).to be_a(Array)
47
+ expect(result.size).to eql(2)
48
+ end
44
49
  end
45
50
  end
46
51
 
47
- it "accepts a weight for the vote of a specific field" do
48
- Timecop.freeze do
49
- stream.vote(field: '1')
50
- stream.vote(field: '1')
51
- stream.vote(field: '2', weight: 3)
52
- expect(stream.get).to eql(['2', '1'])
52
+ describe "#vote" do
53
+ it "ranks most popular for same time as higher" do
54
+ Timecop.freeze do
55
+ stream.vote(field: '1')
56
+ stream.vote(field: '1')
57
+ stream.vote(field: '2')
58
+ expect(stream.get).to eql(['1', '2'])
59
+ end
53
60
  end
54
- end
55
61
 
56
- it "keeps old votes with lower weight on values" do
57
- Timecop.freeze do
58
- stream.vote(field: '1', time: Time.now - 2 * one_week)
59
- stream.vote(field: '2', time: Time.now - 3 * one_week)
62
+ it "accepts a weight for the vote of a specific field" do
63
+ Timecop.freeze do
64
+ stream.vote(field: '1')
65
+ stream.vote(field: '1')
66
+ stream.vote(field: '2', weight: 3)
67
+ expect(stream.get).to eql(['2', '1'])
68
+ end
69
+ end
60
70
 
61
- stream.vote(field: '1')
62
- stream.vote(field: '2')
71
+ it "keeps old votes with lower weight on values" do
72
+ Timecop.freeze do
73
+ stream.vote(field: '1', time: Time.now - 2 * one_week)
74
+ stream.vote(field: '2', time: Time.now - 3 * one_week)
75
+
76
+ stream.vote(field: '1')
77
+ stream.vote(field: '2')
78
+ end
79
+ expect(stream.get).to eql(['1', '2'])
63
80
  end
64
- expect(stream.get).to eql(['1', '2'])
65
81
  end
66
82
 
67
83
  it "#count gets the number of elements and #clear! removes them all" do
68
84
  stream.vote(field: '1')
69
85
  stream.vote(field: '1')
70
86
  expect(stream.count).to eql(1)
87
+
71
88
  stream.clear!
72
89
  expect(stream.count).to eql(0)
73
90
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popular_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolás Hock Isaza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +94,6 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: 0.5.0
83
- - !ruby/object:Gem::Dependency
84
- name: redis
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 3.1.0
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 3.1.0
97
97
  description: Ruby gem to track popular streams with a redis backend.
98
98
  email:
99
99
  - nhocki@gmail.com
@@ -101,8 +101,11 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".editorconfig"
104
105
  - ".gitignore"
105
106
  - ".rspec"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
106
109
  - Gemfile
107
110
  - LICENSE.txt
108
111
  - README.md
@@ -122,9 +125,9 @@ require_paths:
122
125
  - lib
123
126
  required_ruby_version: !ruby/object:Gem::Requirement
124
127
  requirements:
125
- - - ">="
128
+ - - "~>"
126
129
  - !ruby/object:Gem::Version
127
- version: '0'
130
+ version: '2.1'
128
131
  required_rubygems_version: !ruby/object:Gem::Requirement
129
132
  requirements:
130
133
  - - ">="