Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow to overwrite root declaration via options

  • Loading branch information...
commit dc7ef95bd0809b0ef0dc48cd09e6a0a20a5c311d 1 parent 48ea2a5
@mkristian authored
Showing with 9 additions and 4 deletions.
  1. +9 −4 lib/ixtlan/babel/serializer.rb
View
13 lib/ixtlan/babel/serializer.rb
@@ -60,6 +60,10 @@ def self.add_context(key, options = {})
config[key] = options
end
+ def self.root( root )
+ config.root = root
+ end
+
public
def use( context_or_options )
@@ -70,7 +74,7 @@ def use( context_or_options )
def to_hash(options = nil)
setup_filter( options )
if collection?
- @model_or_models.collect do |m|
+ @model_or_models.collect do |m|
filter_model( m )
end
else
@@ -89,6 +93,7 @@ def setup_filter(options)
self.class.config.single_options( @context_or_options )
end
filter.options = o.merge!( options || {} )
+ filter.options[:root] ||= self.class.config.root
end
private :setup_filter
@@ -102,7 +107,7 @@ def to_xml(options = nil)
result = to_hash
- root = filter.root
+ root = config.root
if root && result.is_a?(Array) && root.respond_to?(:pluralize)
root = root.pluralize
@@ -123,8 +128,8 @@ def attr(model)
private
def filter_model( model )
- if root = self.class.config.root
- {root.to_s => filter.filter( model ){ |model| attr(model) } }
+ if root = filter.options[:root]
+ { root.to_s => filter.filter( model ){ |model| attr(model) } }
else
filter.filter( model ){ |model| attr(model) }
end
Please sign in to comment.
Something went wrong with that request. Please try again.