Class: ActivityPub::Base
- Inherits:
-
Object
- Object
- ActivityPub::Base
- Defined in:
- lib/activitypub/base.rb
Overview
This is not part of ActivityPub, but provides basic mechanisms for serialization and dezerialisation.
Instance Attribute Summary collapse
-
#_raw ⇒ Object
Returns the value of attribute _raw.
-
#_resolver ⇒ Object
Returns the value of attribute _resolver.
Class Method Summary collapse
-
.ap_attr(name, type = nil) ⇒ Object
FIXME: Allow specifying a type (e.g. URI).
- .ap_attributes ⇒ Object
- .ap_types ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#_raw ⇒ Object
Returns the value of attribute _raw.
68 69 70 |
# File 'lib/activitypub/base.rb', line 68 def _raw @_raw end |
#_resolver ⇒ Object
Returns the value of attribute _resolver.
67 68 69 |
# File 'lib/activitypub/base.rb', line 67 def _resolver @_resolver end |
Class Method Details
.ap_attr(name, type = nil) ⇒ Object
FIXME: Allow specifying a type (e.g. URI)
72 73 74 75 76 77 78 |
# File 'lib/activitypub/base.rb', line 72 def self.ap_attr(name, type=nil) @ap_attributes ||= [] @ap_attributes << name @ap_types ||= {} @ap_types[name] = type attr_accessor name end |
.ap_attributes ⇒ Object
85 86 87 88 |
# File 'lib/activitypub/base.rb', line 85 def self.ap_attributes parent = superclass.respond_to?(:ap_attributes) ? superclass.ap_attributes : [] parent.concat(@ap_attributes||[]) end |
.ap_types ⇒ Object
80 81 82 83 |
# File 'lib/activitypub/base.rb', line 80 def self.ap_types parent = superclass.respond_to?(:ap_types) ? superclass.ap_types : {} parent.merge(@ap_types || {}) end |
Instance Method Details
#_context ⇒ Object
64 |
# File 'lib/activitypub/base.rb', line 64 def _context = @_context || "https://www.w3.org/ns/activitystreams" |
#_type ⇒ Object
65 |
# File 'lib/activitypub/base.rb', line 65 def _type = self.class.name.split("::").last |
#to_h ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/activitypub/base.rb', line 90 def to_h h = { "@context" => _context, "type" => _type, } self.class.ap_attributes.each do |attr| val = instance_variable_get("@#{attr}") h[attr.to_s] = val if val end h end |
#to_json ⇒ Object
104 |
# File 'lib/activitypub/base.rb', line 104 def to_json(...) = to_h.to_json(...) |