Ciprian Redinciuc

Joined

40 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Recording pattern (Basecamp 3)

Yep, you are right, I kind of misses this detail. https://www.youtube.com/watch?v=lEUkarkROv0
The Event class also has a previous_recordable which means that the recording accesses its recordables through events, leaving Recordables be completely separated from the business logic.

Posted in Recording pattern (Basecamp 3)

There's also this video, where they go through the Buckets & Recordings patterns.
https://www.youtube.com/watch?v=tmWlm0M6JSk&t=3309s

Indeed, it seems that I will have to use Events to keep track of changes and present them.
I thought that I will be able to do that using just recordings and recordables.

I guess the only way to properly clean up the database when a recording is deleted and delete any associated recordables is to have a trashed property that will trigger a job. And I guess that here: https://www.youtube.com/watch?v=AoxoPfilKqE&t=1185s the @recordable.recordings is just a Recording.where(recordable: self), therefore, a delegated_type is sufficient and a Recordable does not need to point to a Recording, even though I am not 100% sure of that because, in the previous class, Recording::Incineratable::Incineration, the incinerate_recordables method is hidden and it has 13 lines of code, so it's not just another simple call.

Posted in Recording pattern (Basecamp 3)

Yes, Basecamp has something along the lines of:

  def record(recordable, children: nil, parent: nil, creator: Current.person, **options)
    transaction do
      recordable.save!
      options.merge!(recordable: recordable, parent: parent, creator: creator)

      recordings.create!(options).tap do |recording|
        Array(children).each do |child|
          record child, parent: recording, status: status, creator: creator
        end
      end
    end
  end

What I cannot yet figure is how to create a relationship from a Recordable, which can be anything, to a Recording.

module Recordable
  extend ActiveSupport::Concern

  TYPES = %w[ Conversation Message Device ]

  included do
    has_one :recording, as: :recordable, inverse_of: :recordable, touch: true
  end
end


class Recording < ApplicationRecord
  include Tree

  include Accountable, Readable, Recordables

  belongs_to :mobile_application, touch: true
  belongs_to :creator, class_name: "Person", default: -> { Current.person }

  delegated_type :recordable, types: Recordable::TYPES, inverse_of: :recording
end


module Recordables
  extend ActiveSupport::Concern

  included do
    after_commit :update_recordable, on: [:create, :update]
  end

  def recordables
    recordable_type.constantize.where(recording_id: id)
  end

  private
    def update_recordable
      recordable.update! recording_id: self.id
    end
end

The reason I need this is to be able to delete the recordables along with the recording.
I will probably have to do it in a after_commit on destory, but I will probably have to do it in a job.

Hope this helps.

Posted in Recording pattern (Basecamp 3)

Hello, you can find a repo that puts these bits and pieces together here: https://github.com/dixpac/camp
Hope it helps!

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.