use .to_h instead of Hash[]
This commit is contained in:
parent
52d9f3a226
commit
d054d42b86
8 changed files with 15 additions and 15 deletions
|
|
@ -161,7 +161,7 @@ module DiasporaFederation
|
|||
# @return [Hash] sorted xml elements with updated signatures
|
||||
def xml_elements
|
||||
xml_data = super.merge(additional_xml_elements)
|
||||
Hash[signature_order.map {|element| [element, xml_data[element]] }].tap do |xml_elements|
|
||||
signature_order.map {|element| [element, xml_data[element]] }.to_h.tap do |xml_elements|
|
||||
xml_elements[:author_signature] = author_signature || sign_with_author
|
||||
xml_elements[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
|
||||
end
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ module DiasporaFederation
|
|||
# Nested entities are also converted to a Hash.
|
||||
# @return [Hash] entity data (mostly equal to the hash used for initialization).
|
||||
def to_h
|
||||
Hash[properties.map {|key, value|
|
||||
properties.map {|key, value|
|
||||
type = self.class.class_props[key]
|
||||
|
||||
if type == String || value.nil?
|
||||
|
|
@ -83,7 +83,7 @@ module DiasporaFederation
|
|||
elsif type.instance_of?(Array)
|
||||
[key, value.map(&:to_h)]
|
||||
end
|
||||
}]
|
||||
}.to_h
|
||||
end
|
||||
|
||||
# Returns the XML representation for this entity constructed out of
|
||||
|
|
@ -216,7 +216,7 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
def xml_elements
|
||||
Hash[properties.map {|name, value| [name, self.class.class_props[name] == String ? value.to_s : value] }]
|
||||
properties.map {|name, value| [name, self.class.class_props[name] == String ? value.to_s : value] }.to_h
|
||||
end
|
||||
|
||||
def add_property_to_xml(doc, root_element, name, value)
|
||||
|
|
@ -248,10 +248,10 @@ module DiasporaFederation
|
|||
# @param [Nokogiri::XML::Element] root_node xml nodes
|
||||
# @return [Hash] entity data
|
||||
private_class_method def self.entity_data(root_node)
|
||||
Hash[class_props.map {|name, type|
|
||||
class_props.map {|name, type|
|
||||
value = parse_element_from_node(name, type, root_node)
|
||||
[name, value] if value
|
||||
}.compact]
|
||||
}.compact.to_h
|
||||
end
|
||||
|
||||
# @param [String] name property name to parse
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ module DiasporaFederation
|
|||
def self.private(sender_id, obj_str, targets)
|
||||
hydra = HydraWrapper.new(sender_id, obj_str)
|
||||
targets.each {|url, xml| hydra.insert_job(url, xml) }
|
||||
Hash[hydra.send.map {|url| [url, targets[url]] }]
|
||||
hydra.send.map {|url| [url, targets[url]] }.to_h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ module DiasporaFederation
|
|||
# @param [Hash] data entity data
|
||||
# @return [Hash] hash with resolved aliases
|
||||
def resolv_aliases(data)
|
||||
Hash[data.map {|name, value|
|
||||
data.map {|name, value|
|
||||
if class_prop_aliases.has_key? name
|
||||
prop_name = class_prop_aliases[name]
|
||||
raise InvalidData, "only use '#{name}' OR '#{prop_name}'" if data.has_key? prop_name
|
||||
|
|
@ -66,7 +66,7 @@ module DiasporaFederation
|
|||
else
|
||||
[name, value]
|
||||
end
|
||||
}]
|
||||
}.to_h
|
||||
end
|
||||
|
||||
# @return [Symbol] alias for the xml-generation/parsing
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ module DiasporaFederation
|
|||
key = AES.generate_key_and_iv
|
||||
encrypted_env = AES.encrypt(magic_env.to_xml, key[:key], key[:iv])
|
||||
|
||||
encoded_key = Hash[key.map {|k, v| [k, Base64.strict_encode64(v)] }]
|
||||
encoded_key = key.map {|k, v| [k, Base64.strict_encode64(v)] }.to_h
|
||||
encrypted_key = Base64.strict_encode64(pubkey.public_encrypt(JSON.generate(encoded_key)))
|
||||
|
||||
JSON.generate(aes_key: encrypted_key, encrypted_magic_envelope: encrypted_env)
|
||||
|
|
@ -51,7 +51,7 @@ module DiasporaFederation
|
|||
encrypted_json = JSON.parse(encrypted_env)
|
||||
|
||||
encoded_key = JSON.parse(privkey.private_decrypt(Base64.decode64(encrypted_json["aes_key"])))
|
||||
key = Hash[encoded_key.map {|k, v| [k, Base64.decode64(v)] }]
|
||||
key = encoded_key.map {|k, v| [k, Base64.decode64(v)] }.to_h
|
||||
|
||||
xml = AES.decrypt(encrypted_json["encrypted_magic_envelope"], key["key"], key["iv"])
|
||||
Nokogiri::XML::Document.parse(xml).root
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ module DiasporaFederation
|
|||
# @param [Hash] hash { key: "...", iv: "..." }
|
||||
# @return [Hash] encoded hash: { key: "...", iv: "..." }
|
||||
def strict_base64_encode(hash)
|
||||
Hash[hash.map {|k, v| [k, Base64.strict_encode64(v)] }]
|
||||
hash.map {|k, v| [k, Base64.strict_encode64(v)] }.to_h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ module DiasporaFederation
|
|||
|
||||
json = JSON.parse(encrypted)
|
||||
aes_key = JSON.parse(privkey.private_decrypt(Base64.decode64(json["aes_key"])))
|
||||
key = Hash[aes_key.map {|k, v| [k, Base64.decode64(v)] }]
|
||||
key = aes_key.map {|k, v| [k, Base64.decode64(v)] }.to_h
|
||||
|
||||
xml = Salmon::AES.decrypt(json["encrypted_magic_envelope"], key["key"], key["iv"])
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ shared_examples "an Entity subclass" do
|
|||
|
||||
describe "#to_h" do
|
||||
it "should return a hash with nested data" do
|
||||
expected_data = Hash[data.map {|key, value|
|
||||
expected_data = data.map {|key, value|
|
||||
if [String, TrueClass, FalseClass, Fixnum, Time, NilClass].include?(value.class)
|
||||
[key, value]
|
||||
elsif value.instance_of?(Array)
|
||||
|
|
@ -34,7 +34,7 @@ shared_examples "an Entity subclass" do
|
|||
else
|
||||
[key, value.to_h]
|
||||
end
|
||||
}]
|
||||
}.to_h
|
||||
|
||||
expect(instance.to_h).to eq(expected_data)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue