liszt 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/liszt.rb CHANGED
@@ -44,7 +44,8 @@ module Liszt
44
44
  def initialize_list!(obj={}, &block)
45
45
  objects = find(:all, :conditions => liszt_query(obj))
46
46
 
47
- # If the caller provided a block, sort the objects by that block's
47
+ # If the caller provided a block, or if they passed in a default
48
+ # with the :sort_by option, sort the objects by that block's
48
49
  # output before populating the list with their ids. If not, put
49
50
  # the objects in descending order by id.
50
51
  ids = if block_given?
@@ -70,15 +71,20 @@ module Liszt
70
71
  end
71
72
 
72
73
  def ordered_list_ids(obj={})
73
- return nil unless ordered_list_initialized?(obj)
74
- ordered_list(obj).all
74
+ if ordered_list_initialized?(obj)
75
+ ordered_list(obj).all
76
+ else
77
+ initialize_list!(obj)
78
+ end
75
79
  end
76
80
 
77
81
  def ordered_list_items(obj={}, double_check=false)
78
- return nil unless ordered_list_initialized?(obj)
82
+ was_initialized = ordered_list_initialized?(obj)
79
83
  ids = ordered_list_ids(obj)
80
84
 
81
- if double_check
85
+ # If ordered_list_ids just did the initialization, we can trust that
86
+ # the list of ids is accurate and ignore the double_check flag.
87
+ if double_check and was_initialized
82
88
  objs = find(:all, :conditions => liszt_query(obj))
83
89
  real_ids = objs.map(&:id)
84
90
  unlisted_ids = real_ids - ids
data/lib/liszt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Liszt
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/test/liszt_test.rb CHANGED
@@ -17,6 +17,11 @@ class LisztTest < ActiveSupport::TestCase
17
17
  assert_nothing_raised { people(:nelson).initialize_list! }
18
18
  assert people(:nelson).ordered_list_initialized?
19
19
  end
20
+
21
+ should "auto-initialize successfully" do
22
+ assert_nothing_raised { people(:nelson).ordered_list_ids }
23
+ assert people(:nelson).ordered_list_initialized?
24
+ end
20
25
  end
21
26
 
22
27
  context "after initialization" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liszt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70260000385480 !ruby/object:Gem::Requirement
16
+ requirement: &70165237093020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70260000385480
24
+ version_requirements: *70165237093020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &70260000385060 !ruby/object:Gem::Requirement
27
+ requirement: &70165237092600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70260000385060
35
+ version_requirements: *70165237092600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &70260000384600 !ruby/object:Gem::Requirement
38
+ requirement: &70165237092140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70260000384600
46
+ version_requirements: *70165237092140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdiscount
49
- requirement: &70260000384180 !ruby/object:Gem::Requirement
49
+ requirement: &70165237091720 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70260000384180
57
+ version_requirements: *70165237091720
58
58
  description: Liszt is an alternative to acts_as_list and sortable that uses atomic
59
59
  Redis operations to maintain scoped ordering information for ActiveRecord objects.
60
60
  email: