comma 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. data/Appraisals +6 -1
  2. data/Gemfile.lock +1 -1
  3. data/README.markdown +42 -2
  4. data/gemfiles/{active3.2.11.gemfile → active3.0.20.gemfile} +2 -2
  5. data/gemfiles/{active3.0.9.gemfile.lock → active3.0.20.gemfile.lock} +17 -17
  6. data/gemfiles/active3.1.12.gemfile.lock +1 -1
  7. data/gemfiles/{active3.0.9.gemfile → active3.2.14.gemfile} +2 -2
  8. data/gemfiles/{active3.2.11.gemfile.lock → active3.2.14.gemfile.lock} +14 -14
  9. data/gemfiles/active4.0.0.gemfile.lock +1 -1
  10. data/gemfiles/{rails3.0.9.gemfile → data_mapper1.2.0.gemfile} +2 -2
  11. data/gemfiles/data_mapper1.2.0.gemfile.lock +101 -0
  12. data/gemfiles/mongoid3.1.4.gemfile.lock +2 -2
  13. data/gemfiles/{rails3.1.1.gemfile → rails3.0.20.gemfile} +1 -1
  14. data/gemfiles/{rails3.0.9.gemfile.lock → rails3.0.20.gemfile.lock} +41 -41
  15. data/gemfiles/rails3.1.12.gemfile.lock +1 -1
  16. data/gemfiles/{rails3.2.11.gemfile → rails3.2.14.gemfile} +1 -1
  17. data/gemfiles/{rails3.2.11.gemfile.lock → rails3.2.14.gemfile.lock} +42 -43
  18. data/gemfiles/rails4.0.0.gemfile.lock +1 -1
  19. data/lib/comma.rb +3 -1
  20. data/lib/comma/data_extractor.rb +78 -0
  21. data/lib/comma/data_mapper_collection.rb +7 -0
  22. data/lib/comma/extractor.rb +36 -0
  23. data/lib/comma/header_extractor.rb +48 -0
  24. data/lib/comma/object.rb +4 -0
  25. data/lib/comma/version.rb +1 -1
  26. data/spec/comma/{extractors_spec.rb → data_extractor_spec.rb} +2 -60
  27. data/spec/comma/header_extractor_spec.rb +68 -0
  28. data/spec/comma/rails/data_mapper_collection_spec.rb +49 -0
  29. metadata +138 -102
  30. checksums.yaml +0 -15
  31. data/gemfiles/active3.1.1.gemfile +0 -9
  32. data/gemfiles/active3.1.1.gemfile.lock +0 -58
  33. data/gemfiles/rails3.1.1.gemfile.lock +0 -124
  34. data/lib/comma/extractors.rb +0 -131
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "fastercsv", :platforms=>:ruby_18
6
- gem "activesupport", "3.1.1"
7
- gem "activerecord", "3.1.1"
8
-
9
- gemspec :path=>"../"
@@ -1,58 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- comma (3.1.0)
5
- activesupport (>= 3.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.1.1)
11
- activesupport (= 3.1.1)
12
- builder (~> 3.0.0)
13
- i18n (~> 0.6)
14
- activerecord (3.1.1)
15
- activemodel (= 3.1.1)
16
- activesupport (= 3.1.1)
17
- arel (~> 2.2.1)
18
- tzinfo (~> 0.3.29)
19
- activesupport (3.1.1)
20
- multi_json (~> 1.0)
21
- appraisal (0.4.1)
22
- bundler
23
- rake
24
- arel (2.2.3)
25
- builder (3.0.0)
26
- diff-lcs (1.1.3)
27
- fastercsv (1.5.4)
28
- i18n (0.6.0)
29
- multi_json (1.1.0)
30
- rake (0.9.2.2)
31
- rspec (2.8.0)
32
- rspec-core (~> 2.8.0)
33
- rspec-expectations (~> 2.8.0)
34
- rspec-mocks (~> 2.8.0)
35
- rspec-core (2.8.0)
36
- rspec-expectations (2.8.0)
37
- diff-lcs (~> 1.1.2)
38
- rspec-mocks (2.8.0)
39
- simplecov (0.6.1)
40
- multi_json (~> 1.0)
41
- simplecov-html (~> 0.5.3)
42
- simplecov-html (0.5.3)
43
- sqlite3 (1.3.5)
44
- tzinfo (0.3.31)
45
-
46
- PLATFORMS
47
- ruby
48
-
49
- DEPENDENCIES
50
- activerecord (= 3.1.1)
51
- activesupport (= 3.1.1)
52
- appraisal (~> 0.4.1)
53
- comma!
54
- fastercsv
55
- rake (~> 0.9.2)
56
- rspec (~> 2.8.0)
57
- simplecov
58
- sqlite3 (~> 1.3.4)
@@ -1,124 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- comma (3.1.0)
5
- activesupport (>= 3.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actionmailer (3.1.1)
11
- actionpack (= 3.1.1)
12
- mail (~> 2.3.0)
13
- actionpack (3.1.1)
14
- activemodel (= 3.1.1)
15
- activesupport (= 3.1.1)
16
- builder (~> 3.0.0)
17
- erubis (~> 2.7.0)
18
- i18n (~> 0.6)
19
- rack (~> 1.3.2)
20
- rack-cache (~> 1.1)
21
- rack-mount (~> 0.8.2)
22
- rack-test (~> 0.6.1)
23
- sprockets (~> 2.0.2)
24
- activemodel (3.1.1)
25
- activesupport (= 3.1.1)
26
- builder (~> 3.0.0)
27
- i18n (~> 0.6)
28
- activerecord (3.1.1)
29
- activemodel (= 3.1.1)
30
- activesupport (= 3.1.1)
31
- arel (~> 2.2.1)
32
- tzinfo (~> 0.3.29)
33
- activeresource (3.1.1)
34
- activemodel (= 3.1.1)
35
- activesupport (= 3.1.1)
36
- activesupport (3.1.1)
37
- multi_json (~> 1.0)
38
- appraisal (0.4.1)
39
- bundler
40
- rake
41
- arel (2.2.3)
42
- builder (3.0.0)
43
- diff-lcs (1.1.3)
44
- erubis (2.7.0)
45
- fastercsv (1.5.4)
46
- hike (1.2.1)
47
- i18n (0.6.0)
48
- json (1.6.5)
49
- mail (2.3.0)
50
- i18n (>= 0.4.0)
51
- mime-types (~> 1.16)
52
- treetop (~> 1.4.8)
53
- mime-types (1.17.2)
54
- multi_json (1.1.0)
55
- polyglot (0.3.3)
56
- rack (1.3.6)
57
- rack-cache (1.1)
58
- rack (>= 0.4)
59
- rack-mount (0.8.3)
60
- rack (>= 1.0.0)
61
- rack-ssl (1.3.2)
62
- rack
63
- rack-test (0.6.1)
64
- rack (>= 1.0)
65
- rails (3.1.1)
66
- actionmailer (= 3.1.1)
67
- actionpack (= 3.1.1)
68
- activerecord (= 3.1.1)
69
- activeresource (= 3.1.1)
70
- activesupport (= 3.1.1)
71
- bundler (~> 1.0)
72
- railties (= 3.1.1)
73
- railties (3.1.1)
74
- actionpack (= 3.1.1)
75
- activesupport (= 3.1.1)
76
- rack-ssl (~> 1.3.2)
77
- rake (>= 0.8.7)
78
- rdoc (~> 3.4)
79
- thor (~> 0.14.6)
80
- rake (0.9.2.2)
81
- rdoc (3.12)
82
- json (~> 1.4)
83
- rspec (2.8.0)
84
- rspec-core (~> 2.8.0)
85
- rspec-expectations (~> 2.8.0)
86
- rspec-mocks (~> 2.8.0)
87
- rspec-core (2.8.0)
88
- rspec-expectations (2.8.0)
89
- diff-lcs (~> 1.1.2)
90
- rspec-mocks (2.8.0)
91
- rspec-rails (2.8.1)
92
- actionpack (>= 3.0)
93
- activesupport (>= 3.0)
94
- railties (>= 3.0)
95
- rspec (~> 2.8.0)
96
- simplecov (0.6.1)
97
- multi_json (~> 1.0)
98
- simplecov-html (~> 0.5.3)
99
- simplecov-html (0.5.3)
100
- sprockets (2.0.3)
101
- hike (~> 1.2)
102
- rack (~> 1.0)
103
- tilt (~> 1.1, != 1.3.0)
104
- sqlite3 (1.3.5)
105
- thor (0.14.6)
106
- tilt (1.3.3)
107
- treetop (1.4.10)
108
- polyglot
109
- polyglot (>= 0.3.1)
110
- tzinfo (0.3.31)
111
-
112
- PLATFORMS
113
- ruby
114
-
115
- DEPENDENCIES
116
- appraisal (~> 0.4.1)
117
- comma!
118
- fastercsv
119
- rails (= 3.1.1)
120
- rake (~> 0.9.2)
121
- rspec (~> 2.8.0)
122
- rspec-rails
123
- simplecov
124
- sqlite3 (~> 1.3.4)
@@ -1,131 +0,0 @@
1
- require 'active_support/core_ext/class/attribute'
2
-
3
- module Comma
4
-
5
- class Extractor
6
-
7
- def initialize(instance, style, formats)
8
- @instance = instance
9
- @style = style
10
- @formats = formats
11
- @results = []
12
- end
13
-
14
- def results
15
- instance_eval &@formats[@style]
16
- @results.map { |r| convert_to_data_value(r) }
17
- end
18
-
19
- def id(*args, &block)
20
- method_missing(:id, *args, &block)
21
- end
22
-
23
- def __use__(style)
24
- # TODO: prevent infinite recursion
25
- instance_eval(&@formats[style])
26
- end
27
-
28
- private
29
-
30
- def convert_to_data_value(result)
31
- result.nil? ? result : result.to_s
32
- end
33
-
34
- end
35
-
36
- class HeaderExtractor < Extractor
37
-
38
- class_attribute :value_humanizer
39
-
40
- DEFAULT_VALUE_HUMANIZER = lambda do |value, model_class|
41
- value.is_a?(String) ? value : value.to_s.humanize
42
- end
43
- self.value_humanizer = DEFAULT_VALUE_HUMANIZER
44
-
45
- def method_missing(sym, *args, &block)
46
- model_class = @instance.class
47
- @results << self.value_humanizer.call(sym, model_class) if args.blank?
48
- args.each do |arg|
49
- case arg
50
- when Hash
51
- arg.each do |k, v|
52
- @results << self.value_humanizer.call(v, get_association_class(model_class, sym))
53
- end
54
- when Symbol
55
- @results << self.value_humanizer.call(arg, get_association_class(model_class, sym))
56
- when String
57
- @results << self.value_humanizer.call(arg, model_class)
58
- else
59
- raise "Unknown header symbol #{arg.inspect}"
60
- end
61
- end
62
- end
63
-
64
- def __static_column__(header = '', &block)
65
- @results << header
66
- end
67
-
68
- private
69
-
70
- def get_association_class(model_class, association)
71
- model_class.respond_to?(:reflect_on_association) ?
72
- model_class.reflect_on_association(association).klass : nil
73
- end
74
- end
75
-
76
- class DataExtractor < Extractor
77
-
78
- def method_missing(sym, *args, &block)
79
- if args.blank?
80
- @results << yield_block_with_value(
81
- extract_value_from_object(@instance, sym), &block)
82
- end
83
-
84
- args.each do |arg|
85
- case arg
86
- when Hash
87
- arg.each do |k, v|
88
- @results << yield_block_with_value(
89
- extract_value_from_object(
90
- get_association(@instance, sym), k), &block)
91
- end
92
- when Symbol
93
- @results << yield_block_with_value(
94
- extract_value_from_object(
95
- get_association(@instance, sym), arg), &block)
96
- when String
97
- @results << yield_block_with_value(
98
- extract_value_from_object(@instance, sym), &block)
99
- else
100
- raise "Unknown data symbol #{arg.inspect}"
101
- end
102
- end
103
- end
104
-
105
- def __static_column__(header = nil, &block)
106
- @results << (block ? yield(@instance) : nil)
107
- end
108
-
109
- private
110
-
111
- def yield_block_with_value(value, &block)
112
- block ? yield(value) : value
113
- end
114
-
115
- def extract_value_from_object(object, method)
116
- object.send(method)
117
- end
118
-
119
- def get_association(model, association_name)
120
- model.send(association_name) || NullAssociation.new
121
- end
122
-
123
- end
124
-
125
- class NullAssociation < Class.const_defined?(:BasicObject) ? ::BasicObject : ::Object
126
- def method_missing(symbol, *args, &block)
127
- nil
128
- end
129
- end
130
-
131
- end