dm-serializer 1.0.2 → 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,115 +1,52 @@
1
- # If you're working on more than one datamapper gem at a time, then it's
2
- # recommended to create a local Gemfile and use this instead of the git
3
- # sources. This will make sure that you are developing against your
4
- # other local datamapper sources that you currently work on. Gemfile.local
5
- # will behave identically to the standard Gemfile apart from the fact that
6
- # it fetches the datamapper gems from local paths. This means that you can use
7
- # the same environment variables, like ADAPTER(S) or PLUGIN(S) when running
8
- # bundle commands. Gemfile.local is added to .gitignore, so you don't need to
9
- # worry about accidentally checking local development paths into git.
10
- # In order to create a local Gemfile, all you need to do is run:
11
- #
12
- # bundle exec rake local_gemfile
13
- #
14
- # This will give you a Gemfile.local file that points to your local clones of
15
- # the various datamapper gems. It's assumed that all datamapper repo clones
16
- # reside in the same directory. You can use the Gemfile.local like so for
17
- # running any bundle command:
18
- #
19
- # BUNDLE_GEMFILE=Gemfile.local bundle foo
20
- #
21
- # You can also specify which adapter(s) should be part of the bundle by setting
22
- # an environment variable. This of course also works when using the Gemfile.local
23
- #
24
- # bundle foo # dm-sqlite-adapter
25
- # ADAPTER=mysql bundle foo # dm-mysql-adapter
26
- # ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter and dm-mysql-adapter
27
- #
28
- # Of course you can also use the ADAPTER(S) variable when using the Gemfile.local
29
- # and running specs against selected adapters.
30
- #
31
- # For easily working with adapters supported on your machine, it's recommended
32
- # that you first install all adapters that you are planning to use or work on
33
- # by doing something like
34
- #
35
- # ADAPTERS=sqlite,mysql,postgres bundle install
36
- #
37
- # This will clone the various repositories and make them available to bundler.
38
- # Once you have them installed you can easily switch between adapters for the
39
- # various development tasks. Running something like
40
- #
41
- # ADAPTER=mysql bundle exec rake spec
42
- #
43
- # will make sure that the dm-mysql-adapter is part of the bundle, and will be used
44
- # when running the specs.
45
- #
46
- # You can also specify which plugin(s) should be part of the bundle by setting
47
- # an environment variable. This also works when using the Gemfile.local
48
- #
49
- # bundle foo # dm-migrations
50
- # PLUGINS=dm-validations bundle foo # dm-migrations and dm-validations
51
- # PLUGINS=dm-validations,dm-types bundle foo # dm-migrations, dm-validations and dm-types
52
- #
53
- # Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run specs
54
- # for certain adapter/plugin combinations.
55
- #
56
- # Finally, to speed up running specs and other tasks, it's recommended to run
57
- #
58
- # bundle lock
59
- #
60
- # after running 'bundle install' for the first time. This will make 'bundle exec' run
61
- # a lot faster compared to the unlocked version. With an unlocked bundle you would
62
- # typically just run 'bundle install' from time to time to fetch the latest sources from
63
- # upstream. When you locked your bundle, you need to run
64
- #
65
- # bundle install --relock
66
- #
67
- # to make sure to fetch the latest updates and then lock the bundle again. Gemfile.lock
68
- # is added to the .gitignore file, so you don't need to worry about accidentally checking
69
- # it into version control.
1
+ require 'pathname'
70
2
 
71
3
  source 'http://rubygems.org'
72
4
 
73
- DATAMAPPER = 'git://github.com/datamapper'
74
- DM_VERSION = '~> 1.0.2'
5
+ SOURCE = ENV.fetch('SOURCE', :git).to_sym
6
+ REPO_POSTFIX = SOURCE == :path ? '' : '.git'
7
+ DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
8
+ DM_VERSION = '~> 1.1.0.rc1'
75
9
 
76
- group :runtime do # Runtime dependencies (as in the gemspec)
10
+ group :runtime do
77
11
 
78
12
  if ENV['EXTLIB']
