dm-serializer 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -31,6 +31,7 @@ measurements
31
31
  .bundle
32
32
  Gemfile.local
33
33
  Gemfile.lock
34
+ Gemfile.local.lock
34
35
 
35
36
  ## PROJECT::SPECIFIC
36
37
  spec/db/
data/Gemfile CHANGED
@@ -71,14 +71,14 @@
71
71
  source 'http://rubygems.org'
72
72
 
73
73
  DATAMAPPER = 'git://github.com/datamapper'
74
- DM_VERSION = '~> 1.0.0'
74
+ DM_VERSION = '~> 1.0.1'
75
75
 
76
76
  group :runtime do # Runtime dependencies (as in the gemspec)
77
77
 
78
78
  if ENV['EXTLIB']
79
- gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
79
+ gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
80
80
  else
81
- gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
81
+ gem 'activesupport', '~> 3.0.0', :git => 'git://github.com/rails/rails.git', :branch => '3-0-stable', :require => nil
82
82
  end
83
83
 
84
84
  gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
@@ -93,7 +93,7 @@ group(:development) do # Development dependencies (as in the gemspec)
93
93
  gem 'nokogiri', '~> 1.4.1'
94
94
 
95
95
  gem 'rake', '~> 0.8.7'
96
- gem 'rspec', '~> 1.3'
96
+ gem 'rspec', '~> 1.3', :git => 'git://github.com/snusnu/rspec', :branch => 'heckle_fix_plus_gemfile'
97
97
  gem 'jeweler', '~> 1.4'
98
98
 
99
99
  end
@@ -112,32 +112,31 @@ end
112
112
  group :datamapper do # We need this because we want to pin these dependencies to their git master sources
113
113
 
114
114
  adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
115
- adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
115
+ adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
116
116
 
117
- unless adapters.empty?
117
+ DO_VERSION = '~> 0.10.2'
118
+ DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
118
119
 
119
- DO_VERSION = '~> 0.10.3'
120
- DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
120
+ if (do_adapters = DM_DO_ADAPTERS & adapters).any?
121
+ options = {}
122
+ options[:git] = "#{DATAMAPPER}/do.git" if ENV['DO_GIT'] == 'true'
121
123
 
122
- gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
124
+ gem 'data_objects', DO_VERSION, options.dup
123
125
 
