array-xml_serialization 0.1.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.
- data/Manifest +4 -0
- data/README.rdoc +0 -0
- data/Rakefile +13 -0
- data/array-xml_serialization.gemspec +30 -0
- data/lib/array-xml_serialization.rb +47 -0
- metadata +73 -0
data/Manifest
ADDED
data/README.rdoc
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('array-xml_serialization', '0.1.0') do |p|
|
6
|
+
p.description = "Forces elements in arrays to be output using to_xml on each element if the element responds to to_xml. If an element does not respond to to_xml then a nested XML tag is created with the element's to_s value and the singlarized name of the array as the tag name."
|
7
|
+
p.url = "http://github.com/tsxn26/array-xml_serialization"
|
8
|
+
p.author = "Thomas Nguyen"
|
9
|
+
p.email = "tsxn26@gmail.com"
|
10
|
+
p.ignore_pattern = []
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{array-xml_serialization}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Thomas Nguyen"]
|
9
|
+
s.date = %q{2010-03-30}
|
10
|
+
s.description = %q{Forces elements in arrays to be output using to_xml on each element if the element responds to to_xml. If an element does not respond to to_xml then a nested XML tag is created with the element's to_s value and the singlarized name of the array as the tag name.}
|
11
|
+
s.email = %q{tsxn26@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/array-xml_serialization.rb"]
|
13
|
+
s.files = ["README.rdoc", "Rakefile", "lib/array-xml_serialization.rb", "Manifest", "array-xml_serialization.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/tsxn26/array-xml_serialization}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Array-xml_serialization", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{array-xml_serialization}
|
18
|
+
s.rubygems_version = %q{1.3.6}
|
19
|
+
s.summary = %q{Forces elements in arrays to be output using to_xml on each element if the element responds to to_xml. If an element does not respond to to_xml then a nested XML tag is created with the element's to_s value and the singlarized name of the array as the tag name.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Extends the XML serialization support in activesupport to allow for arrays containing strings, symbols, and integers.
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'activesupport'
|
5
|
+
require 'builder'
|
6
|
+
|
7
|
+
class Array
|
8
|
+
def to_xml(options = {})
|
9
|
+
#raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml }
|
10
|
+
require 'builder' unless defined?(Builder)
|
11
|
+
|
12
|
+
options = options.dup
|
13
|
+
options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
|
14
|
+
options[:children] ||= options[:root].singularize
|
15
|
+
options[:indent] ||= 2
|
16
|
+
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
17
|
+
|
18
|
+
root = options.delete(:root).to_s
|
19
|
+
children = options.delete(:children)
|
20
|
+
|
21
|
+
if !options.has_key?(:dasherize) || options[:dasherize]
|
22
|
+
root = root.dasherize
|
23
|
+
end
|
24
|
+
|
25
|
+
options[:builder].instruct! unless options.delete(:skip_instruct)
|
26
|
+
|
27
|
+
opts = options.merge({ :root => children })
|
28
|
+
|
29
|
+
root = root.pluralize
|
30
|
+
|
31
|
+
xml = options[:builder]
|
32
|
+
if empty?
|
33
|
+
xml.tag!(root, options[:skip_types] ? {} : {:type => "array"})
|
34
|
+
else
|
35
|
+
xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) do
|
36
|
+
yield xml if block_given?
|
37
|
+
each do |e|
|
38
|
+
if e.respond_to? :to_xml
|
39
|
+
e.to_xml(opts.merge({ :skip_instruct => true }))
|
40
|
+
else
|
41
|
+
xml.tag!(root.singularize, e.to_s)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: array-xml_serialization
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Thomas Nguyen
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-30 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Forces elements in arrays to be output using to_xml on each element if the element responds to to_xml. If an element does not respond to to_xml then a nested XML tag is created with the element's to_s value and the singlarized name of the array as the tag name.
|
22
|
+
email: tsxn26@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.rdoc
|
29
|
+
- lib/array-xml_serialization.rb
|
30
|
+
files:
|
31
|
+
- README.rdoc
|
32
|
+
- Rakefile
|
33
|
+
- lib/array-xml_serialization.rb
|
34
|
+
- Manifest
|
35
|
+
- array-xml_serialization.gemspec
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/tsxn26/array-xml_serialization
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --line-numbers
|
43
|
+
- --inline-source
|
44
|
+
- --title
|
45
|
+
- Array-xml_serialization
|
46
|
+
- --main
|
47
|
+
- README.rdoc
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 2
|
64
|
+
version: "1.2"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: array-xml_serialization
|
68
|
+
rubygems_version: 1.3.6
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Forces elements in arrays to be output using to_xml on each element if the element responds to to_xml. If an element does not respond to to_xml then a nested XML tag is created with the element's to_s value and the singlarized name of the array as the tag name.
|
72
|
+
test_files: []
|
73
|
+
|