79
- gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
13
+ gem 'extlib', '~> 0.9.15', SOURCE => "#{DATAMAPPER}/extlib#{REPO_POSTFIX}", :require => nil
80
14
  else
81
- gem 'activesupport', '~> 3.0.0', :git => 'git://github.com/rails/rails.git', :branch => '3-0-stable', :require => nil
15
+ gem 'activesupport', '~> 3.0.4', :require => nil
16
+ gem 'i18n', '~> 0.5.0'
82
17
  end
83
18
 
84
- gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
19
+ gem 'dm-core', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-core#{REPO_POSTFIX}"
85
20
  gem 'fastercsv', '~> 1.5.3'
86
- gem 'json_pure', '~> 1.4.3'
21
+ gem 'json', '~> 1.5.1'
87
22
 
88
23
  end
89
24
 
90
- group(:development) do # Development dependencies (as in the gemspec)
91
-
92
- gem 'dm-validations', DM_VERSION, :git => "#{DATAMAPPER}/dm-validations.git"
93
- gem 'nokogiri', '~> 1.4.1'
25
+ group :development do
94
26
 
27
+ gem 'dm-validations', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-validations#{REPO_POSTFIX}"
28
+ gem 'jeweler', '~> 1.5.2'
95
29
  gem 'rake', '~> 0.8.7'
96
- gem 'rspec', '~> 1.3', :git => 'git://github.com/snusnu/rspec', :branch => 'heckle_fix_plus_gemfile'
97
- gem 'jeweler', '~> 1.4'
30
+ gem 'rspec', '~> 1.3.1'
31
+
32
+ end
33
+
34
+ group :testing do
35
+
36
+ gem 'nokogiri', '~> 1.4.1'
37
+ gem 'libxml-ruby', '~> 1.1.4', :platforms => [ :mri, :mswin ]
98
38
 
99
39
  end
100
40
 
101
- group :quality do # These gems contain rake tasks that check the quality of the source code
41
+ group :quality do
102
42
 
103
- gem 'metric_fu', '~> 1.3'
104
- gem 'rcov', '~> 0.9.8'
105
- gem 'reek', '~> 1.2.8'
106
- gem 'roodi', '~> 2.1'
107
- gem 'yard', '~> 0.5'
108
- gem 'yardstick', '~> 0.1'
43
+ gem 'rcov', '~> 0.9.9', :platforms => :mri_18
44
+ gem 'yard', '~> 0.6'
45
+ gem 'yardstick', '~> 0.2'
109
46
 
110
47
  end
111
48
 
112
- group :datamapper do # We need this because we want to pin these dependencies to their git master sources
49
+ group :datamapper do
113
50
 
114
51
  adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
115
52
  adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
@@ -119,27 +56,27 @@ group :datamapper do # We need this because we want to pin these dependencies to
119
56
 
120
57
  if (do_adapters = DM_DO_ADAPTERS & adapters).any?
121
58
  options = {}
122
- options[:git] = "#{DATAMAPPER}/do.git" if ENV['DO_GIT'] == 'true'
59
+ options[:git] = "#{DATAMAPPER}/do#{REPO_POSTFIX}" if ENV['DO_GIT'] == 'true'
123
60
 
124
- gem 'data_objects', DO_VERSION, options.dup
61
+ gem 'data_objects', DO_VERSION, options.dup
125
62
 
126
63
  do_adapters.each do |adapter|
127
64
  adapter = 'sqlite3' if adapter == 'sqlite'
128
65
  gem "do_#{adapter}", DO_VERSION, options.dup
129
66
  end
130
67
 
131
- gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
68
+ gem 'dm-do-adapter', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-do-adapter#{REPO_POSTFIX}"
132
69
  end
133
70
 
134
71
  adapters.each do |adapter|
135
- gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
72
+ gem "dm-#{adapter}-adapter", DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-#{adapter}-adapter#{REPO_POSTFIX}"
136
73
  end
137
74
 
138
75
  plugins = ENV['PLUGINS'] || ENV['PLUGIN']
