dm-serializer 1.1.0 → 1.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,20 +5,22 @@ source 'http://rubygems.org'
5
5
  SOURCE = ENV.fetch('SOURCE', :git).to_sym
6
6
  REPO_POSTFIX = SOURCE == :path ? '' : '.git'
7
7
  DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
8
- DM_VERSION = '~> 1.1.0'
9
- DO_VERSION = '~> 0.10.2'
8
+ DM_VERSION = '~> 1.2.0.rc1'
9
+ DO_VERSION = '~> 0.10.6'
10
10
  DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
11
11
 
12
- gem 'dm-core', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-core#{REPO_POSTFIX}"
13
- gem 'fastercsv', '~> 1.5.4'
14
- gem 'json', '~> 1.4.6'
12
+ gem 'dm-core', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-core#{REPO_POSTFIX}"
13
+ gem 'fastercsv', '~> 1.5.4'
14
+ gem 'multi_json', '~> 1.0.3'
15
+ gem 'json', '~> 1.5.4', :platforms => [ :ruby_18, :jruby ]
16
+ gem 'json_pure', '~> 1.5.4', :platforms => [ :mswin ]
15
17
 
16
18
  group :development do
17
19
 
18
20
  gem 'dm-validations', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-validations#{REPO_POSTFIX}"
19
- gem 'jeweler', '~> 1.5.2'
20
- gem 'rake', '~> 0.8.7'
21
- gem 'rspec', '~> 1.3.1'
21
+ gem 'jeweler', '~> 1.6.4'
22
+ gem 'rake', '~> 0.9.2'
23
+ gem 'rspec', '~> 1.3.2'
22
24
 
23
25
  end
24
26
 
@@ -32,9 +34,9 @@ end
32
34
  platforms :mri_18 do
33
35
  group :quality do
34
36
 
35
- gem 'rcov', '~> 0.9.9'
36
- gem 'yard', '~> 0.6'
37
- gem 'yardstick', '~> 0.2'
37
+ gem 'rcov', '~> 0.9.10'
38
+ gem 'yard', '~> 0.7.2'
39
+ gem 'yardstick', '~> 0.4'
38
40
 
39
41
  end
40
42
  end
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- gem 'jeweler', '~> 1.5.2'
5
+ gem 'jeweler', '~> 1.6.4'
6
6
  require 'jeweler'
7
7
 
8
8
  Jeweler::Tasks.new do |gem|
@@ -21,5 +21,5 @@ begin
21
21
 
22
22
  FileList['tasks/**/*.rake'].each { |task| import task }
23
23
  rescue LoadError
24
- puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.5.2'
24
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.6.4'
25
25
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0.rc1
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{dm-serializer}
8
- s.version = "1.1.0"
7
+ s.name = "dm-serializer"
8
+ s.version = "1.2.0.rc1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Guy van den Berg"]
12
- s.date = %q{2011-03-16}
13
- s.description = %q{DataMapper plugin for serializing Resources and Collections}
14
- s.email = %q{vandenberg.guy [a] gmail [d] com}
12
+ s.date = "2011-09-09"
13
+ s.description = "DataMapper plugin for serializing Resources and Collections"
14
+ s.email = "vandenberg.guy [a] gmail [d] com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -22,8 +22,6 @@ Gem::Specification.new do |s|
22
22
  "README.rdoc",
23
23
  "Rakefile",
24
24
  "VERSION",
25
- "autotest/discover.rb",
26
- "autotest/dmserializer_rspec.rb",
27
25
  "benchmarks/to_json.rb",
28
26
  "benchmarks/to_xml.rb",
29
27
  "dm-serializer.gemspec",
@@ -54,53 +52,46 @@ Gem::Specification.new do |s|
54
52
  "tasks/yard.rake",
55
53
  "tasks/yardstick.rake"
56
54
  ]
