cbuilder 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97eba12f5cd2f1fdae6a622bf48420a447512c1f
4
+ data.tar.gz: e7374f630008e1c1455d5b72a0b7c3b97c43eee8
5
+ SHA512:
6
+ metadata.gz: 9b6dc8ae4fe9a50d4ed0a093a65ffbf44c95249f30585f0d79095101c925488c0cfb6c5f4d32d48941879e84d7fb9ad9ea70c00f8c95ca4bc2faf0ea5f8f6f73
7
+ data.tar.gz: acad4c25d5a3e701330cff706a95e95729cbc02917b2fa83e23ac04c616a1f2c2bc223271e90099537a153af27dbc16d890b9efc902c945b90eb5457e2a62fba
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # cbuilder
2
2
 
3
+ [![Build Status](https://travis-ci.org/caffeinatedlabs/cbuilder.png?branch=master)](https://travis-ci.org/caffeinatedlabs/cbuilder)
4
+
3
5
  Cbuilder is an ultralight (< 100 LOC) CSV builder/template handler inspired by dhh's excellent
4
6
  Jbuilder. The goal is a simple DSL for creating CSV files that's better than creating
5
7
  massive custom arrays.
6
8
 
7
- If you're doing any more than 4-5 columns, generating CSV files can be a real pain.
9
+ If you're doing any more than 4-5 columns, generating CSV files can be a real pain.
8
10
  God forbid you're not simply outputting the attributes of a simple array, and need
9
11
  helpers or other niceties.
10
12
 
@@ -13,7 +15,7 @@ You don't need to re-invent the wheel with CSV. Cbuilder weighs in at less than
13
15
  Have you ever found yourself doing this?
14
16
 
15
17
  ```ruby
16
- Customer Name,Products Purchased, Product Names
18
+ Customer Name,Products Purchased, Product Names
17
19
  <% @orders.each do |order|%>
18
20
  <%= order.customer.name %>,<%= products_count(order) %>,<%= product_names(order.products) %>,...
19
21
  <% end %>
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
3
 
4
+ task :default => [:test]
5
+
4
6
  task :test do
5
7
  system 'bundle exec ruby test/cbuilder_test.rb'
6
8
  end
@@ -2,14 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "cbuilder"
5
- gem.version = "0.0.1"
5
+ gem.version = "0.0.2"
6
6
  gem.authors = ["Nate Berkopec"]
7
7
  gem.email = ["nate.berkopec@gmail.com"]
8
8
  gem.summary = "Create CSV structures with a Builder-style DSL"
9
9
  gem.homepage = "http://github.com/nateberkopec/cbuilder"
10
10
 
11
+ gem.add_dependency 'rake'
11
12
  gem.add_dependency 'activesupport', '>= 3.0.0'
12
-
13
+
13
14
  gem.files = `git ls-files`.split($\)
14
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -1,9 +1,19 @@
1
- require 'active_support/basic_object'
1
+ begin
2
+ require 'active_support/proxy_object'
3
+ CbuilderProxy = ActiveSupport::ProxyObject
4
+ rescue LoadError
5
+ require 'active_support/basic_object'
6
+ CbuilderProxy = ActiveSupport::BasicObject
7
+ end
8
+
9
+ require 'csv'
10
+ CbuilderCSVProxy = ::RUBY_VERSION > '1.9' ? CSV : FasterCSV
11
+
2
12
  require 'active_support/core_ext/array/access'
3
13
  require 'active_support/core_ext/enumerable'
4
- require 'csv'
5
14
 
6
- class Cbuilder < ActiveSupport::BasicObject
15
+
16
+ class Cbuilder < CbuilderProxy
7
17
  #Yields a builder and automatically turns the result into a CSV file
8
18
  def self.encode(*args)
9
19
  cbuilder = new(*args)
@@ -29,22 +39,13 @@ class Cbuilder < ActiveSupport::BasicObject
29
39
  collection
30
40
  end
31
41
  end
32
-
42
+
33
43
  # Encodes the current builder as CSV.
34
44
  def target!
35
- if ::RUBY_VERSION > '1.9'
36
- ::CSV.generate do |csv|
37
- csv << @headers # header row
38
- @attributes.each do |element| # body rows
39
- csv << (element.nil? ? '' : element)
40
- end
41
- end
42
- else
43
- FasterCSV.generate do |csv|
44
- csv << @headers # pop header row
45
- @attributes.each do |element| # body rows
46
- csv << (element.nil? ? '' : element)
47
- end
45
+ ::CbuilderCSVProxy.generate do |csv|
46
+ csv << @headers # header row
47
+ @attributes.each do |element| # body rows
48
+ csv << (element.nil? ? '' : element)
48
49
  end
49
50
  end
50
51
  end
metadata CHANGED
@@ -1,30 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nate Berkopec
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-06 00:00:00.000000000 Z
11
+ date: 2013-10-14 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: activesupport
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ! '>='
31
+ - - '>='
20
32
  - !ruby/object:Gem::Version
21
33
  version: 3.0.0
22
34
  type: :runtime
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ! '>='
38
+ - - '>='
28
39
  - !ruby/object:Gem::Version
29
40
  version: 3.0.0
30
41
  description:
@@ -35,6 +46,7 @@ extensions: []
35
46
  extra_rdoc_files: []
36
47
  files:
37
48
  - .gitignore
49
+ - .travis.yml
38
50
  - Gemfile
39
51
  - LICENSE
40
52
  - README.md
@@ -45,27 +57,26 @@ files:
45
57
  - test/cbuilder_test.rb
46
58
  homepage: http://github.com/nateberkopec/cbuilder
47
59
  licenses: []
60
+ metadata: {}
48
61
  post_install_message:
49
62
  rdoc_options: []
50
63
  require_paths:
51
64
  - lib
52
65
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
66
  requirements:
55
- - - ! '>='
67
+ - - '>='
56
68
  - !ruby/object:Gem::Version
57
69
  version: '0'
58
70
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
71
  requirements:
61
- - - ! '>='
72
+ - - '>='
62
73
  - !ruby/object:Gem::Version
63
74
  version: '0'
64
75
  requirements: []
65
76
  rubyforge_project:
66
- rubygems_version: 1.8.23
77
+ rubygems_version: 2.0.0
67
78
  signing_key:
68
- specification_version: 3
79
+ specification_version: 4
69
80
  summary: Create CSV structures with a Builder-style DSL
70
81
  test_files:
71
82
  - test/cbuilder_test.rb