139
76
  plugins = plugins.to_s.tr(',', ' ').split.push('dm-migrations').uniq
140
77
 
141
78
  plugins.each do |plugin|
142
- gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
79
+ gem plugin, DM_VERSION, SOURCE => "#{DATAMAPPER}/#{plugin}#{REPO_POSTFIX}"
143
80
  end
144
81
 
145
82
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Guy van den Berg
1
+ Copyright (c) 2011 Guy van den Berg
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- gem 'jeweler', '~> 1.4'
5
+ gem 'jeweler', '~> 1.5.2'
6
6
  require 'jeweler'
7
7
 
8
8
  Jeweler::Tasks.new do |gem|
@@ -15,20 +15,11 @@ begin
15
15
  gem.has_rdoc = 'yard'
16
16
 
17
17
  gem.rubyforge_project = 'datamapper'
18
-
19
- gem.add_dependency 'dm-core', '~> 1.0.2'
20
- gem.add_dependency 'fastercsv', '~> 1.5.3'
21
- gem.add_dependency 'json_pure', '~> 1.4'
22
-
23
- gem.add_development_dependency 'rspec', '~> 1.3'
24
- gem.add_development_dependency 'dm-validations', '~> 1.0.2'
25
- gem.add_development_dependency 'nokogiri', '~> 1.4.3'
26
- # gem.add_development_dependency 'libxml-ruby', '~> 1.1.4' # not available on JRuby
27
18
  end
28
19
 
29
20
  Jeweler::GemcutterTasks.new
30
21
 
31
22
  FileList['tasks/**/*.rake'].each { |task| import task }
32
23
  rescue LoadError
33
- puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
24
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.5.2'
34
25
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.1.0.rc1
@@ -1,108 +1,112 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-serializer}
8
- s.version = "1.0.2"
8
+ s.version = "1.1.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{2010-09-07}
12
+ s.date = %q{2011-02-28}
13
13
  s.description = %q{DataMapper plugin for serializing Resources and Collections}
14
14
  s.email = %q{vandenberg.guy [a] gmail [d] com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
21
- "Gemfile",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "autotest/discover.rb",
27
- "autotest/dmserializer_rspec.rb",
28
- "benchmarks/to_json.rb",
29
- "benchmarks/to_xml.rb",
30
- "dm-serializer.gemspec",
31
- "lib/dm-serializer.rb",
32
- "lib/dm-serializer/common.rb",
33
- "lib/dm-serializer/to_csv.rb",
34
- "lib/dm-serializer/to_json.rb",
35
- "lib/dm-serializer/to_xml.rb",
36
- "lib/dm-serializer/to_yaml.rb",
37
- "lib/dm-serializer/xml_serializers.rb",
38
- "lib/dm-serializer/xml_serializers/libxml.rb",
39
- "lib/dm-serializer/xml_serializers/nokogiri.rb",
40
- "lib/dm-serializer/xml_serializers/rexml.rb",
41
- "spec/fixtures/cow.rb",
42
- "spec/fixtures/planet.rb",
43
- "spec/fixtures/quan_tum_cat.rb",
44
- "spec/lib/serialization_method_shared_spec.rb",
45
- "spec/public/serializer_spec.rb",
46
- "spec/public/to_csv_spec.rb",
47
- "spec/public/to_json_spec.rb",
48
- "spec/public/to_xml_spec.rb",
49
- "spec/public/to_yaml_spec.rb",
50
- "spec/rcov.opts",
51
- "spec/spec.opts",
52
- "spec/spec_helper.rb",
53
- "tasks/ci.rake",
54
- "tasks/local_gemfile.rake",
55
- "tasks/metrics.rake",
56
- "tasks/spec.rake",
57
- "tasks/yard.rake",
58
- "tasks/yardstick.rake"
20
+ "Gemfile",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "autotest/discover.rb",
26
+ "autotest/dmserializer_rspec.rb",
27
+ "benchmarks/to_json.rb",
28
+ "benchmarks/to_xml.rb",
29
+ "dm-serializer.gemspec",
30
+ "lib/dm-serializer.rb",
31
+ "lib/dm-serializer/common.rb",
32
+ "lib/dm-serializer/to_csv.rb",
33
+ "lib/dm-serializer/to_json.rb",
34
+ "lib/dm-serializer/to_xml.rb",
35
+ "lib/dm-serializer/to_yaml.rb",
36
+ "lib/dm-serializer/xml_serializers.rb",
37
+ "lib/dm-serializer/xml_serializers/libxml.rb",
38
+ "lib/dm-serializer/xml_serializers/nokogiri.rb",
39
+ "lib/dm-serializer/xml_serializers/rexml.rb",
40
+ "spec/fixtures/cow.rb",
41
+ "spec/fixtures/planet.rb",
42
+ "spec/fixtures/quan_tum_cat.rb",
43
+ "spec/fixtures/vehicle.rb",
44
+ "spec/lib/serialization_method_shared_spec.rb",
45
+ "spec/public/serializer_spec.rb",
46
+ "spec/public/to_csv_spec.rb",
47
+ "spec/public/to_json_spec.rb",
48
+ "spec/public/to_xml_spec.rb",
49
+ "spec/public/to_yaml_spec.rb",
50
+ "spec/rcov.opts",
51
+ "spec/spec.opts",
52
+ "spec/spec_helper.rb",
53
+ "tasks/spec.rake",
54
+ "tasks/yard.rake",
55
+ "tasks/yardstick.rake"
59
56
  ]
