| Module | Sequel::Plugins::XmlSerializer::ClassMethods |
| In: |
lib/sequel/plugins/xml_serializer.rb
|
| CAMELIZE | = | proc{|s| s.camelize} | Proc that camelizes the input string, used for the :camelize option | |
| DASHERIZE | = | proc{|s| s.dasherize} | Proc that dasherizes the input string, used for the :dasherize option | |
| IDENTITY | = | proc{|s| s} | Proc that returns the input string as is, used if no :name_proc, :dasherize, or :camelize option is used. | |
| UNDERSCORE | = | proc{|s| s.underscore} | Proc that underscores the input string, used for the :underscore option |
Return an array of instances of this class based on the provided XML.
# File lib/sequel/plugins/xml_serializer.rb, line 133
133: def array_from_xml(xml, opts={})
134: if opts[:all_associations] || opts[:all_columns]
135: Sequel::Deprecation.deprecate("The array_from_xml :all_associations and :all_columns", 'You need to explicitly specify the associations and columns via the :associations and :fields options')
136: end
137: node = Nokogiri::XML(xml).children.first
138: unless node
139: raise Error, "Malformed XML used"
140: end
141: node.children.reject{|c| c.is_a?(Nokogiri::XML::Text)}.map{|c| from_xml_node(c, opts)}
142: end
Return an instance of this class based on the provided XML.
# File lib/sequel/plugins/xml_serializer.rb, line 146
146: def from_xml(xml, opts={})
147: if opts[:all_associations] || opts[:all_columns]
148: Sequel::Deprecation.deprecate("The from_xml :all_associations and :all_columns", 'You need to explicitly specify the associations and columns via the :associations and :fields options')
149: end
150: from_xml_node(Nokogiri::XML(xml).children.first, opts)
151: end
Return an instance of this class based on the given XML node, which should be Nokogiri::XML::Node instance. This should probably not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 156
156: def from_xml_node(parent, opts={})
157: new.from_xml_node(parent, opts)
158: end
Return an appropriate Nokogiri::XML::Builder instance used to create the XML. This should probably not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 163
163: def xml_builder(opts={})
164: if opts[:builder]
165: opts[:builder]
166: else
167: builder_opts = if opts[:builder_opts]
168: opts[:builder_opts]
169: else
170: {}
171: end
172: builder_opts[:encoding] = opts[:encoding] if opts.has_key?(:encoding)
173: Nokogiri::XML::Builder.new(builder_opts)
174: end
175: end
Return a proc (or any other object that responds to []), used for formatting XML tag names when serializing to XML. This should probably not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 180
180: def xml_deserialize_name_proc(opts={})
181: if opts[:name_proc]
182: opts[:name_proc]
183: elsif opts[:underscore]
184: UNDERSCORE
185: else
186: IDENTITY
187: end
188: end
Return a proc (or any other object that responds to []), used for formatting XML tag names when serializing to XML. This should probably not be used directly by user code.
# File lib/sequel/plugins/xml_serializer.rb, line 193
193: def xml_serialize_name_proc(opts={})
194: pr = if opts[:name_proc]
195: opts[:name_proc]
196: elsif opts[:dasherize]
197: DASHERIZE
198: elsif opts[:camelize]
199: CAMELIZE
200: else
201: IDENTITY
202: end
203: proc{|s| "#{pr[s]}_"}
204: end