124
- adapters.each do |adapter|
125
- if DM_DO_ADAPTERS.any? { |dm_do_adapter| dm_do_adapter =~ /#{adapter}/ }
126
- adapter = 'sqlite3' if adapter == 'sqlite'
127
- gem "do_#{adapter}", DO_VERSION, :git => "#{DATAMAPPER}/do.git"
128
- end
126
+ do_adapters.each do |adapter|
127
+ adapter = 'sqlite3' if adapter == 'sqlite'
128
+ gem "do_#{adapter}", DO_VERSION, options.dup
129
129
  end
130
130
 
131
131
  gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
132
+ end
132
133
 
133
- adapters.each do |adapter|
134
- gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
135
- end
136
-
134
+ adapters.each do |adapter|
135
+ gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
137
136
  end
138
137
 
139
138
  plugins = ENV['PLUGINS'] || ENV['PLUGIN']
140
- plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
139
+ plugins = plugins.to_s.tr(',', ' ').split.push('dm-migrations').uniq
141
140
 
142
141
  plugins.each do |plugin|
143
142
  gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
data/Rakefile CHANGED
@@ -15,13 +15,13 @@ begin
15
15
 
16
16
  gem.rubyforge_project = 'datamapper'
17
17
 
18
- gem.add_dependency 'dm-core', '~> 1.0.0'
18
+ gem.add_dependency 'dm-core', '~> 1.0.1'
19
19
  gem.add_dependency 'fastercsv', '~> 1.5.3'
20
- gem.add_dependency 'json_pure', '~> 1.4.3'
20
+ gem.add_dependency 'json_pure', '~> 1.4'
21
21
 
22
22
  gem.add_development_dependency 'rspec', '~> 1.3'
23
- gem.add_development_dependency 'dm-validations', '~> 1.0.0'
24
- gem.add_development_dependency 'nokogiri', '~> 1.4.1'
23
+ gem.add_development_dependency 'dm-validations', '~> 1.0.1'
24
+ gem.add_development_dependency 'nokogiri', '~> 1.4.3'
25
25
  # gem.add_development_dependency 'libxml-ruby', '~> 1.1.4' # not available on JRuby
26
26
  end
27
27
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-serializer}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Guy van den Berg"]
12
- s.date = %q{2010-06-08}
12
+ s.date = %q{2010-09-07}
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 = [
@@ -81,27 +81,27 @@ Gem::Specification.new do |s|
81
81
  s.specification_version = 3
82
82
 
83
83
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
84
- s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0"])
84
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.1"])
85
85
  s.add_runtime_dependency(%q<fastercsv>, ["~> 1.5.3"])
86
- s.add_runtime_dependency(%q<json_pure>, ["~> 1.4.3"])
86
+ s.add_runtime_dependency(%q<json_pure>, ["~> 1.4"])
87
87
  s.add_development_dependency(%q<rspec>, ["~> 1.3"])
88
- s.add_development_dependency(%q<dm-validations>, ["~> 1.0.0"])
89
- s.add_development_dependency(%q<nokogiri>, ["~> 1.4.1"])
88
+ s.add_development_dependency(%q<dm-validations>, ["~> 1.0.1"])
89
+ s.add_development_dependency(%q<nokogiri>, ["~> 1.4.3"])
90
90
  else
91
- s.add_dependency(%q<dm-core>, ["~> 1.0.0"])
91
+ s.add_dependency(%q<dm-core>, ["~> 1.0.1"])
92
92
  s.add_dependency(%q<fastercsv>, ["~> 1.5.3"])
93
- s.add_dependency(%q<json_pure>, ["~> 1.4.3"])
93
+ s.add_dependency(%q<json_pure>, ["~> 1.4"])
94
94
  s.add_dependency(%q<rspec>, ["~> 1.3"])
95
- s.add_dependency(%q<dm-validations>, ["~> 1.0.0"])
96
- s.add_dependency(%q<nokogiri>, ["~> 1.4.1"])
95
+ s.add_dependency(%q<dm-validations>, ["~> 1.0.1"])
96
+ s.add_dependency(%q<nokogiri>, ["~> 1.4.3"])
97
97
  end
98
98
  else
99
- s.add_dependency(%q<dm-core>, ["~> 1.0.0"])
99
+ s.add_dependency(%q<dm-core>, ["~> 1.0.1"])
100
100
  s.add_dependency(%q<fastercsv>, ["~> 1.5.3"])
101
- s.add_dependency(%q<json_pure>, ["~> 1.4.3"])
101
+ s.add_dependency(%q<json_pure>, ["~> 1.4"])
102
102
  s.add_dependency(%q<rspec>, ["~> 1.3"])
103
- s.add_dependency(%q<dm-validations>, ["~> 1.0.0"])
104
- s.add_dependency(%q<nokogiri>, ["~> 1.4.1"])
103
+ s.add_dependency(%q<dm-validations>, ["~> 1.0.1"])
104
+ s.add_dependency(%q<nokogiri>, ["~> 1.4.3"])
105
105
  end
106
106
  end
107
107
 
@@ -4,13 +4,18 @@ require 'json'
4
4
 
5
5
  module DataMapper
6
6
  module Serialize
7
- # Serialize a Resource to JavaScript Object Notation (JSON; RFC 4627)
8
7
  #
9
- # @return <String> a JSON representation of the Resource
10
- def to_json(*args)
11
- options = args.first || {}
12
- options = options.to_h if options.respond_to?(:to_h)
13
-
8
+ # Converts the resource into a hash of properties.
9
+ #
10
+ # @param [Hash] options
11
+ # Additional options.
12
+ #
13
+ # @return [Hash{String => String}]
14
+ # The hash of resources properties.
15
+ #
16
+ # @since 1.0.1
17
+ #
18
+ def as_json(options={})
14
19
  result = {}
15
20
 
16
21
  properties_to_serialize(options).each do |property|
@@ -33,6 +38,18 @@ module DataMapper
33
38
  result[relationship_name] = __send__(relationship_name).to_json(opts.merge(:to_json => false))
34
39
  end
35
40
 
41
+ result
42
+ end
43
+
44
+ # Serialize a Resource to JavaScript Object Notation (JSON; RFC 4627)
45
+ #
46
+ # @return <String> a JSON representation of the Resource
47
+ def to_json(*args)
48
+ options = args.first || {}
49
+ options = options.to_h if options.respond_to?(:to_h)
50
+
51
+ result = as_json(options)
52
+
36
53
  # default to making JSON
37
54
  if options.fetch(:to_json, true)
38
55
  result.to_json
@@ -21,7 +21,7 @@ module DataMapper
21
21
  def to_xml_document(opts={}, doc = nil)
22
22
  xml = XMLSerializers::SERIALIZER
23
23
  doc ||= xml.new_document
24
- default_xml_element_name = lambda { ActiveSupport::Inflector.underscore(model.name).tr("/", "-") }
24
+ default_xml_element_name = lambda { DataMapper::Inflector.underscore(model.name).tr("/", "-") }
25
25
  root = xml.root_node(doc, opts[:element_name] || default_xml_element_name[])
26
26
  properties_to_serialize(opts).each do |property|
27
27
  value = __send__(property.name)
@@ -79,7 +79,7 @@ module DataMapper
79
79
  def to_xml_document(opts = {})
80
80
  xml = DataMapper::Serialize::XMLSerializers::SERIALIZER
81
81
  doc = xml.new_document
82
- default_collection_element_name = lambda {ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(self.model.to_s)).tr("/", "-")}
82
+ default_collection_element_name = lambda {DataMapper::Inflector.pluralize(DataMapper::Inflector.underscore(self.model.to_s)).tr("/", "-")}
83
83
  root = xml.root_node(doc, opts[:collection_element_name] || default_collection_element_name[], {'type' => 'array'})
