Class: DiasporaFederation::Entities::Participation

Inherits:
DiasporaFederation::Entity show all
Defined in:
lib/diaspora_federation/entities/participation.rb

Overview

Participation is sent to subscribe a user on updates for some post.

See Also:

  • Validators::Participation

Defined Under Namespace

Classes: ParentNotLocal

Constant Summary

Constants inherited from DiasporaFederation::Entity

DiasporaFederation::Entity::ENTITY_NAME_REGEX, DiasporaFederation::Entity::INVALID_XML_REGEX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DiasporaFederation::Entity

class_name, entity_class, entity_name, from_json, from_xml, #initialize, #to_h, #to_json, #to_xml

Methods included from PropertiesDSL

#class_props, #default_values, #entity, #missing_props, #optional_props, #property, #resolv_aliases

Methods included from Logging

included

Constructor Details

This class inherits a constructor from DiasporaFederation::Entity

Instance Attribute Details

#authorString (readonly)

The diaspora* ID of the author

Returns:

  • (String)

    diaspora* ID

See Also:



13
# File 'lib/diaspora_federation/entities/participation.rb', line 13

property :author, :string

#guidString (readonly)

A random string of at least 16 chars

Returns:

  • (String)

    guid

See Also:



19
# File 'lib/diaspora_federation/entities/participation.rb', line 19

property :guid, :string

#parent_guidString (readonly)

Returns parent guid.

Returns:

  • (String)

    parent guid

See Also:



24
# File 'lib/diaspora_federation/entities/participation.rb', line 24

property :parent_guid, :string

#parent_typeString (readonly)

A string describing a type of the target to subscribe on Currently only “Post” is supported.

Returns:

  • (String)

    parent type



30
# File 'lib/diaspora_federation/entities/participation.rb', line 30

property :parent_type, :string

Class Method Details

.from_hash(hash) ⇒ Entity

Validate that the parent is local.

Parameters:

  • hash (Hash)

    entity initialization hash

Returns:

See Also:



47
48
49
# File 'lib/diaspora_federation/entities/participation.rb', line 47

def self.from_hash(hash)
  super.tap(&:validate_parent)
end

Instance Method Details

#to_sString

Returns string representation of this object.

Returns:

  • (String)

    string representation of this object



33
34
35
# File 'lib/diaspora_federation/entities/participation.rb', line 33

def to_s
  "#{super}:#{parent_type}:#{parent_guid}"
end

#validate_parentObject

Validates that the parent exists and the parent author is local

Raises:



38
39
40
41
# File 'lib/diaspora_federation/entities/participation.rb', line 38

def validate_parent
  parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, parent_type, parent_guid)
  raise ParentNotLocal, "obj=#{self}" unless parent&.local
end