attributes_sort 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -1,13 +1,8 @@
1
1
  module AttributesSort
2
2
  def self.included(receiver)
3
3
  receiver.instance_eval do
4
- def build_attributes(attributes)
5
- "[" << attributes.map!{|attribute| "object.#{attribute}"}.join(",") << "]"
6
- end
7
-
8
- def do_attributes_sort(collection, attributes)
9
- attribute_array_string = build_attributes(attributes)
10
- collection.sort_by{|object| eval(attribute_array_string)}
4
+ def do_attributes_sort(collection, attributes)
5
+ collection.sort_by { |object| attributes.map { |attribute| object.send(attribute) }}
11
6
  end
12
7
  end
13
8
  Array.class_eval do
@@ -17,11 +12,6 @@ module AttributesSort
17
12
 
18
13
  def class_type
19
14
  klass = self.first.class
20
-
21
- #use duck type check respond to check instead
22
- #is_same = self.all?{|object| object.class == klass}
23
- #raise "All objects must be of the same class type" unless is_same
24
-
25
15
  raise "All objects must respond to sort criteria"unless sortable_attributes?
26
16
  klass
27
17
  end
@@ -38,11 +38,6 @@ describe "AttributesSort" do
38
38
  p.should respond_to(:age)
39
39
  end
40
40
 
41
- it "build attributes string array to be eval'd at deferred time in sort_by block'" do
42
- criteria = [:lastname, :age, :firstname]
43
- Person.build_attributes(criteria).should == "[object.lastname,object.age,object.firstname]"
44
- end
45
-
46
41
  it "sort by last name" do
47
42
  test_sort([:lastname], [@p1, @p2, @p5, @p4, @p3])
48
43
  end
@@ -71,12 +66,6 @@ describe "AttributesSort" do
71
66
  lambda {test_sort([:blah], [@p1, @p2, @p5, @p4, @p3])}.should raise_error("All objects must respond to sort criteria")
72
67
  end
73
68
 
74
- it "raise error if objects are not of same class type" do
75
- pending "using duck type check instead"
76
- @people << "some other object"
77
- lambda {test_sort([:age],[@p1, @p2, @p5, @p4, @p3])}.should raise_error("All objects must be of the same class type")
78
- end
79
-
80
69
  class Dog
81
70
  attr_accessor :firstname,:lastname,:age
82
71
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Karmen Blake