57
- s.homepage = %q{http://github.com/datamapper/dm-serializer}
55
+ s.homepage = "http://github.com/datamapper/dm-serializer"
58
56
  s.require_paths = ["lib"]
59
- s.rubyforge_project = %q{datamapper}
60
- s.rubygems_version = %q{1.6.2}
61
- s.summary = %q{DataMapper plugin for serializing Resources and Collections}
62
- s.test_files = [
63
- "spec/fixtures/cow.rb",
64
- "spec/fixtures/planet.rb",
65
- "spec/fixtures/quan_tum_cat.rb",
66
- "spec/fixtures/vehicle.rb",
67
- "spec/lib/serialization_method_shared_spec.rb",
68
- "spec/public/serializer_spec.rb",
69
- "spec/public/to_csv_spec.rb",
70
- "spec/public/to_json_spec.rb",
71
- "spec/public/to_xml_spec.rb",
72
- "spec/public/to_yaml_spec.rb",
73
- "spec/spec_helper.rb"
74
- ]
57
+ s.rubyforge_project = "datamapper"
58
+ s.rubygems_version = "1.8.10"
59
+ s.summary = "DataMapper plugin for serializing Resources and Collections"
75
60
 
76
61
  if s.respond_to? :specification_version then
77
62
  s.specification_version = 3
78
63
 
79
64
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
80
- s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0"])
65
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
81
66
  s.add_runtime_dependency(%q<fastercsv>, ["~> 1.5.4"])
82
- s.add_runtime_dependency(%q<json>, ["~> 1.4.6"])
83
- s.add_development_dependency(%q<dm-validations>, ["~> 1.1.0"])
84
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
85
- s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
86
- s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
67
+ s.add_runtime_dependency(%q<multi_json>, ["~> 1.0.3"])
68
+ s.add_runtime_dependency(%q<json>, ["~> 1.5.4"])
69
+ s.add_runtime_dependency(%q<json_pure>, ["~> 1.5.4"])
70
+ s.add_development_dependency(%q<dm-validations>, ["~> 1.2.0.rc1"])
71
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
72
+ s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
73
+ s.add_development_dependency(%q<rspec>, ["~> 1.3.2"])
87
74
  else
88
- s.add_dependency(%q<dm-core>, ["~> 1.1.0"])
75
+ s.add_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
89
76
  s.add_dependency(%q<fastercsv>, ["~> 1.5.4"])
90
- s.add_dependency(%q<json>, ["~> 1.4.6"])
91
- s.add_dependency(%q<dm-validations>, ["~> 1.1.0"])
92
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
93
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
94
- s.add_dependency(%q<rspec>, ["~> 1.3.1"])
77
+ s.add_dependency(%q<multi_json>, ["~> 1.0.3"])
78
+ s.add_dependency(%q<json>, ["~> 1.5.4"])
79
+ s.add_dependency(%q<json_pure>, ["~> 1.5.4"])
80
+ s.add_dependency(%q<dm-validations>, ["~> 1.2.0.rc1"])
81
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
82
+ s.add_dependency(%q<rake>, ["~> 0.9.2"])
83
+ s.add_dependency(%q<rspec>, ["~> 1.3.2"])
95
84
  end
96
85
  else
97
- s.add_dependency(%q<dm-core>, ["~> 1.1.0"])
86
+ s.add_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
98
87
  s.add_dependency(%q<fastercsv>, ["~> 1.5.4"])
99
- s.add_dependency(%q<json>, ["~> 1.4.6"])
100
- s.add_dependency(%q<dm-validations>, ["~> 1.1.0"])
101
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
102
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
103
- s.add_dependency(%q<rspec>, ["~> 1.3.1"])
88
+ s.add_dependency(%q<multi_json>, ["~> 1.0.3"])
89
+ s.add_dependency(%q<json>, ["~> 1.5.4"])
90
+ s.add_dependency(%q<json_pure>, ["~> 1.5.4"])
91
+ s.add_dependency(%q<dm-validations>, ["~> 1.2.0.rc1"])
92
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
93
+ s.add_dependency(%q<rake>, ["~> 0.9.2"])
94
+ s.add_dependency(%q<rspec>, ["~> 1.3.2"])
104
95
  end
105
96
  end
106
97
 
@@ -2,9 +2,6 @@ require 'dm-core'
2
2
 
3
3
  module DataMapper
4
4
  module Serializer
5
- def self.dm_validations_loaded?
6
- DataMapper.const_defined?("Validations")
7
- end
8
5
 
9
6
  # Returns propreties to serialize based on :only or :exclude arrays,
10
7
  # if provided :only takes precendence over :exclude
@@ -4,7 +4,6 @@ if RUBY_VERSION >= '1.9.0'
4
4
  require 'csv'
5
5
  else
6
6
  begin
7
- gem 'fastercsv', '~>1.5.0'
8
7
  require 'fastercsv'
9
8
  CSV = FasterCSV
10
9
  rescue LoadError
@@ -62,14 +61,11 @@ module DataMapper
62
61
  end
63
62
  end
64
63
 
65
- if Serializer.dm_validations_loaded?
66
-
64
+ if const_defined?(:Validations)
67
65
  module Validations
68
66
  class ValidationErrors
69
67
  include DataMapper::Serializer::ValidationErrors::ToCsv
70
68
  end
71
69
  end
72
-
73
70
  end
74
-
75
71
  end
@@ -1,6 +1,6 @@
1
1
  require 'dm-serializer/common'
2
2
 
3
- require 'json'
3
+ require 'multi_json'
4
4
 
5
5
  module DataMapper
6
6
  module Serializer
@@ -60,7 +60,7 @@ module DataMapper
60
60
 
61
61
  # default to making JSON
62
62
  if options.fetch(:to_json, true)
63
- result.to_json
63
+ MultiJson.encode(result)
64
64
  else
65
65
  result
66
66
  end
@@ -69,7 +69,7 @@ module DataMapper
69
69
  module ValidationErrors
70
70
  module ToJson
71
71
  def to_json(*args)
72
- DataMapper::Ext::Array.to_hash(errors).to_json
72
+ MultiJson.encode(Hash[ errors ])
73
73
  end
74
74
  end
75
75
  end
@@ -93,14 +93,11 @@ module DataMapper
93
93
  end
94
94
  end
95
95
 
96
- if Serializer.dm_validations_loaded?
97
-
96
+ if const_defined?(:Validations)
98
97
  module Validations
99
98
  class ValidationErrors
100
99
  include DataMapper::Serializer::ValidationErrors::ToJson
101
100
  end
102
101
  end
103
-
104
102
  end
105
-
106
103
  end
@@ -116,13 +116,11 @@ module DataMapper
116
116
  end
117
117
  end
118
118
 
119
- if Serializer.dm_validations_loaded?
120
-
119
+ if const_defined?(:Validations)
121
120
  module Validations
122
121
  class ValidationErrors
123
122
  include DataMapper::Serializer::ValidationErrors::ToXml
124
123
  end
125
124
  end
126
-
127
125
  end
128
126
  end
@@ -2,68 +2,159 @@ require 'dm-serializer/common'
2
2
 
3
3
  module DataMapper
4
4
  module Serializer
5
- # Serialize a Resource to YAML
5
+ TAG_NAME = "ruby/DataMapper,#{DataMapper::VERSION}".freeze
6
+
7
+ # Include a callback to register the YAML output
8
+ #
9
+ # @param [DataMapper::Model] descendant
10
+ #
11
+ # @return [undefined]
6
12
  #
7
- # @return [YAML]
8
- # A YAML representation of this Resource.
9
- def to_yaml(opts_or_emitter = {})
10
- unless opts_or_emitter.is_a?(Hash)
11
- emitter = opts_or_emitter
12
- opts = {}
13
- else
14
- emitter = {}
15
- opts = opts_or_emitter
13
+ # @api private
14
+ def self.included(descendant)
15
+ YAML.add_domain_type(TAG_NAME, descendant.name) do |_tag, values|
16
+ values
16
17
  end
18
+ end
17
19
 
18
- YAML.quick_emit(object_id,emitter) do |out|
19
- out.map(nil,to_yaml_style) do |map|
20
- properties_to_serialize(opts).each do |property|
21
- value = __send__(property.name.to_sym)
22
- map.add(property.name, value.is_a?(Class) ? value.to_s : value)
23
- end
24
-
25
- # add methods
26
- Array(opts[:methods]).each do |meth|
27
- if respond_to?(meth)
28
- map.add(meth.to_sym, __send__(meth))
29
- end
30
- end
31
-
32
- if (additions = instance_variable_get("@yaml_addes"))
33
- additions.each { |k,v| map.add(k.to_s,v) }
34
- end
20
+ # Serialize a Resource to YAML
21
+ #
22
+ # @example
23
+ # yaml = resource.to_yaml # => a valid YAML string
24
+ #
25
+ # @param [Hash] options
26
+ #
27
+ # @return [String]
28
+ #
29
+ # @api public
30
+ def to_yaml(options = {})
31
+ YAML.quick_emit(object_id, options) do |out|
32
+ out.map(to_yaml_type, to_yaml_style) do |map|
33
+ encode_with(map, options.kind_of?(Hash) ? options : {})
35
34
  end
36
35
  end
36
+ end unless YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
37
+
38
+ # A callback to encode the resource in the YAML stream
39
+ #
40
+ # @param [#add] coder
41
+ # handles adding the values to the output
42
+ #
43
+ # @param [Hash] options
44
+ # optional Hash configuring the output
45
+ #
46
+ # @return [undefined]
47
+ #
48
+ # @api public
49
+ def encode_with(coder, options = {})
50
+ coder.tag = to_yaml_type if coder.respond_to?(:tag=)
51
+ coder.style = to_yaml_style if coder.respond_to?(:style=)
52
+
53
+ methods = []
54
+
55
+ methods.concat properties_to_serialize(options).map { |property| property.name }
56
+ methods.concat Array(options[:methods])
57
+
58
+ methods.each do |method|
59
+ coder.add(method.to_s, __send__(method))
60
+ end
37
61
  end
38
62
 
63
+ private
64
+
65
+ # Return the YAML type to use for the output
66
+ #
67
+ # @return [String]
68
+ #
69
+ # @api private
70
+ def to_yaml_type
71
+ "!#{TAG_NAME}:#{model.name}"
72
+ end
73
+
74
+ # Return the YAML style to use for the output
75
+ #
76
+ # @return [Integer]
77
+ #
78
+ # @api private
79
+ def to_yaml_style
80
+ Psych::Nodes::Mapping::ANY
81
+ end if YAML.const_defined?(:ENGINE) && YAML::ENGINE.yamler == 'psych'
82
+
39
83
  module ValidationErrors
40
84
  module ToYaml
85
+
86
+ # Serialize the errors to YAML
87
+ #
88
+ # @example
89
+ # yaml = errors.to_yaml # => a valid YAML string
90
+ #
91
+ # @param [Hash] options
92
+ #
93
+ # @return [String]
94
+ #
95
+ # @api public
41
96
  def to_yaml(*args)
42
- DataMapper::Ext::Array.to_hash(errors).to_yaml(*args)
97
+ Hash[errors].to_yaml(*args)
43
98
  end
44
- end
45
- end
46
99
 
47
- end
100
+ # A callback to encode the errors in the YAML stream
101
+ #
102
+ # @param [#add] coder
103
+ # handles adding the values to the output
104
+ #
105
+ # @return [undefined]
106
+ #
107
+ # @api public
108
+ def encode_with(coder)
109
+ coder.map = Hash[errors]
110
+ end
48
111
 
49
- class Collection
50
- def to_yaml(opts_or_emitter = {})
51
- unless opts_or_emitter.is_a?(Hash)
52
- to_a.to_yaml(opts_or_emitter)
53
- else
54
- # FIXME: Don't double handle the YAML (remove the YAML.load)
55
- to_a.collect { |x| YAML.load(x.to_yaml(opts_or_emitter)) }.to_yaml
56
- end
57
- end
58
- end
112
+ end # module ToYaml
113
+ end # module ValidationErrors
114
+
115
+ module Collection
116
+ module ToYaml
117
+
118
+ # Serialize the collection to YAML
119
+ #
120
+ # @example
121
+ # yaml = collection.to_yaml # => a valid YAML string
122
+ #
123
+ # @param [Hash] options
124
+ #
125
+ # @return [String]
126
+ #
127
+ # @api public
128
+ def to_yaml(*args)
129
+ to_a.to_yaml(*args)
130
+ end
131
+
132
+ # A callback to encode the collection in the YAML stream
133
+ #
134
+ # @param [#add] coder
135
+ # handles adding the values to the output
136
+ #
137
+ # @return [undefined]
138
+ #
139
+ # @api public
140
+ def encode_with(coder)
141
+ coder.seq = to_a
142
+ end
59
143
 
60
- if Serializer.dm_validations_loaded?
144
+ end # module ToYaml
145
+ end # module Collection
146
+ end # module Serializer
61
147
 
148
+ class Collection
149
+ include Serializer::Collection::ToYaml
150
+ end # class Collection
151
+
152
+ if const_defined?(:Validations)
62
153
  module Validations
63
154
  class ValidationErrors
64
155
  include DataMapper::Serializer::ValidationErrors::ToYaml
65
- end
66
- end
67
-
156
+ end # class ValidationErrors
157
+ end # module Validations
68
158
  end
69
- end
159
+
160
+ end # module DataMapper
@@ -31,8 +31,8 @@ share_examples_for 'A serialization method that also serializes core classes' do
31
31
  keys = %w[ id composite name breed ]
32
32
 
33
33
  resources = [
34
- keys.zip([ 1, 2, 'Betsy', 'Jersey' ]).to_hash,
35
- keys.zip([ 89, 34, 'Berta', 'Guernsey' ]).to_hash,
34
+ Hash[ keys.zip([ 1, 2, 'Betsy', 'Jersey' ]) ],
35
+ Hash[ keys.zip([ 89, 34, 'Berta', 'Guernsey' ]) ],
36
36
  ]
37
37
 
38
38
  collection = DataMapper::Collection.new(query, query.model.load(resources, query))
@@ -93,73 +93,87 @@ share_examples_for 'A serialization method' do
93
93
  end
94
94
 
95
95
  it "should only includes properties given to :only option" do
96
- planet = Planet.new(
97
- :name => "Mars",
98
- :aphelion => 249_209_300.4
99
- )
100
-
101
- result = @harness.test(planet, :only => [:name])
102
- result.values_at("name", "aphelion").should == ["Mars", nil]
96
+ pending_if 'Psych provides no way to pass in parameters', @ruby_192 && @to_yaml do
97
+ planet = Planet.new(
98
+ :name => "Mars",
99
+ :aphelion => 249_209_300.4
100
+ )
101
+
102
+ result = @harness.test(planet, :only => [:name])
103
+ result.values_at("name", "aphelion").should == ["Mars", nil]
104
+ end
103
105
  end
104
106
 
105
107
  it "should serialize values returned by an array of methods given to :methods option" do
106
- planet = Planet.new(
107
- :name => "Mars",
108
- :aphelion => 249_209_300.4
109
- )
110
-
111
- result = @harness.test(planet, :methods => [:category, :has_known_form_of_life?])
112
- # XML currently can't serialize ? at the end of method names
113
- boolean_method_name = @harness.method_name == :to_xml ? "has_known_form_of_life" : "has_known_form_of_life?"
114
- result.values_at("category", boolean_method_name).should == ["terrestrial", false]
108
+ pending_if 'Psych provides no way to pass in parameters', @ruby_192 && @to_yaml do
109
+ planet = Planet.new(
110
+ :name => "Mars",
111
+ :aphelion => 249_209_300.4
112
+ )
113
+
114
+ result = @harness.test(planet, :methods => [:category, :has_known_form_of_life?])
115
+ # XML currently can't serialize ? at the end of method names
116
+ boolean_method_name = @harness.method_name == :to_xml ? "has_known_form_of_life" : "has_known_form_of_life?"
117
+ result.values_at("category", boolean_method_name).should == ["terrestrial", false]
118
+ end
115
119
  end
116
120
 
117
121
  it "should serialize values returned by a single method given to :methods option" do
118
- planet = Planet.new(
119
- :name => "Mars",
120
- :aphelion => 249_209_300.4
121
- )
122
-
123
- result = @harness.test(planet, :methods => :category)
124
- result.values_at("category").should == ["terrestrial"]
122
+ pending_if 'Psych provides no way to pass in parameters', @ruby_192 && @to_yaml do
123
+ planet = Planet.new(
124
+ :name => "Mars",
125
+ :aphelion => 249_209_300.4
126
+ )
127
+
128
+ result = @harness.test(planet, :methods => :category)
129
+ result.values_at("category").should == ["terrestrial"]
130
+ end
125
131
  end
126
132
 
127
133
  it "should only include properties given to :only option" do
128
- planet = Planet.new(
129
- :name => "Mars",
130
- :aphelion => 249_209_300.4
131
- )
132
-
133
- result = @harness.test(planet, :only => [:name])
134
- result.values_at("name", "aphelion").should == ["Mars", nil]
134
+ pending_if 'Psych provides no way to pass in parameters', @ruby_192 && @to_yaml do
135
+ planet = Planet.new(
136
+ :name => "Mars",
137
+ :aphelion => 249_209_300.4
138
+ )
139
+
140
+ result = @harness.test(planet, :only => [:name])
141
+ result.values_at("name", "aphelion").should == ["Mars", nil]
142
+ end
135
143
  end
136
144
 
137
145
  it "should exclude properties given to :exclude option" do
138
- planet = Planet.new(
139
- :name => "Mars",
140
- :aphelion => 249_209_300.4
141
- )
142
-
143
- result = @harness.test(planet, :exclude => [:aphelion])
144
- result.values_at("name", "aphelion").should == ["Mars", nil]
146
+ pending_if 'Psych provides no way to pass in parameters', @ruby_192 && @to_yaml do
147
+ planet = Planet.new(
148
+ :name => "Mars",
149
+ :aphelion => 249_209_300.4
150
+ )
151
+
152
+ result = @harness.test(planet, :exclude => [:aphelion])
153
+ result.values_at("name", "aphelion").should == ["Mars", nil]
154
+ end
145
155
  end
146
156
 
147
157
  it "should give higher precendence to :only option over :exclude" do
148
- planet = Planet.new(
149
- :name => "Mars",
150
- :aphelion => 249_209_300.4
151
- )
152
-
153
- result = @harness.test(planet, :only => [:name], :exclude => [:name])
154
- result.values_at("name", "aphelion").should == ["Mars", nil]
158
+ pending_if 'Psych provides no way to pass in parameters', @ruby_192 && @to_yaml do
159
+ planet = Planet.new(
160
+ :name => "Mars",
161
+ :aphelion => 249_209_300.4
162
+ )
163
+
164
+ result = @harness.test(planet, :only => [:name], :exclude => [:name])
165
+ result.values_at("name", "aphelion").should == ["Mars", nil]
166
+ end
155
167
  end
156
168
 
157
169
  it 'should support child associations included via the :methods parameter' do
158
- solar_system = SolarSystem.create(:name => "one")
159
- planet = Planet.new(:name => "earth")
160
- planet.solar_system = solar_system
161
- result = @harness.test(planet, :methods => [:solar_system])
162
- result['solar_system'].values_at('name', 'id').should == ['one', 1]
170
+ pending_if 'Psych provides no way to pass in parameters', @ruby_192 && @to_yaml do
171
+ solar_system = SolarSystem.create(:name => "one")
172
+ planet = Planet.new(:name => "earth")
173
+ planet.solar_system = solar_system
174
+ result = @harness.test(planet, :methods => [:solar_system])
175
+ result['solar_system'].values_at('name', 'id').should == ['one', 1]
176
+ end
163
177
  end
164
178
  end
165
179
 
@@ -183,8 +197,8 @@ share_examples_for 'A serialization method' do
183
197
  keys = %w[ id composite name breed ]
184
198
 
185
199
  resources = [
186
- keys.zip([ 1, 2, 'Betsy', 'Jersey' ]).to_hash,
187
- keys.zip([ 10, 20, 'Berta', 'Guernsey' ]).to_hash,
200
+ Hash[ keys.zip([ 1, 2, 'Betsy', 'Jersey' ]) ],
201
+ Hash[ keys.zip([ 10, 20, 'Berta', 'Guernsey' ]) ],
188
202
  ]
189
203
 
190
204
  collection = DataMapper::Collection.new(query, query.model.load(resources, query))
@@ -269,8 +283,8 @@ share_examples_for 'A serialization method' do
269
283
  planet = Planet.create(:name => 'a')
270
284
  results = @harness.test(planet.errors)
271
285
  results.should == {
272
- "name" => planet.errors[:name],
273
- "solar_system_id" => planet.errors[:solar_system_id]
286
+ "name" => planet.errors[:name].map { |e| e.to_s },
287
+ "solar_system_id" => planet.errors[:solar_system_id].map { |e| e.to_s }
274
288
  }
275
289
  end
276
290
  end
@@ -13,8 +13,8 @@ describe DataMapper::Serializer, '#to_json' do
13
13
  keys = %w[ id composite name breed ]
14
14
 
15
15
  resources = [
16
- keys.zip([ 1, 2, 'Betsy', 'Jersey' ]).to_hash,
17
- keys.zip([ 10, 20, 'Berta', 'Guernsey' ]).to_hash,
16
+ Hash[ keys.zip([ 1, 2, 'Betsy', 'Jersey' ]) ],
17
+ Hash[ keys.zip([ 10, 20, 'Berta', 'Guernsey' ]) ],
18
18
  ]
19
19
 
20
20
  @collection = DataMapper::Collection.new(query, query.model.load(resources, query))
@@ -26,6 +26,9 @@ describe DataMapper::Serializer, '#to_yaml' do
26
26
  process[result]
27
27
  end
28
28
  end.new
29
+
30
+ @ruby_192 = RUBY_VERSION >= '1.9.2'
31
+ @to_yaml = true
29
32
  end
30
33
 
31
34
  it_should_behave_like 'A serialization method'
@@ -1,5 +1,6 @@
1
1
  require 'dm-core/spec/setup'
2
2
  require 'dm-core/spec/lib/adapter_helpers'
3
+ require 'dm-core/spec/lib/pending_helpers'
3
4
 
4
5
  require 'dm-validations' # FIXME: must be required before dm-serializer
5
6
  require 'dm-serializer'
@@ -7,12 +8,6 @@ require 'dm-migrations'
7
8
 
8
9
  require File.expand_path('spec/lib/serialization_method_shared_spec')
9
10
 
10
- class Array
11
- def to_hash
12
- DataMapper::Ext::Array.to_hash(self)
13
- end
14
- end
15
-
16
11
  # require fixture resources
17
12
  SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
18
13
  Pathname.glob((SPEC_ROOT + 'fixtures/**/*.rb').to_s).each { |file| require file }
@@ -27,4 +22,5 @@ DataMapper::Spec.setup
27
22
 
28
23
  Spec::Runner.configure do |config|
29
24
  config.extend(DataMapper::Spec::Adapters::Helpers)
25
+ config.include(DataMapper::Spec::PendingHelpers)
30
26
  end
metadata CHANGED
@@ -1,8 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-serializer
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.1.0
4
+ hash: 15424023
5
+ prerelease: 6
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 0
10
+ - rc
11
+ - 1
12
+ version: 1.2.0.rc1
6
13
  platform: ruby
7
14
  authors:
8
15
  - Guy van den Berg
@@ -10,86 +17,156 @@ autorequire:
10
17
  bindir: bin
11
18
  cert_chain: []
12
19
 
13
- date: 2011-03-16 00:00:00 -07:00
14
- default_executable:
20
+ date: 2011-09-09 00:00:00 Z
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
- name: dm-core
18
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ type: :runtime
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
19
25
  none: false
20
26
  requirements:
21
27
  - - ~>
22
28
  - !ruby/object:Gem::Version
23
- version: 1.1.0
24
- type: :runtime
29
+ hash: 15424023
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 0
34
+ - rc
35
+ - 1
36
+ version: 1.2.0.rc1
25
37
  prerelease: false
26
- version_requirements: *id001
38
+ requirement: *id001
39
+ name: dm-core
27
40
  - !ruby/object:Gem::Dependency
28
- name: fastercsv
29
- requirement: &id002 !ruby/object:Gem::Requirement
41
+ type: :runtime
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
30
43
  none: false
31
44
  requirements:
32
45
  - - ~>
33
46
  - !ruby/object:Gem::Version
47
+ hash: 11
48
+ segments:
49
+ - 1
50
+ - 5
51
+ - 4
34
52
  version: 1.5.4
35
- type: :runtime
36
53
  prerelease: false
37
- version_requirements: *id002
54
+ requirement: *id002
55
+ name: fastercsv
38
56
  - !ruby/object:Gem::Dependency
39
- name: json
40
- requirement: &id003 !ruby/object:Gem::Requirement
57
+ type: :runtime
58
+ version_requirements: &id003 !ruby/object:Gem::Requirement
41
59
  none: false
42
60
  requirements:
43
61
  - - ~>
44
62
  - !ruby/object:Gem::Version
45
- version: 1.4.6
46
- type: :runtime
63
+ hash: 17
64
+ segments:
65
+ - 1
66
+ - 0
67
+ - 3
68
+ version: 1.0.3
47
69
  prerelease: false
48
- version_requirements: *id003
70
+ requirement: *id003
71
+ name: multi_json
49
72
  - !ruby/object:Gem::Dependency
50
- name: dm-validations
51
- requirement: &id004 !ruby/object:Gem::Requirement
73
+ type: :runtime
74
+ version_requirements: &id004 !ruby/object:Gem::Requirement
52
75
  none: false
53
76
  requirements:
54
77
  - - ~>
55
78
  - !ruby/object:Gem::Version
56
- version: 1.1.0
57
- type: :development
79
+ hash: 11
80
+ segments:
81
+ - 1
82
+ - 5
83
+ - 4
84
+ version: 1.5.4
58
85
  prerelease: false
59
- version_requirements: *id004
86
+ requirement: *id004
87
+ name: json
60
88
  - !ruby/object:Gem::Dependency
61
- name: jeweler
62
- requirement: &id005 !ruby/object:Gem::Requirement
89
+ type: :runtime
90
+ version_requirements: &id005 !ruby/object:Gem::Requirement
63
91
  none: false
64
92
  requirements:
65
93
  - - ~>
66
94
  - !ruby/object:Gem::Version
67
- version: 1.5.2
68
- type: :development
95
+ hash: 11
96
+ segments:
97
+ - 1
98
+ - 5
99
+ - 4
100
+ version: 1.5.4
69
101
  prerelease: false
70
- version_requirements: *id005
102
+ requirement: *id005
103
+ name: json_pure
71
104
  - !ruby/object:Gem::Dependency
72
- name: rake
73
- requirement: &id006 !ruby/object:Gem::Requirement
105
+ type: :development
106
+ version_requirements: &id006 !ruby/object:Gem::Requirement
74
107
  none: false
75
108
  requirements:
76
109
  - - ~>
77
110
  - !ruby/object:Gem::Version
78
- version: 0.8.7
111
+ hash: 15424023
112
+ segments:
113
+ - 1
114
+ - 2
115
+ - 0
116
+ - rc
117
+ - 1
118
+ version: 1.2.0.rc1
119
+ prerelease: false
120
+ requirement: *id006
121
+ name: dm-validations
122
+ - !ruby/object:Gem::Dependency
79
123
  type: :development
124
+ version_requirements: &id007 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ~>
128
+ - !ruby/object:Gem::Version
129
+ hash: 7
130
+ segments:
131
+ - 1
132
+ - 6
133
+ - 4
134
+ version: 1.6.4
80
135
  prerelease: false
81
- version_requirements: *id006
136
+ requirement: *id007
137
+ name: jeweler
82
138
  - !ruby/object:Gem::Dependency
83
- name: rspec
84
- requirement: &id007 !ruby/object:Gem::Requirement
139
+ type: :development
140
+ version_requirements: &id008 !ruby/object:Gem::Requirement
85
141
  none: false
86
142
  requirements:
87
143
  - - ~>
88
144
  - !ruby/object:Gem::Version
89
- version: 1.3.1
145
+ hash: 63
146
+ segments:
147
+ - 0
148
+ - 9
149
+ - 2
150
+ version: 0.9.2
151
+ prerelease: false
152
+ requirement: *id008
153
+ name: rake
154
+ - !ruby/object:Gem::Dependency
90
155
  type: :development
156
+ version_requirements: &id009 !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ~>
160
+ - !ruby/object:Gem::Version
161
+ hash: 31
162
+ segments:
163
+ - 1
164
+ - 3
165
+ - 2
166
+ version: 1.3.2
91
167
  prerelease: false
92
- version_requirements: *id007
168
+ requirement: *id009
169
+ name: rspec
93
170
  description: DataMapper plugin for serializing Resources and Collections
94
171
  email: vandenberg.guy [a] gmail [d] com
95
172
  executables: []
@@ -105,8 +182,6 @@ files:
105
182
  - README.rdoc
106
183
  - Rakefile
107
184
  - VERSION
108
- - autotest/discover.rb
109
- - autotest/dmserializer_rspec.rb
110
185
  - benchmarks/to_json.rb
111
186
  - benchmarks/to_xml.rb
112
187
  - dm-serializer.gemspec
@@ -136,7 +211,6 @@ files:
136
211
  - tasks/spec.rake
137
212
  - tasks/yard.rake
138
213
  - tasks/yardstick.rake
139
- has_rdoc: true
140
214
  homepage: http://github.com/datamapper/dm-serializer
141
215
  licenses: []
142
216
 
@@ -150,29 +224,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
224
  requirements:
151
225
  - - ">="
152
226
  - !ruby/object:Gem::Version
227
+ hash: 3
228
+ segments:
229
+ - 0
153
230
  version: "0"
154
231
  required_rubygems_version: !ruby/object:Gem::Requirement
155
232
  none: false
156
233
  requirements:
157
- - - ">="
234
+ - - ">"
158
235
  - !ruby/object:Gem::Version
159
- version: "0"
236
+ hash: 25
237
+ segments:
238
+ - 1
239
+ - 3
240
+ - 1
241
+ version: 1.3.1
160
242
  requirements: []
161
243
 
162
244
  rubyforge_project: datamapper
163
- rubygems_version: 1.6.2
245
+ rubygems_version: 1.8.10
164
246
  signing_key:
165
247
  specification_version: 3
166
248
  summary: DataMapper plugin for serializing Resources and Collections
167
- test_files:
168
- - spec/fixtures/cow.rb
169
- - spec/fixtures/planet.rb
170
- - spec/fixtures/quan_tum_cat.rb
171
- - spec/fixtures/vehicle.rb
172
- - spec/lib/serialization_method_shared_spec.rb
173
- - spec/public/serializer_spec.rb
174
- - spec/public/to_csv_spec.rb
175
- - spec/public/to_json_spec.rb
176
- - spec/public/to_xml_spec.rb
177
- - spec/public/to_yaml_spec.rb
178
- - spec/spec_helper.rb
249
+ test_files: []
250
+
@@ -1,3 +0,0 @@
1
- Autotest.add_discovery do
2
- "dmserializer"
3
- end
@@ -1,108 +0,0 @@
1
- require 'autotest'
2
-
3
- $VERBOSE = false
4
-
5
- class RspecCommandError < StandardError; end
6
-
7
- # Autotest has no full-blown snake_case to CamelCase
8
- class Autotest::DmserializerRspec < Autotest
9
- WHOLE_SUITE_REGEXP = %r{^spec/(unit|integration)/.*_spec\.rb}
10
-
11
- Autotest.add_hook :initialize do |at|
12
- at.clear_mappings
13
- at.add_exception(/\.git|TAGS/)
14
-
15
- # Updating a spec runs that spec.
16
- at.add_mapping(%r{^spec/.*_spec\.rb$}) do |filename, _|
17
- filename
18
- end
19
-
20
- # Updating spec helper runs the whole suite.
21
- at.add_mapping(%r{^spec/spec_helper\.rb}) do |_, m|
22
- at.files_matching WHOLE_SUITE_REGEXP
23
- end
24
-
25
- # Updating of library file runs the whole suite.
26
- at.add_mapping(%r{^lib/.*\.rb}) do |_, m|
27
- at.files_matching WHOLE_SUITE_REGEXP
28
- end
29
-
30
- # Updating of fixture resources runs the whole suite.
31
- at.add_mapping(%r{^spec/fixtures/.*\.rb}) do |_, m|
32
- at.files_matching WHOLE_SUITE_REGEXP
33
- end
34
- end
35
-
36
-
37
- def initialize(kernel = Kernel, separator = File::SEPARATOR, alt_separator = File::ALT_SEPARATOR) # :nodoc:
38
- super() # need parens so that Ruby doesn't pass our args
39
- # to the superclass version which takes none..
40
-
41
- @kernel, @separator, @alt_separator = kernel, separator, alt_separator
42
- @spec_command = spec_command
43
- end
44
-
45
- attr_accessor :failures
46
-
47
- def failed_results(results)
48
- results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
49
- end
50
-
51
- def handle_results(results)
52
- @failures = failed_results(results)
53
- @files_to_test = consolidate_failures @failures
54
- unless $TESTING
55
- if @files_to_test.empty?
56
- hook :green
57
- else
58
- hook :red
59
- end
60
- end
61
- @tainted = true unless @files_to_test.empty?
62
- end
63
-
64
- def consolidate_failures(failed)
65
- filters = Hash.new { |h,k| h[k] = [] }
66
- failed.each do |spec, failed_trace|
67
- find_files.keys.select { |f| f =~ /spec\// }.each do |f|
68
- if failed_trace =~ Regexp.new(f)
69
- filters[f] << spec
70
- break
71
- end
72
- end
73
- end
74
- filters
75
- end
76
-
77
- def make_test_cmd(files_to_test)
78
- "#{ruby} -S #{@spec_command} #{test_cmd_options} #{files_to_test.keys.flatten.join(' ')}"
79
- end
80
-
81
- def test_cmd_options
82
- # '-O specs/spec.opts' if File.exist?('specs/spec.opts')
83
- end
84
-
85
- # Finds the proper spec command to use. Precendence is set in the
86
- # lazily-evaluated method spec_commands. Alias + Override that in
87
- # ~/.autotest to provide a different spec command then the default
88
- # paths provided.
89
- def spec_command(separator=File::ALT_SEPARATOR)
90
- unless defined?(@spec_command)
91
- @spec_command = spec_commands.find { |cmd| File.exists?(cmd) }
92
-
93
- raise RspecCommandError, "No spec command could be found" unless @spec_command
94
-
95
- @spec_command.gsub!(File::SEPARATOR, separator) if separator
96
- end
97
- @spec_command
98
- end
99
-
100
- # Autotest will look for spec commands in the following
101
- # locations, in this order:
102
- #
103
- # * default spec bin/loader installed in Rubygems
104
- # * any spec command found in PATH
105
- def spec_commands
106
- [File.join(Config::CONFIG['bindir'], 'spec'), 'spec']
107
- end
108
- end