csv_pirate 5.0.6 → 5.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -61,3 +61,4 @@ pkg
61
61
  spec/csv/*
62
62
 
63
63
  log
64
+ .rvmrc
@@ -5,4 +5,3 @@ rvm:
5
5
  - jruby-19mode
6
6
  - rbx-19mode
7
7
  - ruby-head
8
- - jruby-head
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ Version 5.0.7 2012-12-28
2
+
3
+ - BUGFIX - Corrected implementation of :bury_treasure option, which allows storage of results as an array in buried_treasure
4
+ - BUGFIX - Corrected implementation of CsvPirate.create (v5 compatibility) to use CsvPirate::TheCapn.create
5
+ - SPECS - Added tests for :bury_treasure option
6
+ - SPECS - Improved tests for v5 compatibility
7
+ - Updated Readme to not advertise deprecated usage as much.
8
+
1
9
  Version 5.0.6 2012-09-13
2
10
  - Added back more support for pre v5 syntax with deprecation warnings. CsvPirate.new & create now work again. (Issue 2)
3
11
 
@@ -1,6 +1,4 @@
1
- == CsvPirate
2
-
3
- {<img src="https://secure.travis-ci.org/pboling/csv_pirate.png?branch=master" alt="Build Status" />}[http://travis-ci.org/pboling/csv_pirate] <= This cake is a lie. I am not sure why Travis is failing me.
1
+ == CsvPirate {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/pboling/csv_pirate] {<img src="https://secure.travis-ci.org/pboling/csv_pirate.png?branch=master" alt="Build Status" />}[http://travis-ci.org/pboling/csv_pirate] {<img src="http://api.coderwall.com/pboling/endorsecount.png" />}[http://coderwall.com/pboling]
4
2
 
5
3
  Easily create CSVs of any data that can be derived from your models.
6
4
 
@@ -22,7 +20,7 @@ Initialize method (a.k.a new()) takes a hash of parameters, and creates the blan
22
20
  # and order them according to the order of the spyglasses (optional)
23
21
  # :booty booty (columns/methods) on your model that you want printed in the CSV, also used to create the figurehead (CSV header)
24
22
  # :chart array of directory names (relative to rails root if using rails) which will be the filepath where you want to hide your loot
25
- # :wagonner name of document where you will give detailed descriptions of the loot
23
+ # :waggoner name of document where you will give detailed descriptions of the loot
26
24
  # :aft filename extention ('.csv')
27
25
  # :shrouds CSV column separator, default is ','. For tsv, tab-delimited, "\t"
28
26
  # :chronometer keeps track of when you hunt for treasure
@@ -105,7 +103,7 @@ Since the defaults assume an active record class you need to override some of th
105
103
  @distance = args.first[:distance]
106
104
  @spectral_type = args.first[:spectral_type]
107
105
  end
108
-
106
+
109
107
  def star_vowels
110
108
  self.name.tr('aeiou', '*')
111
109
  end
@@ -174,7 +172,7 @@ Assuming a Make (as in manufacturers of automobiles) model like this:
174
172
  :spyglasses => [:all] # Array of symbols/strings: Methods that will be chained together and called on :grub in order to get the :swag records which will become the rows of the CSV.
175
173
  :booty => Make.column_names # Array of symbols/strings or nested hashes of symbols/strings: Methods to call on each object in :swag. These become the columns of the CSV. The method names become the CSV column headings. Methods can be chained to dig deep (e.g. traverse several ActiveRecord associations) to get at a value for the CSV. To call instance methods that include arguments, pass a booty element of an array such as [:method_name, arg1, arg2...].
176
174
 
177
- :swab => :counter # Symbol: What kind of file counter to use to avoid overwtiting the CSV file, :counter is Integer, :timestamp is HHMMSS, :none is no file counter, increasing the liklihood of duplicate filenames on successive csv exports.
175
+ :swab => :counter # Symbol: What kind of file counter to use to avoid overwriting the CSV file, :counter is Integer, :timestamp is HHMMSS, :none is no file counter, increasing the likelihood of duplicate filenames on successive csv exports.
178
176
  :mop => :clean # Symbol: If we DO end up writing to a preexisting file (by design or accident) should we overwrite (:clean) or append (:dirty)?
179
177
  :shrouds => ',' # String: Delimiter for CSV. '\t' will create a tab delimited file (tsv), '|' will create a pipe delimited file.
180
178
  :bury_treasure => true # Boolean: Should the array of objects in :swag be stored in the CsvPirate object for later inspection?
@@ -213,7 +211,7 @@ What if you want the file name to be always the same and to always append to the
213
211
  Make.walk_the_plank({:chronometer => false, :gibbet => "", :aft => "", :swab => :none, :waggoner => 'data'})
214
212
  Make.blindfold(:chronometer => false, :gibbet => "", :aft => "", :swab => :none, :waggoner => 'data')
215
213
 
216
- All of the options to has_csv_pirate_ship are available to walk_the_plank, land_ho, and blindfold, as well as to the raw class methods CsvPirate.new and CsvPirate.create, but not neccessarily the other way around.
214
+ All of the options to has_csv_pirate_ship are available to walk_the_plank, land_ho, and blindfold, as well as to the raw class methods CsvPirate::TheCapn.new and CsvPirate::TheCapn.create, but not necessarily the other way around.
217
215
 
218
216
  You can also customize the CSV, for example if you want to customize which columns are in the csv:
219
217
 
@@ -260,7 +258,7 @@ You can also use the raw CsvPirate class itself directly wherever you want.
260
258
 
261
259
  The following two sets of code are identical:
262
260
 
263
- csv_pirate = CsvPirate.new({
261
+ csv_pirate = CsvPirate::TheCapn.new({
264
262
  :grub => User,
265
263
  :spyglasses => [:active,:logged_in],
266
264
  :waggoner => 'active_users_logged_in',
@@ -269,7 +267,7 @@ The following two sets of code are identical:
269
267
  })
270
268
  csv_pirate.hoist_mainstay() # creates CSV file and writes out the rows
271
269
 
272
- CsvPirate.create({
270
+ CsvPirate::TheCapn.create({
273
271
  :grub => User,
274
272
  :spyglasses => [:active,:logged_in],
275
273
  :waggoner => 'active_users_logged_in',
@@ -280,7 +278,7 @@ The following two sets of code are identical:
280
278
  Another example using swag instead of grub:
281
279
 
282
280
  users = User.logged_out.inactive
283
- csv_pirate = CsvPirate.new({
281
+ csv_pirate = CsvPirate::TheCapn.new({
284
282
  :swag => users,
285
283
  :waggoner => 'inactive_users_not_logged_in',
286
284
  :booty => ["id","number","login","created_at"],
@@ -294,11 +292,11 @@ Then if you want to get your hands on the loot immediately:
294
292
 
295
293
  For those who can't help but copy/paste into console and then edit:
296
294
 
297
- csv_pirate = CsvPirate.new({:grub => User,:spyglasses => [:active,:logged_in],:waggoner => 'active_users_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']})
295
+ csv_pirate = CsvPirate::TheCapn.new({:grub => User,:spyglasses => [:active,:logged_in],:waggoner => 'active_users_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']})
298
296
 
299
297
  OR
300
298
 
301
- csv_pirate = CsvPirate.new({:swag => users,:waggoner => 'inactive_users_not_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']})
299
+ csv_pirate = CsvPirate::TheCapn.new({:swag => users,:waggoner => 'inactive_users_not_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']})
302
300
 
303
301
 
304
302
  == Downloading the CSV
@@ -42,7 +42,7 @@ module CsvPirate
42
42
 
43
43
  def self.create(*args)
44
44
  warn "[DEPRECATION] \"CsvPirate.create\" is deprecated. Use \"CsvPirate::TheCapn.create\" instead. Called from: #{caller.first}"
45
- CsvPirate::TheCapn.new(*args)
45
+ CsvPirate::TheCapn.create(*args)
46
46
  end
47
47
 
48
48
  end
@@ -116,7 +116,7 @@ module CsvPirate
116
116
 
117
117
  @astrolabe = args.first[:astrolabe] || false
118
118
 
119
- @bury_treasure = args.first[:astrolabe] || false
119
+ @bury_treasure = args.first[:bury_treasure] || false
120
120
  @buried_treasure = []
121
121
 
122
122
  #does not rely on rails humanize!
@@ -1,6 +1,6 @@
1
1
  module CsvPirate
2
2
 
3
- VERSION = "5.0.6"
3
+ VERSION = "5.0.7"
4
4
 
5
5
  VERSION_ARRAY = VERSION.split('.')
6
6
 
@@ -30,27 +30,71 @@ describe CsvPirate do
30
30
  end
31
31
  end
32
32
 
33
- describe "#new" do
34
- it "should support the old < v5 syntax" do
35
- # Similar to example from the readme
36
- CsvPirate.new({
37
- :swag => [Struct.new(:first_name, :last_name, :birthday).new('Joe','Smith','12/24/1805')],
38
- :waggoner => 'active_users_logged_in',
39
- :booty => [:first_name, :last_name],
40
- :chart => ['log','csv']
41
- }).class.should == CsvPirate::TheCapn
33
+ describe "support the old < v5 syntax" do
34
+ # Mapping needs to be a separate test, because testing the method call mocks the object, and breaks the actual #new
35
+ describe "#new mapping" do
36
+ it "should map to CsvPirate::TheCapn.new" do
37
+ CsvPirate::TheCapn.should_receive(:new)
38
+ # Similar to old example from the v5 readme
39
+ @csv_pirate = CsvPirate.new({
40
+ :swag => [Struct.new(:first_name, :last_name, :birthday).new('Joe','Smith','12/24/1805')],
41
+ :waggoner => 'active_users_logged_in',
42
+ :booty => [:first_name, :last_name],
43
+ :chart => ['log','csv'],
44
+ :bury_treasure => true,
45
+ })
46
+ end
47
+ end
48
+ describe "#new" do
49
+ before(:each) do
50
+ # Similar to old example from the v5 readme
51
+ @csv_pirate = CsvPirate.new({
52
+ :swag => [Struct.new(:first_name, :last_name, :birthday).new('Joe','Smith','12/24/1805')],
53
+ :waggoner => 'active_users_logged_in',
54
+ :booty => [:first_name, :last_name],
55
+ :chart => ['log','csv'],
56
+ :bury_treasure => true,
57
+ })
58
+ end
59
+ it "should create an instance of CsvPirate::TheCapn" do
60
+ @csv_pirate.class.should == CsvPirate::TheCapn
61
+ end
62
+ it "should NOT mine the data" do
63
+ @csv_pirate.buried_treasure.length.should == 0
64
+ end
42
65
  end
43
- end
44
66
 
45
- describe "#create" do
46
- it "should support the old < v5 syntax" do
47
- # Similar to example from the readme
48
- CsvPirate.create({
49
- :swag => [Struct.new(:first_name, :last_name, :birthday).new('Joe','Smith','12/24/1805')],
50
- :waggoner => 'active_users_logged_in',
51
- :booty => [:first_name, :last_name],
52
- :chart => ['log','csv']
53
- }).class.should == CsvPirate::TheCapn
67
+ # Mapping needs to be a separate test, because testing the method call mocks the object, and breaks the actual #new
68
+ describe "#create mapping" do
69
+ it "should map to CsvPirate::TheCapn.create" do
70
+ CsvPirate::TheCapn.should_receive(:create)
71
+ # Similar to old example from the v5 readme
72
+ @csv_pirate = CsvPirate.create({
73
+ :swag => [Struct.new(:first_name, :last_name, :birthday).new('Joe','Smith','12/24/1805')],
74
+ :waggoner => 'active_users_logged_in',
75
+ :booty => [:first_name, :last_name],
76
+ :chart => ['log','csv'],
77
+ :bury_treasure => true,
78
+ })
79
+ end
80
+ end
81
+ describe "#create" do
82
+ before(:each) do
83
+ # Similar to old example from the v5 readme
84
+ @csv_pirate = CsvPirate.create({
85
+ :swag => [Struct.new(:first_name, :last_name, :birthday).new('Joe','Smith','12/24/1805')],
86
+ :waggoner => 'active_users_logged_in',
87
+ :booty => [:first_name, :last_name],
88
+ :chart => ['log','csv'],
89
+ :bury_treasure => true,
90
+ })
91
+ end
92
+ it "should create an instance of CsvPirate::TheCapn" do
93
+ @csv_pirate.class.should == CsvPirate::TheCapn
94
+ end
95
+ it "should mine the data" do
96
+ @csv_pirate.buried_treasure.length.should == 1
97
+ end
54
98
  end
55
99
  end
56
100
 
@@ -239,4 +239,40 @@ describe CsvPirate::TheCapn do
239
239
  end
240
240
  end
241
241
 
242
+ describe ":bury_treasure option" do
243
+ describe "when true" do
244
+ before(:each) do
245
+ # Similar to example from the readme
246
+ @csv_pirate = CsvPirate::TheCapn.create({
247
+ :swag => [Struct.new(:first_name, :last_name, :birthday).new('Joe','Smith','12/24/1805')],
248
+ :waggoner => 'active_users_logged_in',
249
+ :booty => [:first_name, :last_name],
250
+ :chart => ['log','csv'],
251
+ :bury_treasure => true
252
+ })
253
+ end
254
+ it "should bury treasure in buried_treasure as array" do
255
+ @csv_pirate.buried_treasure.class.should == Array
256
+ end
257
+ it "should have buried treasure" do
258
+ @csv_pirate.buried_treasure.first.should == %w(Joe Smith)
259
+ end
260
+ end
261
+ describe "when false" do
262
+ before(:each) do
263
+ # Similar to example from the readme
264
+ @csv_pirate = CsvPirate::TheCapn.create({
265
+ :swag => [Struct.new(:first_name, :last_name, :birthday).new('Joe','Smith','12/24/1805')],
266
+ :waggoner => 'active_users_logged_in',
267
+ :booty => [:first_name, :last_name],
268
+ :chart => ['log','csv'],
269
+ :bury_treasure => false
270
+ })
271
+ end
272
+ it "should not bury any treasure in the buried_treasure array" do
273
+ @csv_pirate.buried_treasure.should == []
274
+ end
275
+ end
276
+ end
277
+
242
278
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_pirate
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.6
4
+ version: 5.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -182,4 +182,3 @@ test_files:
182
182
  - spec/spec_helper.rb
183
183
  - spec/support/glowing_gas_ball.rb
184
184
  - spec/support/star.rb
185
- has_rdoc: