acts_as_sweepable 0.1.1 → 0.1.2

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.
data/CHANGELOG.rdoc CHANGED
@@ -1,2 +1,4 @@
1
+ = Version 0.1.2
2
+ * Switched to convenient method declaration
1
3
  = Version 0.1.0
2
4
  * Gem existence started
data/README.md CHANGED
@@ -15,23 +15,23 @@ Adds a class method called sweep to ActiveRecord - used to remove old elements.
15
15
  ## Example
16
16
 
17
17
  # Will remove elements older than 10 days
18
- MyClass.sweep('10d')
18
+ MyClass.sweep(:time => '10d')
19
19
 
20
20
  # Will remove elements older than 10 hours
21
- MyClass.sweep('10h')
21
+ MyClass.sweep(:time => '10h')
22
22
 
23
23
  # Will remove elements older than 10 minutes
24
- MyClass.sweep('10m')
24
+ MyClass.sweep(:time => '10m')
25
25
 
26
26
  Params accepted by this method:
27
27
 
28
- * `time_ago` - d(days),h(hours), m(minutes)
28
+ * `time` - d(days),h(hours), m(minutes)
29
29
  * `conditions` - additional SQL conditions (like WHERE)
30
- * `created_or_updated` - (default true) - should it use updated_at and created_at to determine if object is old enough or should it use just created_at.
30
+ * `active` - (default true) - should it use updated_at and created_at to determine if object is old enough or should it use just created_at.
31
31
 
32
32
  You can also yield a block of code - it will be performed on every object that should be deleted:
33
33
 
34
- MyClass.sweep('10d') do |el|
34
+ MyClass.sweep(:time => '10d') do |el|
35
35
  el.do_smhtng
36
36
  end
37
37
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('acts_as_sweepable', '0.1.1') do |p|
5
+ Echoe.new('acts_as_sweepable', '0.1.2') do |p|
6
6
  p.description = "Adds a class method called sweep to ActiveRecord - used to remove old elements"
7
7
  p.url = "https://github.com/mensfeld/Acts-as-Sweepable"
8
8
  p.author = "Maciej Mensfeld"
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{acts_as_sweepable}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Maciej Mensfeld"]
9
9
  s.cert_chain = ["/home/mencio/.cert_keys/gem-public_cert.pem"]
10
- s.date = %q{2011-04-17}
10
+ s.date = %q{2011-04-23}
11
11
  s.description = %q{Adds a class method called sweep to ActiveRecord - used to remove old elements}
12
12
  s.email = %q{maciej@mensfeld.pl}
13
13
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md", "lib/acts_as_sweepable.rb"]
@@ -7,7 +7,15 @@ module Acts
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def sweep(time_ago = nil, conditions = nil, created_or_updated = true)
10
+ def sweep(*sources)
11
+ # time_ago = nil, conditions = nil, created_or_updated = true
12
+ options = sources.extract_options!.stringify_keys
13
+
14
+ time_ago = options.delete("time")
15
+ conditions = options.delete("conditions")
16
+ created_or_updated = options.delete("active")
17
+ created_or_updated = true if created_or_updated.nil?
18
+
11
19
  time = case time_ago
12
20
  when /^(\d+)m$/ then Time.now - $1.to_i.minute
13
21
  when /^(\d+)h$/ then Time.now - $1.to_i.hour
@@ -29,10 +37,10 @@ module Acts
29
37
  # Run on each block of code
30
38
  els.each {|el| yield el } if block_given?
31
39
 
32
- self.delete_all "#{statement} #{conditions}"
40
+ self.destroy_all "#{statement} #{conditions}"
33
41
  end
34
42
  end
35
-
43
+
36
44
  end
37
45
  end
38
46
 
@@ -13,19 +13,19 @@ describe CoolElement do
13
13
  context "when object is old enough" do
14
14
  it "should be sweeped" do
15
15
  el = subject.create(:created_at => 10.days.ago)
16
- subject.sweep('9d')
16
+ subject.sweep(:time => '9d')
17
17
  subject.all.count.should eql(0)
18
18
  el = subject.create(:created_at => 10.hours.ago)
19
- subject.sweep('9h')
19
+ subject.sweep(:time => '9h')
20
20
  subject.all.count.should eql(0)
21
21
  el = subject.create(:created_at => 10.minutes.ago)
22
- subject.sweep('9m')
22
+ subject.sweep(:time => '9m')
23
23
  subject.all.count.should eql(0)