84
84
  self.each do |item|
85
85
  item.to_xml_document(opts, doc)
@@ -1,16 +1,14 @@
1
1
  desc "Support bundling from local source code (allows BUNDLE_GEMFILE=Gemfile.local bundle foo)"
2
2
  task :local_gemfile do |t|
3
3
 
4
- root = Pathname(__FILE__).dirname.parent
5
- datamapper = root.parent
6
-
7
- source_regex = /DATAMAPPER = 'git:\/\/github.com\/datamapper'/
8
- gem_source_regex = /:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/
4
+ root = Pathname(__FILE__).dirname.parent
5
+ datamapper = root.parent
9
6
 
10
7
  root.join('Gemfile.local').open('w') do |f|
11
8
  root.join('Gemfile').open.each do |line|
12
- line.sub!(source_regex, "DATAMAPPER = '#{datamapper}'")
13
- line.sub!(gem_source_regex, ':path => "#{DATAMAPPER}/\1"')
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"')
14
12
  f.puts line
15
13
  end
16
14
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-serializer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 0
9
- - 0
10
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Guy van den Berg
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-06-08 00:00:00 -07:00
17
+ date: 2010-09-07 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,12 +25,11 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 23
30
28
  segments:
31
29
  - 1
32
30
  - 0
33
- - 0
34
- version: 1.0.0
31
+ - 1
32
+ version: 1.0.1
35
33
  type: :runtime
36
34
  version_requirements: *id001
37
35
  - !ruby/object:Gem::Dependency
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 5
46
43
  segments:
47
44
  - 1
48
45
  - 5
@@ -58,12 +55,10 @@ dependencies:
58
55
  requirements:
59
56
  - - ~>
60
57
  - !ruby/object:Gem::Version
61
- hash: 1
62
58
  segments:
63
59
  - 1
64
60
  - 4
65
- - 3
66
- version: 1.4.3
61
+ version: "1.4"
67
62
  type: :runtime
68
63
  version_requirements: *id003
69
64
  - !ruby/object:Gem::Dependency
@@ -74,7 +69,6 @@ dependencies:
74
69
  requirements:
75
70
  - - ~>
76
71
  - !ruby/object:Gem::Version
77
- hash: 9
78
72
  segments:
79
73
  - 1
80
74
  - 3
@@ -89,12 +83,11 @@ dependencies:
89
83
  requirements:
90
84
  - - ~>
91
85
  - !ruby/object:Gem::Version
92
- hash: 23
93
86
  segments:
94
87
  - 1
95
88
  - 0
96
- - 0
97
- version: 1.0.0
89
+ - 1
90
+ version: 1.0.1
98
91
  type: :development
99
92
  version_requirements: *id005
100
93
  - !ruby/object:Gem::Dependency
@@ -105,12 +98,11 @@ dependencies:
105
98
  requirements:
106
99
  - - ~>
107
100
  - !ruby/object:Gem::Version
108
- hash: 5
109
101
  segments:
110
102
  - 1
111
103
  - 4
112
- - 1
113
- version: 1.4.1
104
+ - 3
105
+ version: 1.4.3
114
106
  type: :development
115
107
  version_requirements: *id006
116
108
  description: DataMapper plugin for serializing Resources and Collections
@@ -176,7 +168,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
168
  requirements:
177
169
  - - ">="
178
170
  - !ruby/object:Gem::Version
179
- hash: 3
180
171
  segments:
181
172
  - 0
182
173
  version: "0"
@@ -185,7 +176,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
176
  requirements:
186
177
  - - ">="
187
178
  - !ruby/object:Gem::Version
188
- hash: 3
189
179
  segments:
190
180
  - 0
191
181
  version: "0"