Array#to_h is new in Ruby 2.1, we still support 2.0

This commit is contained in:
Benjamin Neff 2015-11-30 01:34:33 +01:00
parent 3879632a11
commit 48b56ee6da
2 changed files with 4 additions and 4 deletions

View file

@ -89,7 +89,7 @@ module DiasporaFederation
# and attached to resulted hash as string. It is intended to build a hash
# invariable of an Entity definition, in order to support receiving objects
# from the future versions of Diaspora, where new elements may have been added.
data = root_node.element_children.map { |child|
data = Hash[root_node.element_children.map { |child|
xml_name = child.name
property = klass.class_props.find {|prop| prop[:xml_name].to_s == xml_name }
if property
@ -97,7 +97,7 @@ module DiasporaFederation
else
[xml_name, child.text]
end
}.to_h
}]
Entities::Relayable.verify_signatures(data) if klass.included_modules.include?(Entities::Relayable)

View file

@ -11,9 +11,9 @@ module DiasporaFederation
# @param [Entity.Class] klass entity type to sort according to
# @return [Hash] sorted hash
def self.sort_hash(data, klass)
klass.class_props.map { |prop|
Hash[klass.class_props.map { |prop|
[prop[:name], data[prop[:name]]] unless data[prop[:name]].nil?
}.compact.to_h
}.compact]
end
# Generates attributes for entity constructor with correct signatures in it