24
24
  el = subject.create(:created_at => 10.minutes.ago, :updated_at => 1.minutes.ago)
25
- subject.sweep('9m')
25
+ subject.sweep(:time => '9m')
26
26
  subject.all.count.should eql(0)
27
27
  el = subject.create(:created_at => 1.minutes.ago, :updated_at => 10.minutes.ago)
28
- subject.sweep('9m')
28
+ subject.sweep(:time => '9m')
29
29
  subject.all.count.should eql(0)
30
30
  end
31
31
  end
@@ -33,13 +33,13 @@ describe CoolElement do
33
33
  context "when object is not old enough" do
34
34
  it "should not be sweeped" do
35
35
  el = subject.create(:created_at => 10.days.ago)
36
- subject.sweep('11d')
36
+ subject.sweep(:time => '11d')
37
37
  subject.all.count.should eql(1)
38
38
  el = subject.create(:created_at => 10.minutes.ago)
39
- subject.sweep('11m')
39
+ subject.sweep(:time => '11m')
40
40
  subject.all.count.should eql(1)
41
41
  el = subject.create(:created_at => 10.hours.ago)
42
- subject.sweep('11h')
42
+ subject.sweep(:time => '11h')
43
43
  subject.all.count.should eql(2)
44
44
  end
45
45
  end
@@ -48,7 +48,7 @@ describe CoolElement do
48
48
  it "should be used" do
49
49
  el1 = subject.create(:created_at => 10.days.ago, :name => 'First')
50
50
  el2 = subject.create(:created_at => 10.days.ago, :name => 'Second')
51
- subject.sweep('9d', 'name LIKE "Second"')
51
+ subject.sweep(:time => '9d', :conditions => 'name LIKE "Second"')
52
52
  subject.all.count.should eql(1)
53
53
  subject.all.first.name.should eql "First"
54
54
  end
@@ -57,13 +57,13 @@ describe CoolElement do
57
57
  context "when we use only updated_at" do
58
58
  it "should sweep old objects" do
59
59
  el = subject.create(:updated_at => 10.days.ago)
60
- subject.sweep('9d', nil, false)
60
+ subject.sweep(:time => '9d', :active => false)
61
61
  subject.all.count.should eql(0)
62
62
  end
63
63
 
64
64
  it "should not sweep recently updated objects" do
65
65
  el = subject.create(:updated_at => 1.days.ago, :created_at => 10.days.ago)
66
- subject.sweep('9d', nil, false)
66
+ subject.sweep(:time => '9d', :active => false)
67
67
  subject.all.count.should eql(1)
68
68
  end
69
69
  end
@@ -72,7 +72,7 @@ describe CoolElement do
72
72
  it "should be able to perform on each" do
73
73
  2.times { |i| subject.create(:created_at => 10.days.ago, :name => i.to_s) }
74
74
  saved = []
75
- subject.sweep('1d') do |el|
75
+ subject.sweep(:time => '1d') do |el|
76
76
  saved << el.name
77
77
  end
78
78
  saved.first.to_i.should eql(0)
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- $"/1���::/V���K]��}�w���li$]Wnƅv���`-�uaI�NN���GrN��a��zWh
2
- .jt���e������=��Zz/,2��x�'����]S�C
1
+ ��>�y~}�Fl��x(�����Qߴ ,�[nY��I$����L+�ù�e��7`����ENU�D@��G���uJ��
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_sweepable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Maciej Mensfeld
@@ -31,7 +31,7 @@ cert_chain:
31
31
  BH3YFsdk
32
32
  -----END CERTIFICATE-----
33
33
 
34
- date: 2011-04-17 00:00:00 +02:00
34
+ date: 2011-04-23 00:00:00 +02:00
35
35
  default_executable:
36
36
  dependencies:
37
37
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- PcD!i��0>Ϟ
2
- X`X@�y�Y�E'H@�<�nQBL|�f5맞��Ƶ>�d��ۣ���F,.�:�Xwg��/NsM�3#Z-uj
1
+ ;�I����~�\��!FK� R `��f���Ή-��+��� �6�?�"I��9g<��†ֳ�!?Yh�VO�[G�,�]��`
2
+ �!�}��76F�W&�6W4��iR��0����.";S�7DƳ�<5Ds��:��.������^F� ��Y�0 ��SJ���_Fd7�4L^��F=EmK&=Ǻ����� ]