mongoid_to_csv 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -23,12 +23,30 @@ to_csv() returns the entire contents including the header ready to be written to
23
23
  title,director_id
24
24
  The Kids Are All Right,4
25
25
 
26
- For normal arrays, `to_csv` works the same way.
26
+ For normal arrays, `to_mongoid_csv` works the same way.
27
27
 
28
- Movie.all.to_csv
28
+ Movie.all.to_mongoid_csv
29
29
  # Same as
30
30
  Movie.to_csv
31
31
 
32
+ === Why not Array.to_csv?
33
+
34
+ I tried.
35
+
36
+ require 'csv'
37
+ module ArrayToCSV
38
+ def to_csv
39
+ if first.is_a?(Mongoid::Document)
40
+ MongoidToCSV.documents_to_csv(self)
41
+ else
42
+ super
43
+ end
44
+ end
45
+ end
46
+ Array.send :include, ArrayToCSV
47
+
48
+ Something is giving ruby's internal `Array#to_csv` precedence and ignoring mine. Got tired of messing around with it.
49
+
32
50
  === Attribute#to_csv
33
51
 
34
52
  After a model object's attributes are collected, to_csv is called on the resulting array. However, this poses a problem because it will blindly convert the attributes to a string -- i.e. call to_s on them. If one of your attributes is a Date, then calling to_s may produce unwanted output. For example, if you have Date::DATE_FORMATS[:default] = '%d %B, %Y' your dates will have the month written out like 'January', 'February', etc. To counter this, this gem will make an attempt to call to_csv() on each attribute. To get YYYY-MM-DD output, you could do something like:
@@ -1,3 +1,3 @@
1
1
  module MongoidToCSV
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -43,13 +43,8 @@ class Mongoid::Relation
43
43
  end
44
44
  end
45
45
 
46
- module ArrayToCSV
47
- def to_csv
48
- if first.is_a?(Mongoid::Document)
49
- MongoidToCSV.documents_to_csv(self)
50
- else
51
- super
52
- end
46
+ class Array
47
+ def to_mongoid_csv
48
+ MongoidToCSV.documents_to_csv(self)
53
49
  end
54
50
  end
55
- Array.send :include, ArrayToCSV
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_to_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
- requirement: &70104211044580 !ruby/object:Gem::Requirement
16
+ requirement: &70316840720020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.0.0.rc.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70104211044580
24
+ version_requirements: *70316840720020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70104211044080 !ruby/object:Gem::Requirement
27
+ requirement: &70316840719520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70104211044080
35
+ version_requirements: *70316840719520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongo
38
- requirement: &70104211043620 !ruby/object:Gem::Requirement
38
+ requirement: &70316840719060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.3.1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70104211043620
46
+ version_requirements: *70316840719060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bson_ext
49
- requirement: &70104211043240 !ruby/object:Gem::Requirement
49
+ requirement: &70316840718680 !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: *70104211043240
57
+ version_requirements: *70316840718680
58
58
  description: Simple Mongoid Model to_csv() class method that preserves scopes
59
59
  email:
60
60
  - jared@redningja.com