comma 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
- pkg
2
- .swp
3
- comma.gemspec
1
+ pkg/*
2
+ .*.swp
3
+ *~
4
+ *.gemspec
data/README.rdoc CHANGED
@@ -109,10 +109,16 @@ You can specify which output format you would like to use via an optional parame
109
109
 
110
110
  Specifying no description name to to_comma is equivalent to specifying :default as the description name.
111
111
 
112
- You can pass options for FasterCVS, e.g.
112
+ You can pass options for FasterCSV, e.g.
113
113
 
114
114
  Book.limited(10).to_comma(:style => :brief, :col_sep => ';', :force_quotes => true)
115
115
 
116
+ You can pass the :filename option and have Comma writes the CSV output to this file:
117
+
118
+ Book.limited(10).to_comma(:filename => 'books.csv')
119
+
120
+ === USING WITH RAILS
121
+
116
122
  When used with Rails (ie. add 'comma' as a gem dependency), Comma automatically adds support for rendering CSV output in your controllers:
117
123
 
118
124
  class BooksController < ApplicationController
@@ -125,9 +131,23 @@ When used with Rails (ie. add 'comma' as a gem dependency), Comma automatically
125
131
 
126
132
  end
127
133
 
128
- If you have any questions or suggestions for Comma, please feel free to contact me at crafterm@redartisan.com, all feedback welcome!
134
+ When used with Rails 2.3.*, Comma also adds support for exporting named scopes:
135
+
136
+ class Book < ActiveRecord::Base
137
+ named_scope :recent,
138
+ lambda { { :conditions => ['created_at > ?', 1.month.ago] } }
139
+
140
+ # ...
141
+ end
142
+
143
+ Calling the to_comma method on the named scope will internally use Rails' find_each method, instantiating only 1,000 ActiveRecord objects at a time:
144
+
145
+ Book.recent.to_comma
129
146
 
130
147
  == DEPENDENCIES
131
148
 
132
- If you're on ruby 1.8.*, the fasterCSV gem is recommended for performance reasons.
149
+ If you're on Ruby 1.8.*, the FasterCSV gem is recommended for performance reasons.
150
+
133
151
  gem install fastercsv
152
+
153
+ If you have any questions or suggestions for Comma, please feel free to contact me at crafterm@redartisan.com, all feedback welcome!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/lib/comma.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  if defined? Rails and Rails.version < '2.3.5'
3
3
  require 'activesupport'
4
4
  else
5
- require 'active_support'
5
+ require 'active_support/core_ext/class/inheritable_attributes'
6
6
  end
7
7
 
8
8
  # load the right csv library
@@ -28,10 +28,10 @@ require 'comma/extractors'
28
28
  require 'comma/generator'
29
29
  require 'comma/array'
30
30
  require 'comma/object'
31
- require 'comma/renderascsv'
31
+ require 'comma/render_as_csv'
32
32
 
33
33
  if defined?(ActiveRecord)
34
- require 'comma/namedscope'
34
+ require 'comma/named_scope'
35
35
  end
36
36
 
37
37
  if defined?(ActionController)
@@ -16,7 +16,7 @@ module Comma
16
16
 
17
17
  def run(iterator_method)
18
18
  if @filename
19
- FasterCSV.open(@filename, 'w'){ |csv| append_csv(csv, iterator_method) } and return true
19
+ FasterCSV.open(@filename, 'w', @options){ |csv| append_csv(csv, iterator_method) } and return true
20
20
  else
21
21
  FasterCSV.generate(@options){ |csv| append_csv(csv, iterator_method) }
22
22
  end
File without changes
File without changes
@@ -1,5 +1,4 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'active_record'
3
2
 
4
3
  describe Comma, 'generating CSV from an ActiveRecord object' do
5
4
  before(:all) do
@@ -39,15 +39,21 @@ describe Comma, 'generating CSV' do
39
39
  end
40
40
 
41
41
  describe 'with :filename specified' do
42
- before{ @books.to_comma(:filename => 'comma.csv') }
43
42
  after{ File.delete('comma.csv') }
44
43
 
45
44
  it "should write to the file" do
45
+ @books.to_comma(:filename => 'comma.csv')
46
46
  File.read('comma.csv').should == "Title,Description,Issuer,ISBN-10,ISBN-13\nSmalltalk-80,Language and Implementation,ISBN,123123123,321321321\n"
47
47
  end
48
+
49
+ it "should accept FasterCSV options" do
50
+ @books.to_comma(:filename => 'comma.csv', :col_sep => ';', :force_quotes => true)
51
+ File.read('comma.csv').should == "\"Title\";\"Description\";\"Issuer\";\"ISBN-10\";\"ISBN-13\"\n\"Smalltalk-80\";\"Language and Implementation\";\"ISBN\";\"123123123\";\"321321321\"\n"
52
+ end
53
+
48
54
  end
49
55
 
50
- describe "with FasterCVS options" do
56
+ describe "with FasterCSV options" do
51
57
  it "should not change when options are empty" do
52
58
  @books.to_comma({}).should == "Title,Description,Issuer,ISBN-10,ISBN-13\nSmalltalk-80,Language and Implementation,ISBN,123123123,321321321\n"
53
59
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
+ require 'active_record'
3
4
 
4
5
  $:.unshift(File.dirname(__FILE__) + '/../lib')
5
6
  require 'comma'
data/sudo ADDED
@@ -0,0 +1,384 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file, hub, is generated code.
4
+ # Please DO NOT EDIT or send patches for it.
5
+ #
6
+ # Please take a look at the source from
7
+ # http://github.com/defunkt/hub
8
+ # and submit patches against the individual files
9
+ # that build hub.
10
+ #
11
+
12
+ module Hub
13
+ class Args < Array
14
+ def after(command = nil, &block)
15
+ @after ||= block ? block : command
16
+ end
17
+
18
+ def after?
19
+ !!@after
20
+ end
21
+ end
22
+ end
23
+ module Hub
24
+ module Commands
25
+ instance_methods.each { |m| undef_method(m) unless m =~ /(^__|send|to\?$)/ }
26
+ extend self
27
+
28
+ PRIVATE = 'git@github.com:%s/%s.git'
29
+ PUBLIC = 'git://github.com/%s/%s.git'
30
+ USER = `git config --global github.user`.chomp
31
+ REPO = `basename $(pwd)`.chomp
32
+ LGHCONF = "http://github.com/guides/local-github-config"
33
+
34
+ def clone(args)
35
+ ssh = args.delete('-p')
36
+ args[1..-1].each_with_index do |arg, i|
37
+ i += 1
38
+ if arg.scan('/').size == 1 && !arg.include?(':')
39
+ url = ssh ? PRIVATE : PUBLIC
40
+ args[i] = url % arg.split('/')
41
+ break
42
+ elsif arg !~ /:|\//
43
+ url = ssh ? PRIVATE : PUBLIC
44
+ args[i] = url % [ github_user, arg ]
45
+ break
46
+ end
47
+ end
48
+ end
49
+
50
+ def remote(args)
51
+ return unless args[1] == 'add'
52
+
53
+ if args[-1] !~ /:|\//
54
+ ssh = args.delete('-p')
55
+ user = args.last
56
+ url = ssh ? PRIVATE : PUBLIC
57
+ args << url % [ user, REPO ]
58
+ end
59
+ end
60
+
61
+ def init(args)
62
+ if args.delete('-g')
63
+
64
+ url = PRIVATE % [ github_user, REPO ]
65
+ args.after "git remote add origin #{url}"
66
+ end
67
+ end
68
+
69
+ def alias(args)
70
+ shells = {
71
+ 'sh' => 'alias git=hub',
72
+ 'bash' => 'alias git=hub',
73
+ 'zsh' => 'alias git=hub',
74
+ 'csh' => 'alias git hub',
75
+ 'fish' => 'alias git hub'
76
+ }
77
+
78
+ silent = args.delete('-s')
79
+
80
+ if shell = args[1]
81
+ if silent.nil?
82
+ puts "Run this in your shell to start using `hub` as `git`:"
83
+ print " "
84
+ end
85
+ else
86
+ puts "usage: hub alias [-s] SHELL", ""
87
+ puts "You already have hub installed and available in your PATH,"
88
+ puts "but to get the full experience you'll want to alias it to"
89
+ puts "`git`.", ""
90
+ puts "To see how to accomplish this for your shell, run the alias"
91
+ puts "command again with the name of your shell.", ""
92
+ puts "Known shells:"
93
+ shells.map { |key, _| key }.sort.each do |key|
94
+ puts " " + key
95
+ end
96
+ puts "", "Options:"
97
+ puts " -s Silent. Useful when using the output with eval, e.g."
98
+ puts " $ eval `hub alias -s bash`"
99
+
100
+ exit
101
+ end
102
+
103
+ if shells[shell]
104
+ puts shells[shell]
105
+ else
106
+ abort "fatal: never heard of `#{shell}'"
107
+ end
108
+
109
+ exit
110
+ end
111
+
112
+ def version(args)
113
+ args.after do
114
+ puts "hub version %s" % Version
115
+ end
116
+ end
117
+ alias_method "--version", :version
118
+
119
+ def help(args)
120
+ if args[1] == 'hub'
121
+ puts hub_manpage
122
+ exit
123
+ elsif args.size == 1
124
+ puts improved_help_text
125
+ exit
126
+ end
127
+ end
128
+
129
+ def improved_help_text
130
+ <<-help
131
+ usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
132
+ [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR]
133
+ [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]
134
+
135
+ Basic Commands:
136
+ init Create an empty git repository or reinitialize an existing one
137
+ add Add new or modified files to the staging area
138
+ rm Remove files from the working directory and staging area
139
+ mv Move or rename a file, a directory, or a symlink
140
+ status Show the status of the working directory and staging area
141
+ commit Record changes to the repository
142
+
143
+ History Commands:
144
+ log Show the commit history log
145
+ diff Show changes between commits, commit and working tree, etc
146
+ show Show information about commits, tags or files
147
+
148
+ Branching Commands:
149
+ branch List, create, or delete branches
150
+ checkout Switch the active branch to another branch
151
+ merge Join two or more development histories (branches) together
152
+ tag Create, list, delete, sign or verify a tag object
153
+
154
+ Remote Commands:
155
+ clone Clone a remote repository into a new directory
156
+ fetch Download data, tags and branches from a remote repository
157
+ pull Fetch from and merge with another repository or a local branch
158
+ push Upload data, tags and branches to a remote repository
159
+ remote View and manage a set of remote repositories
160
+
161
+ Advanced commands:
162
+ reset Reset your staging area or working directory to another point
163
+ rebase Re-apply a series of patches in one branch onto another
164
+ bisect Find by binary search the change that introduced a bug
165
+ grep Print files with lines matching a pattern in your codebase
166
+
167
+ See 'git help COMMAND' for more information on a specific command.
168
+ help
169
+ end
170
+
171
+ private
172
+
173
+ def github_user
174
+ if USER.empty?
175
+ abort "** No GitHub user set. See #{LGHCONF}"
176
+ else
177
+ USER
178
+ end
179
+ end
180
+
181
+ def hub_manpage
182
+ return "** Can't find groff(1)" unless groff?
183
+
184
+ require 'open3'
185
+ out = nil
186
+ Open3.popen3(groff_command) do |stdin, stdout, _|
187
+ stdin.puts hub_raw_manpage
188
+ stdin.close
189
+ out = stdout.read.strip
190
+ end
191
+ out
192
+ end
193
+
194
+ def groff?
195
+ system("which groff")
196
+ end
197
+
198
+ def groff_command
199
+ "groff -Wall -mtty-char -mandoc -Tascii"
200
+ end
201
+
202
+ def hub_raw_manpage
203
+ if File.exists? file = File.dirname(__FILE__) + '/../../man/hub.1'
204
+ File.read(file)
205
+ else
206
+ DATA.read
207
+ end
208
+ end
209
+
210
+ def puts(*args)
211
+ page_stdout
212
+ super
213
+ end
214
+
215
+ def page_stdout
216
+ return unless $stdout.tty?
217
+
218
+ read, write = IO.pipe
219
+
220
+ if Kernel.fork
221
+ $stdin.reopen(read)
222
+ read.close
223
+ write.close
224
+
225
+ ENV['LESS'] = 'FSRX'
226
+
227
+ Kernel.select [STDIN]
228
+
229
+ pager = ENV['PAGER'] || 'less -isr'
230
+ exec pager rescue exec "/bin/sh", "-c", pager
231
+ else
232
+ $stdout.reopen(write)
233
+ $stderr.reopen(write) if $stderr.tty?
234
+ read.close
235
+ write.close
236
+ end
237
+ end
238
+ end
239
+ end
240
+ module Hub
241
+ class Runner
242
+ attr_reader :args
243
+ def initialize(*args)
244
+ @args = Args.new(args)
245
+
246
+ @args[0] = 'help' if @args.empty?
247
+
248
+ if Commands.respond_to?(@args[0])
249
+ Commands.send(@args[0], @args)
250
+ end
251
+ end
252
+
253
+ def self.execute(*args)
254
+ new(*args).execute
255
+ end
256
+
257
+ def after
258
+ args.after.to_s
259
+ end
260
+
261
+ def command
262
+ "git #{args.join(' ')}"
263
+ end
264
+
265
+ def execute
266
+ if args.after?
267
+ execute_with_after_callback
268
+ else
269
+ exec "git", *args
270
+ end
271
+ end
272
+
273
+ def execute_with_after_callback
274
+ after = args.after
275
+ if system("git", *args)
276
+ after.respond_to?(:call) ? after.call : exec(after)
277
+ exit
278
+ else
279
+ exit 1
280
+ end
281
+ end
282
+ end
283
+ end
284
+ module Hub
285
+ Version = '0.1.3'
286
+ end
287
+ Hub::Runner.execute(*ARGV)
288
+ __END__
289
+ .\" generated with Ron/v0.3
290
+ .\" http://github.com/rtomayko/ron/
291
+ .
292
+ .TH "HUB" "1" "December 2009" "DEFUNKT" "Git Manual"
293
+ .
294
+ .SH "NAME"
295
+ \fBhub\fR \-\- git + hub = github
296
+ .
297
+ .SH "SYNOPSIS"
298
+ \fBhub\fR \fICOMMAND\fR \fIOPTIONS\fR
299
+ .
300
+ .br
301
+ \fBhub alias\fR [\fB\-s\fR] \fISHELL\fR
302
+ .
303
+ .P
304
+ \fBgit init \-g\fR \fIOPTIONS\fR
305
+ .
306
+ .br
307
+ \fBgit clone\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR
308
+ .
309
+ .br
310
+ \fBgit remote add\fR [\fB\-p\fR] \fIOPTIONS\fR \fIUSER\fR[/\fIREPOSITORY\fR]
311
+ .
312
+ .br
313
+ .
314
+ .SH "DESCRIPTION"
315
+ \fBhub\fR enhances various \fBgit\fR commands with GitHub remote expansion. The
316
+ alias command displays information on configuring your environment:
317
+ .
318
+ .TP
319
+ \fBhub alias\fR [\fB\-s\fR] \fISHELL\fR
320
+ Writes shell aliasing code for \fISHELL\fR (\fBbash\fR, \fBsh\fR, \fBzsh\fR, \fBcsh\fR) to standard output. With the \fB\-s\fR option, the output of
321
+ this command can be evaluated directly within the shell: \fBeval $(hub alias \-s bash)\fR
322
+ .
323
+ .P
324
+ After configuring the alias, the following commands have superpowers:
325
+ .
326
+ .TP
327
+ \fBgit init\fR \fB\-g\fR \fIOPTIONS\fR
328
+ Create a git repository as with git\-init(1) and add remote \fBorigin\fR at
329
+ "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git"; \fIUSER\fR is your GitHub username and \fIREPOSITORY\fR is the current working directory's basename.
330
+ .
331
+ .TP
332
+ \fBgit clone\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR \fIDIRECTORY\fR
333
+ Clone repository "git://github.com/\fIUSER\fR/\fIREPOSITORY\fR.git" into \fIDIRECTORY\fR as with git\-clone(1). When \fIUSER\fR/ is omitted, assumes
334
+ your GitHub login. With \fB\-p\fR, use private remote
335
+ "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git".
336
+ .
337
+ .TP
338
+ \fBgit remote add\fR [\fB\-p\fR] \fIOPTIONS\fR \fIUSER\fR[\fB/\fR\fIREPOSITORY\fR]
339
+ Add remote "git://github.com/\fIUSER\fR/\fIREPOSITORY\fR.git" as with
340
+ git\-remote(1). When /\fIREPOSITORY\fR is omitted, the basename of the
341
+ current working directory is used. With \fB\-p\fR, use private remote
342
+ "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git".
343
+ .
344
+ .TP
345
+ \fBgit help\fR
346
+ Display enhanced git\-help(1).
347
+ .
348
+ .SH "CONFIGURATION"
349
+ Use git\-config(1) to display the currently configured GitHub username:
350
+ .
351
+ .IP "" 4
352
+ .
353
+ .nf
354
+
355
+ $ git config \-\-global github.user
356
+ .
357
+ .fi
358
+ .
359
+ .IP "" 0
360
+ .
361
+ .P
362
+ Or, set the GitHub username with:
363
+ .
364
+ .IP "" 4
365
+ .
366
+ .nf
367
+
368
+ $ git config \-\-global github.user <username>
369
+ .
370
+ .fi
371
+ .
372
+ .IP "" 0
373
+ .
374
+ .P
375
+ See \fIhttp://github.com/guides/local\-github\-config\fR for more information.
376
+ .
377
+ .SH "BUGS"
378
+ \fIhttp://github.com/defunkt/hub/issues\fR
379
+ .
380
+ .SH "AUTHOR"
381
+ Chris Wanstrath :: chris@ozmm.org :: @defunkt
382
+ .
383
+ .SH "SEE ALSO"
384
+ git(1), git\-clone(1), git\-remote(1), git\-init(1),\fIhttp://github.com\fR, \fIhttp://github.com/defunkt/hub\fR
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Crafter
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-22 00:00:00 +11:00
12
+ date: 2010-01-06 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,14 +51,15 @@ files:
51
51
  - lib/comma/array.rb
52
52
  - lib/comma/extractors.rb
53
53
  - lib/comma/generator.rb
54
- - lib/comma/namedscope.rb
54
+ - lib/comma/named_scope.rb
55
55
  - lib/comma/object.rb
56
- - lib/comma/renderascsv.rb
56
+ - lib/comma/render_as_csv.rb
57
57
  - spec/comma/ar_spec.rb
58
58
  - spec/comma/comma_spec.rb
59
59
  - spec/comma/extractors_spec.rb
60
60
  - spec/spec.opts
61
61
  - spec/spec_helper.rb
62
+ - sudo
62
63
  has_rdoc: true
63
64
  homepage: http://github.com/crafterm/comma
64
65
  licenses: []