hit_counter 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.1.0
data/hit_counter.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hit_counter"
8
- s.version = "0.0.6"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roderick Monje"]
12
- s.date = "2011-09-19"
12
+ s.date = "2011-09-25"
13
13
  s.email = "rod@seologic.com"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
data/lib/hit_counter.rb CHANGED
@@ -46,14 +46,17 @@ class HitCounter
46
46
  # Class methods ==================================================================================
47
47
 
48
48
  # Returns a <code>HitCounter</code> matching the specified URL. The HitCounter is created if no
49
- # matching one is found.
49
+ # matching one is found. In the latter case, the hits argument specifies the starting count.
50
50
  #
51
51
  # * *Args*
52
52
  # - +url+ -> the URL for the site being counted
53
+ # - +hits+ -> the number of hits to start with
53
54
  # * *Returns*
54
55
  # - the site's HitCounter
55
- def self.get url
56
- self.find_or_create_by :url => HitCounter.normalize_url(url)
56
+ def self.get url, hits = 0
57
+ args = {:url => HitCounter.normalize_url(url)}
58
+ args[:hits] = hits unless HitCounter.exists? :conditions => args
59
+ self.find_or_create_by args
57
60
  end
58
61
 
59
62
  # Instance methods: Overrides ====================================================================
@@ -11,6 +11,12 @@ describe HitCounter do
11
11
  describe 'document count' do
12
12
  specify { HitCounter.count.should == 1 }
13
13
  end
14
+
15
+ context 'with starting count 10' do
16
+ describe 'hits' do
17
+ specify { HitCounter.get(@hit_counter.url, 10).hits.should == 0 }
18
+ end
19
+ end
14
20
  end
15
21
 
16
22
  context 'when new URL' do
@@ -19,6 +25,12 @@ describe HitCounter do
19
25
  describe 'document count' do
20
26
  specify { HitCounter.count.should == 2 }
21
27
  end
28
+
29
+ context 'with starting count 10' do
30
+ describe 'hits' do
31
+ specify { HitCounter.get('www.nytimes.com', 10).hits.should == 10 }
32
+ end
33
+ end
22
34
  end
23
35
  end
24
36
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hit_counter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 6
10
- version: 0.0.6
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roderick Monje
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-19 00:00:00 Z
18
+ date: 2011-09-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: addressable