lib/roxml/definition.rb in roxml-3.1.5 vs lib/roxml/definition.rb in roxml-3.1.6
- old
+ new
@@ -53,20 +53,21 @@
elsif opts[:from] == :name
opts[:from] = '*'
elsif opts[:from] == :attr
@sought_type = :attr
opts[:from] = nil
- elsif opts[:from] == :name
+ elsif opts[:from] == :namespace
opts[:from] = '*'
+ @sought_type = :namespace
elsif opts[:from].to_s.starts_with?('@')
@sought_type = :attr
opts[:from].sub!('@', '')
end
- @attr_name = accessor.to_s.chomp('?')
- @name = (opts[:from] || @attr_name).to_s
+ @name = @attr_name = accessor.to_s.chomp('?')
@name = @name.singularize if hash? || array?
+ @name = (opts[:from] || @name).to_s
if hash? && (hash.key.name? || hash.value.name?)
@name = '*'
end
raise ContradictoryNamespaces if @name.include?(':') && (@namespace.present? || @namespace == false)
@@ -110,10 +111,11 @@
def to_ref(inst)
case sought_type
when :attr then XMLAttributeRef
when :text then XMLTextRef
+ when :namespace then XMLNameSpaceRef
when HashDefinition then XMLHashRef
when Symbol then raise ArgumentError, "Invalid type argument #{sought_type}"
else XMLObjectRef
end.new(self, inst)
end
@@ -210,10 +212,10 @@
# if a second block is present, and we can't coerce the xml value
# to bool, we need to be able to pass it to the user-provided block
as = (block ? :bool_combined : :bool_standalone)
end
as = self.class.block_shorthands.fetch(as) do
- unless as.respond_to?(:from_xml) || (as.respond_to?(:first) && as.first.respond_to?(:from_xml)) || (as.is_a?(Hash) && !(as.keys & [:key, :value]).empty?)
+ unless (as == :text) || as.respond_to?(:from_xml) || (as.respond_to?(:first) && as.first.respond_to?(:from_xml)) || (as.is_a?(Hash) && !(as.keys & [:key, :value]).empty?)
raise ArgumentError, "Invalid :as argument #{as}" unless as.nil?
end
nil
end
[as, block].compact