Today I Learned

A Zero One initiative

1 post by michealforbes @Micheal_Forbes2

Slide an Organiser into another Organiser's DM's

When calling an Organiser within another Organiser with light-service, a really neat way to do it is to splat the actions from the desired organiser into the other like this:

module Users
  class UpdateProfile
    extend ::LightService::Organizer

    def self.call()
      with(
        # some params go here
      ).reduce(actions)
    end

    def self.actions
      [
        # some actions go here
        *Users::UpdatePreferencesAndNotify.actions,
        # some more actions go here
      ]
    end
  end
end

I needed to call an organiser responsible for updating a completeness score on the user and also running the organiser responsible for updating the users attributes and awarding a badge based on the score. This allowed me to still segment the logic while not cluttering the organiser with more actions.

See https://github.com/adomokos/light-service/issues/160 for reference. Also it’s not necessary to use the extend LightService::Action in the organisers