Module: DiasporaFederation::Entities::Relayable
- Includes:
- Signable
- Included in:
- Comment, EventParticipation, Like, PollParticipation
- Defined in:
- lib/diaspora_federation/entities/relayable.rb
Overview
This is a module that defines common properties for relayable entities which include Like, Comment, Participation, Message, etc. Each relayable has a parent, identified by guid. Relayables are also signed and signing/verification logic is embedded into Salmon XML processing code.
Defined Under Namespace
Modules: Parsing Classes: AuthorPrivateKeyNotFound
Constant Summary
Constants included from Signable
Instance Attribute Summary collapse
-
#additional_data ⇒ Hash
readonly
Additional properties from parsed input object.
-
#author ⇒ String
readonly
The diaspora* ID of the author.
-
#author_signature ⇒ String
readonly
Contains a signature of the entity using the private key of the author of a relayable itself.
-
#guid ⇒ String
readonly
A random string of at least 16 chars.
-
#parent ⇒ RelatedEntity
readonly
Meta information about the parent object.
-
#parent_guid ⇒ String
readonly
Parent guid.
Class Method Summary collapse
-
.included(klass) ⇒ Object
On inclusion of this module the required properties for a relayable are added to the object that includes it.
Instance Method Summary collapse
-
#initialize(data, signature_order = nil, additional_data = {}) ⇒ Object
Initializes a new relayable Entity with order and additional xml elements.
- #sender_valid?(sender) ⇒ Boolean
-
#signature_order ⇒ Array
The order for signing.
- #to_json(*_args) ⇒ Object
-
#to_s ⇒ String
String representation of this object.
-
#verify_signature ⇒ Object
Verifies the
author_signature
if needed.
Methods included from Signable
Instance Attribute Details
#additional_data ⇒ Hash
Additional properties from parsed input object
14 15 16 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 14 def additional_data @additional_data end |
#author ⇒ String (readonly)
The diaspora* ID of the author
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 43 def self.included(klass) klass.class_eval do property :author, :string property :guid, :string property :parent_guid, :string property :author_signature, :string, default: nil entity :parent, Entities::RelatedEntity end klass.extend Parsing end |
#author_signature ⇒ String (readonly)
Contains a signature of the entity using the private key of the author of a relayable itself. The presence of this signature is mandatory. Without it the entity won’t be accepted by a target pod.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 43 def self.included(klass) klass.class_eval do property :author, :string property :guid, :string property :parent_guid, :string property :author_signature, :string, default: nil entity :parent, Entities::RelatedEntity end klass.extend Parsing end |
#guid ⇒ String (readonly)
A random string of at least 16 chars
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 43 def self.included(klass) klass.class_eval do property :author, :string property :guid, :string property :parent_guid, :string property :author_signature, :string, default: nil entity :parent, Entities::RelatedEntity end klass.extend Parsing end |
#parent ⇒ RelatedEntity (readonly)
Meta information about the parent object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 43 def self.included(klass) klass.class_eval do property :author, :string property :guid, :string property :parent_guid, :string property :author_signature, :string, default: nil entity :parent, Entities::RelatedEntity end klass.extend Parsing end |
#parent_guid ⇒ String (readonly)
Returns parent guid.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 43 def self.included(klass) klass.class_eval do property :author, :string property :guid, :string property :parent_guid, :string property :author_signature, :string, default: nil entity :parent, Entities::RelatedEntity end klass.extend Parsing end |
Class Method Details
.included(klass) ⇒ Object
On inclusion of this module the required properties for a relayable are added to the object that includes it.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 43 def self.included(klass) klass.class_eval do property :author, :string property :guid, :string property :parent_guid, :string property :author_signature, :string, default: nil entity :parent, Entities::RelatedEntity end klass.extend Parsing end |
Instance Method Details
#initialize(data, signature_order = nil, additional_data = {}) ⇒ Object
Initializes a new relayable Entity with order and additional xml elements
61 62 63 64 65 66 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 61 def initialize(data, signature_order=nil, additional_data={}) self.signature_order = signature_order if signature_order self.additional_data = additional_data super(data) end |
#sender_valid?(sender) ⇒ Boolean
77 78 79 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 77 def sender_valid?(sender) (sender == && parent.root.local) || sender == parent.root. end |
#signature_order ⇒ Array
The order for signing
97 98 99 100 101 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 97 def signature_order @signature_order || (self.class.class_props.keys.reject {|key| self.class.optional_props.include?(key) && public_send(key).nil? } - %i[author_signature parent]) end |
#to_json(*_args) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 86 def to_json(*_args) super.merge!(property_order: signature_order).tap {|json_hash| missing_properties = json_hash[:property_order] - json_hash[:entity_data].keys missing_properties.each {|property| json_hash[:entity_data][property] = nil } } end |
#to_s ⇒ String
Returns string representation of this object.
82 83 84 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 82 def to_s "#{super}#{":#{parent_type}" if respond_to?(:parent_type)}:#{parent_guid}" end |
#verify_signature ⇒ Object
Verifies the author_signature
if needed.
73 74 75 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 73 def verify_signature super(, :author_signature) unless == parent.root. end |