add string representation to entities for better and easier logging

This commit is contained in:
Benjamin Neff 2016-05-15 00:11:04 +02:00
parent 58b22df9c5
commit 38922d5f30
36 changed files with 86 additions and 3 deletions

View file

@ -175,6 +175,11 @@ module DiasporaFederation
)
end
# @return [String] string representation of this object
def to_s
"WebFinger:#{acct_uri}"
end
private
# Parses the XML string to a Hash and does some rudimentary checking on

View file

@ -13,6 +13,11 @@ module DiasporaFederation
# @see AccountDeletion#author
# @return [String] diaspora ID
property :author, alias: :diaspora_id, xml_name: :diaspora_handle
# @return [String] string representation of this object
def to_s
"AccountDeletion:#{author}"
end
end
end
end

View file

@ -24,6 +24,11 @@ module DiasporaFederation
# @!attribute [r] sharing
# @return [Boolean] if the author is sharing with the person
property :sharing, default: true
# @return [String] string representation of this object
def to_s
"Contact:#{author}:#{recipient}"
end
end
end
end

View file

@ -55,6 +55,11 @@ module DiasporaFederation
property :nsfw, default: false
property :tag_string, default: nil
# @return [String] string representation of this object
def to_s
"Profile:#{author}"
end
end
end
end

View file

@ -93,6 +93,11 @@ module DiasporaFederation
sender == author || sender == parent.author
end
# @return [String] string representation of this object
def to_s
"#{super}#{":#{parent_type}" if respond_to?(:parent_type)}:#{parent_guid}"
end
private
# this happens only on downstream federation

View file

@ -72,6 +72,11 @@ module DiasporaFederation
Retraction.new(author: author, target_guid: target_guid, target_type: target_type, target: target)
end
# @return [String] string representation of this object
def to_s
"RelayableRetraction:#{target_type}:#{target_guid}"
end
private
# @param [Nokogiri::XML::Element] root_node xml nodes

View file

@ -24,6 +24,11 @@ module DiasporaFederation
Contact.new(author: author, recipient: recipient)
end
# @return [String] string representation of this object
def to_s
"Request:#{author}:#{recipient}"
end
# @param [Nokogiri::XML::Element] root_node xml nodes
# @return [Retraction] instance
def self.populate_entity(root_node)

View file

@ -22,6 +22,11 @@ module DiasporaFederation
# has no meaning at the moment
# @return [Boolean] public
property :public, default: true # always true? (we only reshare public posts)
# @return [String] string representation of this object
def to_s
"#{super}:#{root_guid}"
end
end
end
end

View file

@ -42,6 +42,11 @@ module DiasporaFederation
end
end
# @return [String] string representation of this object
def to_s
"Retraction:#{target_type}:#{target_guid}"
end
# @param [Nokogiri::XML::Element] root_node xml nodes
# @return [Retraction] instance
def self.populate_entity(root_node)

View file

@ -57,6 +57,11 @@ module DiasporaFederation
Base64.strict_encode64(privkey.sign(Relayable::DIGEST, [ret.target_guid, ret.target_type].join(";")))
end
# @return [String] string representation of this object
def to_s
"SignedRetraction:#{target_type}:#{target_guid}"
end
private
# @param [Nokogiri::XML::Element] root_node xml nodes

View file

@ -131,6 +131,11 @@ module DiasporaFederation
Entities.const_get(class_name)
end
# @return [String] string representation of this object
def to_s
"#{self.class.name.rpartition('::').last}#{":#{guid}" if respond_to?(:guid)}"
end
private
def setable?(name, val)

View file

@ -18,7 +18,7 @@ module DiasporaFederation
def receive
validate_and_receive
rescue => e
logger.error "failed to receive #{entity.class}#{":#{entity.guid}" if entity.respond_to?(:guid)}"
logger.error "failed to receive #{entity}"
raise e
end
@ -29,8 +29,7 @@ module DiasporaFederation
def validate_and_receive
validate
DiasporaFederation.callbacks.trigger(:receive_entity, entity, recipient_id)
logger.info "successfully received #{entity.class}#{":#{entity.guid}" if entity.respond_to?(:guid)} " \
"from person #{sender}#{" for #{recipient_id}" if recipient_id}"
logger.info "successfully received #{entity} from person #{sender}#{" for #{recipient_id}" if recipient_id}"
end
def validate

View file

@ -107,6 +107,7 @@ module DiasporaFederation
</html>
HTML
}
let(:string) { "HCard:#{data[:guid]}" }
it_behaves_like "an Entity subclass"

View file

@ -36,6 +36,7 @@ module DiasporaFederation
</XRD>
XML
}
let(:string) { "WebFinger:#{data[:acct_uri]}" }
it_behaves_like "an Entity subclass"

View file

@ -9,6 +9,7 @@ module DiasporaFederation
</account_deletion>
XML
}
let(:string) { "AccountDeletion:#{data[:author]}" }
it_behaves_like "an Entity subclass"

View file

@ -19,6 +19,7 @@ module DiasporaFederation
</comment>
XML
}
let(:string) { "Comment:#{data[:guid]}:#{parent.guid}" }
it_behaves_like "an Entity subclass", [:parent]

View file

@ -12,6 +12,7 @@ module DiasporaFederation
</contact>
XML
}
let(:string) { "Contact:#{data[:author]}:#{data[:recipient]}" }
it_behaves_like "an Entity subclass"

View file

@ -31,6 +31,7 @@ module DiasporaFederation
</conversation>
XML
}
let(:string) { "Conversation:#{data[:guid]}" }
it_behaves_like "an Entity subclass"

View file

@ -25,6 +25,7 @@ module DiasporaFederation
</like>
XML
}
let(:string) { "Like:#{data[:guid]}:Post:#{parent.guid}" }
it_behaves_like "an Entity subclass", [:parent]

View file

@ -11,6 +11,7 @@ module DiasporaFederation
</location>
XML
}
let(:string) { "Location" }
it_behaves_like "an Entity subclass"

View file

@ -21,6 +21,7 @@ module DiasporaFederation
</message>
XML
}
let(:string) { "Message:#{data[:guid]}:#{parent.guid}" }
it_behaves_like "an Entity subclass", [:parent]

View file

@ -24,6 +24,7 @@ module DiasporaFederation
</participation>
XML
}
let(:string) { "Participation:#{data[:guid]}:Post:#{parent.guid}" }
it_behaves_like "an Entity subclass", [:parent]

View file

@ -27,6 +27,7 @@ module DiasporaFederation
</person>
XML
}
let(:string) { "Person:#{data[:guid]}" }
it_behaves_like "an Entity subclass"

View file

@ -18,6 +18,7 @@ module DiasporaFederation
</photo>
XML
}
let(:string) { "Photo:#{data[:guid]}" }
it_behaves_like "an Entity subclass"

View file

@ -10,6 +10,7 @@ module DiasporaFederation
</poll_answer>
XML
}
let(:string) { "PollAnswer:#{data[:guid]}" }
it_behaves_like "an Entity subclass"

View file

@ -23,6 +23,7 @@ module DiasporaFederation
</poll_participation>
XML
}
let(:string) { "PollParticipation:#{data[:guid]}:#{parent.guid}" }
it_behaves_like "an Entity subclass", [:parent]

View file

@ -11,6 +11,7 @@ module DiasporaFederation
</poll>
XML
}
let(:string) { "Poll:#{data[:guid]}" }
it_behaves_like "an Entity subclass"

View file

@ -21,6 +21,7 @@ module DiasporaFederation
</profile>
XML
}
let(:string) { "Profile:#{data[:author]}" }
it_behaves_like "an Entity subclass"

View file

@ -1,6 +1,7 @@
module DiasporaFederation
describe Entities::RelatedEntity do
let(:data) { FactoryGirl.attributes_for(:related_entity) }
let(:string) { "RelatedEntity" }
it_behaves_like "an Entity subclass"
end

View file

@ -32,6 +32,7 @@ module DiasporaFederation
</relayable_retraction>
XML
}
let(:string) { "RelayableRetraction:#{data[:target_type]}:#{data[:target_guid]}" }
it_behaves_like "an Entity subclass", [:target]

View file

@ -10,6 +10,7 @@ module DiasporaFederation
</request>
XML
}
let(:string) { "Request:#{data[:author]}:#{data[:recipient]}" }
it_behaves_like "an Entity subclass"

View file

@ -15,6 +15,7 @@ module DiasporaFederation
</reshare>
XML
}
let(:string) { "Reshare:#{data[:guid]}:#{data[:root_guid]}" }
it_behaves_like "an Entity subclass"

View file

@ -20,6 +20,7 @@ module DiasporaFederation
</retraction>
XML
}
let(:string) { "Retraction:#{data[:target_type]}:#{data[:target_guid]}" }
it_behaves_like "an Entity subclass", [:target]

View file

@ -22,6 +22,7 @@ module DiasporaFederation
</signed_retraction>
XML
}
let(:string) { "SignedRetraction:#{data[:target_type]}:#{data[:target_guid]}" }
it_behaves_like "an Entity subclass", [:target]

View file

@ -53,6 +53,7 @@ module DiasporaFederation
</status_message>
XML
}
let(:string) { "StatusMessage:#{data[:guid]}" }
it_behaves_like "an Entity subclass"

View file

@ -31,6 +31,12 @@ shared_examples "an Entity subclass" do |ignored_props=[]|
expect(hash).to eq(data)
end
end
describe "#to_s" do
it "should represent the entity as string" do
expect(instance.to_s).to eq(string)
end
end
end
end