module HelixSync # Front end to managing changelist-related resources. # # This doesn't actually provide implementations, just hooks for other services. class ChangeService # Rack environment attr_accessor :env def initialize(env: nil) @env = env end @@create_pending_change = [] @@fetch_latest_change = [] @@fetch_pending_change = [] @@submit_pending_change = [] # Callback list for finding the latest changelist for a project. # # Your handler should return the changelist if your implementation supports # this particular project. # # Each callback you add should consume these parameters: # # - `project` [String]: The encoded project ID # # - `env` [Hash]: Current Rack environment # # Example: # # HelixSync::ChangeService.fetch_change << lambda do |project, env| # fetch_change(project, env) if i_support?(project) # end def self.fetch_latest_change @@fetch_latest_change end # Returns the change found by the first handler that supports the project, # or nil def find_latest_change(project_id) change_num = nil @@fetch_latest_change.find do |handler| c = handler.call(project_id, env) change_num = c if c c end change_num end # Callback list for finding the pending changelist for a project. # # Your handler should return the changelist if your implementation supports # this particular project. # # Each callback you add should consume these parameters: # # - `project` [String]: The encoded project ID # # - `env` [Hash]: Current Rack environment # # Example: # # HelixSync::ChangeService.fetch_change << lambda do |project, env| # fetch_change(project, env) if i_support?(project) # end def self.fetch_pending_change @@fetch_pending_change end # Returns the change found by the first handler that supports the project, # or nil def find_pending_change(project_id) change_num = nil @@fetch_pending_change.find do |handler| c = handler.call(project_id, env) change_num = c if c c end change_num end # Callback list for creating a pending changelist # # Your handler should return the changelist if your implementation handled # creating the changelist number. # # Each callback you add should consume these parameters: # # - `project` [String]: The encoded project ID # # - `env` [Hash]: Current Rack environment # # Example: # # HelixSync::ChangeService.create_pending_change << lambda do |project, env| # create_change(project, env) if i_support?(project) # end # def self.create_pending_change @@create_pending_change end # Returns the new pending change for the user and project ID def create_pending_change(project_id) change_num = nil @@create_pending_change.find do |handler| c = handler.call(project_id, env) change_num = c if c c end change_num end # Callback list for submitting a pending changelist for a project # # Your handler should return the changelist if your implementation handled # creating the changelist number. # # Each callback you add should consume these parameters: # # - `project` [String]: The encoded project ID # # - `env` [Hash]: Current Rack environment # # Example: # # HelixSync::ChangeService.submit_pending_change << lambda do |project, changelist, env| # create_change(project, changelist, env) if i_support?(project) # end # def self.submit_pending_change @@submit_pending_change end def submit_pending_change(project_id) @@submit_pending_change.find do |handler| handler.call(project_id, env) end end end end