60
- s.has_rdoc = %q{yard}
61
57
  s.homepage = %q{http://github.com/datamapper/dm-serializer}
62
- s.rdoc_options = ["--charset=UTF-8"]
63
58
  s.require_paths = ["lib"]
64
59
  s.rubyforge_project = %q{datamapper}
65
- s.rubygems_version = %q{1.3.7}
60
+ s.rubygems_version = %q{1.5.2}
66
61
  s.summary = %q{DataMapper plugin for serializing Resources and Collections}
67
62
  s.test_files = [
68
63
  "spec/fixtures/cow.rb",
69
- "spec/fixtures/planet.rb",
70
- "spec/fixtures/quan_tum_cat.rb",
71
- "spec/lib/serialization_method_shared_spec.rb",
72
- "spec/public/serializer_spec.rb",
73
- "spec/public/to_csv_spec.rb",
74
- "spec/public/to_json_spec.rb",
75
- "spec/public/to_xml_spec.rb",
76
- "spec/public/to_yaml_spec.rb",
77
- "spec/spec_helper.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"
78
74
  ]
79
75
 
80
76
  if s.respond_to? :specification_version then
81
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
82
77
  s.specification_version = 3
83
78
 
84
79
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
85
- s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.2"])
80
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.4"])
81
+ s.add_runtime_dependency(%q<i18n>, ["~> 0.5.0"])
82
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0.rc1"])
86
83
  s.add_runtime_dependency(%q<fastercsv>, ["~> 1.5.3"])
87
- s.add_runtime_dependency(%q<json_pure>, ["~> 1.4"])
88
- s.add_development_dependency(%q<rspec>, ["~> 1.3"])
89
- s.add_development_dependency(%q<dm-validations>, ["~> 1.0.2"])
90
- s.add_development_dependency(%q<nokogiri>, ["~> 1.4.3"])
84
+ s.add_runtime_dependency(%q<json>, ["~> 1.5.1"])
85
+ s.add_development_dependency(%q<dm-validations>, ["~> 1.1.0.rc1"])
86
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
87
+ s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
88
+ s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
91
89
  else
92
- s.add_dependency(%q<dm-core>, ["~> 1.0.2"])
90
+ s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
91
+ s.add_dependency(%q<i18n>, ["~> 0.5.0"])
92
+ s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc1"])
93
93
  s.add_dependency(%q<fastercsv>, ["~> 1.5.3"])
94
- s.add_dependency(%q<json_pure>, ["~> 1.4"])
95
- s.add_dependency(%q<rspec>, ["~> 1.3"])
96
- s.add_dependency(%q<dm-validations>, ["~> 1.0.2"])
97
- s.add_dependency(%q<nokogiri>, ["~> 1.4.3"])
94
+ s.add_dependency(%q<json>, ["~> 1.5.1"])
95
+ s.add_dependency(%q<dm-validations>, ["~> 1.1.0.rc1"])
96
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
97
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
98
+ s.add_dependency(%q<rspec>, ["~> 1.3.1"])
98
99
  end
99
100
  else
100
- s.add_dependency(%q<dm-core>, ["~> 1.0.2"])
101
+ s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
102
+ s.add_dependency(%q<i18n>, ["~> 0.5.0"])
103
+ s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc1"])
101
104
  s.add_dependency(%q<fastercsv>, ["~> 1.5.3"])
102
- s.add_dependency(%q<json_pure>, ["~> 1.4"])
103
- s.add_dependency(%q<rspec>, ["~> 1.3"])
104
- s.add_dependency(%q<dm-validations>, ["~> 1.0.2"])
105
- s.add_dependency(%q<nokogiri>, ["~> 1.4.3"])
105
+ s.add_dependency(%q<json>, ["~> 1.5.1"])
106
+ s.add_dependency(%q<dm-validations>, ["~> 1.1.0.rc1"])
107
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
108
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
109
+ s.add_dependency(%q<rspec>, ["~> 1.3.1"])
106
110
  end
107
111
  end
108
112
 
@@ -15,12 +15,14 @@ module DataMapper
15
15
  #
16
16
  # @since 1.0.1
17
17
  #
18
- def as_json(options={})
19
- result = {}
18
+ def as_json(options = {})
19
+ options = {} if options.nil?
20
+ result = {}
20
21
 
21
22
  properties_to_serialize(options).each do |property|
22
23
  property_name = property.name
23
- result[property_name] = __send__(property_name)
24
+ value = __send__(property_name)
25
+ result[property_name] = value.kind_of?(DataMapper::Model) ? value.name : value
24
26
  end
25
27
 
26
28
  # add methods
@@ -45,8 +47,8 @@ module DataMapper
45
47
  #
46
48
  # @return <String> a JSON representation of the Resource
47
49
  def to_json(*args)
48
- options = args.first || {}
49
- options = options.to_h if options.respond_to?(:to_h)
50
+ options = args.first
51
+ options = {} unless options.kind_of?(Hash)
50
52
 
51
53
  result = as_json(options)
52
54
 
@@ -68,33 +70,16 @@ module DataMapper
68
70
 
69
71
  end
70
72
 
71
-
72
- module Associations
73
- # the json gem adds Object#to_json, which breaks the DM proxies, since it
74
- # happens *after* the proxy has been blank slated. This code removes the added
75
- # method, so it is delegated correctly to the Collection
76
- proxies = []
77
-
78
- proxies << ManyToMany::Proxy if defined?(ManyToMany::Proxy)
79
- proxies << OneToMany::Proxy if defined?(OneToMany::Proxy)
80
- proxies << ManyToOne::Proxy if defined?(ManyToOne::Proxy)
81
-
82
- proxies.each do |proxy|
83
- if proxy.public_instance_methods.any? { |m| m.to_sym == :to_json }
84
- proxy.send(:undef_method, :to_json)
85
- end
86
- end
87
- end
88
-
89
73
  class Collection
90
74
  def to_json(*args)
91
- opts = args.first || {}
75
+ options = args.first
76
+ options = {} unless options.kind_of?(Hash)
92
77
 
93
- options = opts.merge(:to_json => false)
94
- collection = map { |e| e.to_json(options) }
78
+ resource_options = options.merge(:to_json => false)
79
+ collection = map { |resource| resource.to_json(resource_options) }
95
80
 
96
81
  # default to making JSON
97
- if opts.fetch(:to_json, true)
82
+ if options.fetch(:to_json, true)
98
83
  collection.to_json
99
84
  else
100
85
  collection
@@ -29,7 +29,7 @@ module DataMapper
29
29
  xml.add_node(root, property.name.to_s, value, attrs)
30
30
  end
31
31
 
32
- (opts[:methods] || []).each do |meth|
32
+ Array(opts[:methods]).each do |meth|
33
33
  if self.respond_to?(meth)
34
34
  xml_name = meth.to_s.gsub(/[^a-z0-9_]/, '')
35
35
  value = __send__(meth)
@@ -21,7 +21,7 @@ module DataMapper
21
21
  map.add(property.name, value.is_a?(Class) ? value.to_s : value)
22
22
  end
23
23
  # add methods
24
- (opts[:methods] || []).each do |meth|
24
+ Array(opts[:methods]).each do |meth|
25
25
  if respond_to?(meth)
26
26
  map.add(meth.to_sym, __send__(meth))
27
27
  end
@@ -0,0 +1,14 @@
1
+ class Vehicle
2
+ include DataMapper::Resource
3
+ property :id, Serial
4
+ property :name, String
5
+ property :type, Discriminator
6
+ end
7
+
8
+ class Car < Vehicle
9
+
10
+ end
11
+
12
+ class Motorcycle < Vehicle
13
+
14
+ end
@@ -102,7 +102,7 @@ share_examples_for 'A serialization method' do
102
102
  result.values_at("name", "aphelion").should == ["Mars", nil]
103
103
  end
104
104
 
105
- it "should serialize values returned by methods given to :methods option" do
105
+ it "should serialize values returned by an array of methods given to :methods option" do
106
106
  planet = Planet.new(
107
107
  :name => "Mars",
108
108
  :aphelion => 249_209_300.4
@@ -114,6 +114,16 @@ share_examples_for 'A serialization method' do
114
114
  result.values_at("category", boolean_method_name).should == ["terrestrial", false]
115
115
  end
116
116
 
117
+ 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"]
125
+ end
126
+
117
127
  it "should only include properties given to :only option" do
118
128
  planet = Planet.new(
119
129
  :name => "Mars",
@@ -57,4 +57,19 @@ describe DataMapper::Serialize, '#to_json' do
57
57
 
58
58
  it "has :repository option to override used repository"
59
59
 
60
+ it "can be serialized within a Hash" do
61
+ hash = { 'cows' => Cow.all }
62
+ JSON.parse(hash.to_json).should == hash
63
+ end
64
+
65
+ end
66
+
67
+ describe DataMapper::Serialize, '#as_json' do
68
+ it "handles nil for options" do
69
+ expect { Cow.new.as_json(nil) }.to_not raise_error
70
+ end
71
+
72
+ it "serializes Discriminator types as strings" do
73
+ Motorcycle.new.as_json[:type].should == "Motorcycle"
74
+ end
60
75
  end
data/tasks/spec.rake CHANGED
@@ -35,7 +35,4 @@ rescue LoadError
35
35
  end
36
36
  end
37
37
 
38
- task :spec => :check_dependencies
39
- task :rcov => :check_dependencies
40
-
41
38
  task :default => :spec
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-serializer
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 2
9
- version: 1.0.2
4
+ prerelease: 6
5
+ version: 1.1.0.rc1
10
6
  platform: ruby
11
7
  authors:
12
8
  - Guy van den Berg
@@ -14,97 +10,108 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-09-07 00:00:00 -07:00
13
+ date: 2011-02-28 00:00:00 -08:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
- name: dm-core
22
- prerelease: false
17
+ name: activesupport
23
18
  requirement: &id001 !ruby/object:Gem::Requirement
24
19
  none: false
25
20
  requirements:
26
21
  - - ~>
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 0
31
- - 2
32
- version: 1.0.2
23
+ version: 3.0.4
33
24
  type: :runtime
25
+ prerelease: false
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
36
- name: fastercsv
37
- prerelease: false
28
+ name: i18n
38
29
  requirement: &id002 !ruby/object:Gem::Requirement
39
30
  none: false
40
31
  requirements:
41
32
  - - ~>
42
33
  - !ruby/object:Gem::Version
43
- segments:
44
- - 1
45
- - 5
46
- - 3
47
- version: 1.5.3
34
+ version: 0.5.0
48
35
  type: :runtime
36
+ prerelease: false
49
37
  version_requirements: *id002
50
38
  - !ruby/object:Gem::Dependency
51
- name: json_pure
52
- prerelease: false
39
+ name: dm-core
53
40
  requirement: &id003 !ruby/object:Gem::Requirement
54
41
  none: false
55
42
  requirements:
56
43
  - - ~>
57
44
  - !ruby/object:Gem::Version
58
- segments:
59
- - 1
60
- - 4
61
- version: "1.4"
45
+ version: 1.1.0.rc1
62
46
  type: :runtime
47
+ prerelease: false
63
48
  version_requirements: *id003
64
49
  - !ruby/object:Gem::Dependency
65
- name: rspec
66
- prerelease: false
50
+ name: fastercsv
67
51
  requirement: &id004 !ruby/object:Gem::Requirement
68
52
  none: false
69
53
  requirements:
70
54
  - - ~>
71
55
  - !ruby/object:Gem::Version
72
- segments:
73
- - 1
74
- - 3
75
- version: "1.3"
76
- type: :development
56
+ version: 1.5.3
57
+ type: :runtime
58
+ prerelease: false
77
59
  version_requirements: *id004
78
60
  - !ruby/object:Gem::Dependency
79
- name: dm-validations
80
- prerelease: false
61
+ name: json
81
62
  requirement: &id005 !ruby/object:Gem::Requirement
82
63
  none: false
83
64
  requirements:
84
65
  - - ~>
85
66
  - !ruby/object:Gem::Version
86
- segments:
87
- - 1
88
- - 0
89
- - 2
90
- version: 1.0.2
91
- type: :development
67
+ version: 1.5.1
68
+ type: :runtime
69
+ prerelease: false
92
70
  version_requirements: *id005
93
71
  - !ruby/object:Gem::Dependency
94
- name: nokogiri
95
- prerelease: false
72
+ name: dm-validations
96
73
  requirement: &id006 !ruby/object:Gem::Requirement
97
74
  none: false
98
75
  requirements:
99
76
  - - ~>
100
77
  - !ruby/object:Gem::Version
101
- segments:
102
- - 1
103
- - 4
104
- - 3
105
- version: 1.4.3
78
+ version: 1.1.0.rc1
106
79
  type: :development
80
+ prerelease: false
107
81
  version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: jeweler
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.5.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: rake
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ~>
99
+ - !ruby/object:Gem::Version
100
+ version: 0.8.7
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: rspec
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.1
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *id009
108
115
  description: DataMapper plugin for serializing Resources and Collections
109
116
  email: vandenberg.guy [a] gmail [d] com
110
117
  executables: []
@@ -115,7 +122,6 @@ extra_rdoc_files:
115
122
  - LICENSE
116
123
  - README.rdoc
117
124
  files:
118
- - .gitignore
119
125
  - Gemfile
120
126
  - LICENSE
121
127
  - README.rdoc
@@ -139,6 +145,7 @@ files:
139
145
  - spec/fixtures/cow.rb
140
146
  - spec/fixtures/planet.rb
141
147
  - spec/fixtures/quan_tum_cat.rb
148
+ - spec/fixtures/vehicle.rb
142
149
  - spec/lib/serialization_method_shared_spec.rb
143
150
  - spec/public/serializer_spec.rb
144
151
  - spec/public/to_csv_spec.rb
@@ -148,19 +155,16 @@ files:
148
155
  - spec/rcov.opts
149
156
  - spec/spec.opts
150
157
  - spec/spec_helper.rb
151
- - tasks/ci.rake
152
- - tasks/local_gemfile.rake
153
- - tasks/metrics.rake
154
158
  - tasks/spec.rake
155
159
  - tasks/yard.rake
156
160
  - tasks/yardstick.rake
157
- has_rdoc: yard
161
+ has_rdoc: true
158
162
  homepage: http://github.com/datamapper/dm-serializer
159
163
  licenses: []
160
164
 
161
165
  post_install_message:
162
- rdoc_options:
163
- - --charset=UTF-8
166
+ rdoc_options: []
167
+
164
168
  require_paths:
165
169
  - lib
166
170
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -168,21 +172,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
172
  requirements:
169
173
  - - ">="
170
174
  - !ruby/object:Gem::Version
171
- segments:
172
- - 0
173
175
  version: "0"
174
176
  required_rubygems_version: !ruby/object:Gem::Requirement
175
177
  none: false
176
178
  requirements:
177
- - - ">="
179
+ - - ">"
178
180
  - !ruby/object:Gem::Version
179
- segments:
180
- - 0
181
- version: "0"
181
+ version: 1.3.1
182
182
  requirements: []
183
183
 
184
184
  rubyforge_project: datamapper
185
- rubygems_version: 1.3.7
185
+ rubygems_version: 1.5.2
186
186
  signing_key:
187
187
  specification_version: 3
188
188
  summary: DataMapper plugin for serializing Resources and Collections
@@ -190,6 +190,7 @@ test_files:
190
190
  - spec/fixtures/cow.rb
191
191
  - spec/fixtures/planet.rb
192
192
  - spec/fixtures/quan_tum_cat.rb
193
+ - spec/fixtures/vehicle.rb
193
194
  - spec/lib/serialization_method_shared_spec.rb
194
195
  - spec/public/serializer_spec.rb
195
196
  - spec/public/to_csv_spec.rb
data/.gitignore DELETED
@@ -1,37 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## Rubinius
17
- *.rbc
18
-
19
- ## PROJECT::GENERAL
20
- *.gem
21
- coverage
22
- rdoc
23
- pkg
24
- tmp
25
- doc
26
- log
27
- .yardoc
28
- measurements
29
-
30
- ## BUNDLER
31
- .bundle
32
- Gemfile.local
33
- Gemfile.lock
34
- Gemfile.local.lock
35
-
36
- ## PROJECT::SPECIFIC
37
- spec/db/
data/tasks/ci.rake DELETED
@@ -1 +0,0 @@
1
- task :ci => [ :verify_measurements, 'metrics:all' ]
@@ -1,16 +0,0 @@
1
- desc "Support bundling from local source code (allows BUNDLE_GEMFILE=Gemfile.local bundle foo)"
2
- task :local_gemfile do |t|
3
-
4
- root = Pathname(__FILE__).dirname.parent
5
- datamapper = root.parent
6
-
7
- root.join('Gemfile.local').open('w') do |f|
8
- root.join('Gemfile').open.each do |line|
9
- line.sub!(/DATAMAPPER = 'git:\/\/github.com\/datamapper'/, "DATAMAPPER = '#{datamapper}'")
10
- line.sub!(/:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/, ':path => "#{DATAMAPPER}/\1"')
11
- line.sub!(/do_options\[:git\] = \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/, 'do_options[:path] = "#{DATAMAPPER}/\1"')
12
- f.puts line
13
- end
14
- end
15
-
16
- end
data/tasks/metrics.rake DELETED
@@ -1,36 +0,0 @@
1
- begin
2
- require 'metric_fu'
3
- rescue LoadError
4
- namespace :metrics do
5
- task :all do
6
- abort 'metric_fu is not available. In order to run metrics:all, you must: gem install metric_fu'
7
- end
8
- end
9
- end
10
-
11
- begin
12
- require 'reek/adapters/rake_task'
13
-
14
- Reek::RakeTask.new do |t|
15
- t.fail_on_error = true
16
- t.verbose = false
17
- t.source_files = 'lib/**/*.rb'
18
- end
19
- rescue LoadError
20
- task :reek do
21
- abort 'Reek is not available. In order to run reek, you must: gem install reek'
22
- end
23
- end
24
-
25
- begin
26
- require 'roodi'
27
- require 'roodi_task'
28
-
29
- RoodiTask.new do |t|
30
- t.verbose = false
31
- end
32
- rescue LoadError
33
- task :roodi do
34
- abort 'Roodi is not available. In order to run roodi, you must: gem install roodi'
35
- end
36
- end