Module: Fedipub::DataEntity::ClassMethods
- Defined in:
- app/models/concerns/fedipub/data_entity.rb
Overview
Class methods automatically included in the concern.
Instance Method Summary collapse
-
#acts_as_fedipub_data(handles:, with: :handle_incoming_fediverse_data, route_path_segment: nil, actor_entity_method: nil, url_param: :id, filter_method: nil, should_federate_method: :default_should_federate?, soft_deleted_method: nil, soft_delete_date_method: nil) ⇒ Object
Configures the mapping between entity and Fediverse.
- #find_untombstoned_by!(**params) ⇒ Object
-
#handle_incoming_fediverse_data(activity_hash_or_id) ⇒ self
Creates or updates entity based on the ActivityPub activity.
-
#new_from_activitypub_object(activitypub_object) ⇒ self
Instantiates a new instance from an ActivityPub object.
Instance Method Details
#acts_as_fedipub_data(handles:, with: :handle_incoming_fediverse_data, route_path_segment: nil, actor_entity_method: nil, url_param: :id, filter_method: nil, should_federate_method: :default_should_federate?, soft_deleted_method: nil, soft_delete_date_method: nil) ⇒ Object
Configures the mapping between entity and Fediverse
rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/models/concerns/fedipub/data_entity.rb', line 130 def acts_as_fedipub_data( handles:, with: :handle_incoming_fediverse_data, route_path_segment: nil, actor_entity_method: nil, url_param: :id, filter_method: nil, should_federate_method: :default_should_federate?, soft_deleted_method: nil, soft_delete_date_method: nil ) route_path_segment ||= name.pluralize.underscore Fedipub::Configuration.register_data_type self, route_path_segment: route_path_segment, actor_entity_method: actor_entity_method, url_param: url_param, handles: handles, with: with, filter_method: filter_method, should_federate_method: should_federate_method, soft_deleted_method: soft_deleted_method, soft_delete_date_method: soft_delete_date_method # NOTE: Delete activities cannot be handled like this as we can't be sure to have the object's type Fediverse::Inbox.register_handler 'Create', handles, self, with Fediverse::Inbox.register_handler 'Update', handles, self, with end |
#find_untombstoned_by!(**params) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'app/models/concerns/fedipub/data_entity.rb', line 190 def find_untombstoned_by!(**params) configuration = Fedipub.data_entity_configuration(self) entity = find_by!(**params) raise Fedipub::DataEntity::TombstonedError if configuration[:soft_deleted_method] && entity.send(configuration[:soft_deleted_method]) entity end |
#handle_incoming_fediverse_data(activity_hash_or_id) ⇒ self
Creates or updates entity based on the ActivityPub activity
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'app/models/concerns/fedipub/data_entity.rb', line 174 def handle_incoming_fediverse_data(activity_hash_or_id) activity = Fediverse::Request.dereference(activity_hash_or_id) object = Fediverse::Request.dereference(activity['object']) entity = Fedipub::Utils::Object.find_or_create!(object) if activity['type'] == 'Update' entity.assign_attributes from_activitypub_object(object) # Use timestamps from attributes entity.save! touch: false end entity end |
#new_from_activitypub_object(activitypub_object) ⇒ self
Instantiates a new instance from an ActivityPub object
165 166 167 |
# File 'app/models/concerns/fedipub/data_entity.rb', line 165 def new_from_activitypub_object(activitypub_object) new from_activitypub_object(activitypub_object) end |