Class: DistributedPress::V1::Social::Reference

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/distributed_press/v1/social/reference.rb

Overview

A lazy loaded reference to a remote object that can access its attributes directly.

Constant Summary collapse

PUBLIC =

Public addressing doesn’t lead to an activity

Returns:

  • (String)
'https://www.w3.org/ns/activitystreams#Public'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, dereferencer:, object: nil) ⇒ Reference

Returns a new instance of Reference.

Parameters:



25
26
27
28
29
# File 'lib/distributed_press/v1/social/reference.rb', line 25

def initialize(uri:, dereferencer:, object: nil)
  @object = object
  @uri = uri
  @dereferencer = dereferencer
end

Instance Attribute Details

#dereferencerDistributedPress::V1::Social::Dereferencer (readonly)



20
21
22
# File 'lib/distributed_press/v1/social/reference.rb', line 20

def dereferencer
  @dereferencer
end

#uriString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/distributed_press/v1/social/reference.rb', line 17

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/distributed_press/v1/social/reference.rb', line 31

def ==(other)
  case other
  when String then uri == other
  when Reference then uri == other.uri
  else false
  end
end

#inspectObject



68
69
70
# File 'lib/distributed_press/v1/social/reference.rb', line 68

def inspect
  "#{self.class.name}(#{uri})"
end

#objectHTTParty::Response

Fetches the remote object once

Returns:

  • (HTTParty::Response)


43
44
45
# File 'lib/distributed_press/v1/social/reference.rb', line 43

def object
  @object ||= dereferencer.get(uri: uri)
end

#private?Bool

It’s not publicly available

Returns:

  • (Bool)


64
65
66
# File 'lib/distributed_press/v1/social/reference.rb', line 64

def private?
  !public? && !unlisted?
end

#public?Bool

Is this a public post?

Returns:

  • (Bool)


50
51
52
# File 'lib/distributed_press/v1/social/reference.rb', line 50

def public?
  [slice(*%w[audience to]).values].flatten.include? PUBLIC
end

#unlisted?Bool

Is it unlisted?

Returns:

  • (Bool)


57
58
59
# File 'lib/distributed_press/v1/social/reference.rb', line 57

def unlisted?
  [self['cc']].flatten.include? PUBLIC
end