Module: Observ::PromptManager::VersionManagement
- Included in:
- Observ::PromptManager
- Defined in:
- app/services/observ/prompt_manager/version_management.rb
Overview
Concern for prompt version management operations including creation, state transitions (promote, demote, restore), and version queries.
Instance Method Summary collapse
-
#create(name:, prompt:, config: {}, commit_message: nil, created_by: nil, promote_to_production: false) ⇒ Observ::Prompt
Create new version of a prompt.
-
#demote(name:, version:) ⇒ Observ::Prompt
Demote production to archived.
-
#promote(name:, version:) ⇒ Observ::Prompt
Promote specific version to production.
-
#restore(name:, version:) ⇒ Observ::Prompt
Restore archived to production.
-
#rollback(name:, to_version:) ⇒ Observ::Prompt
Rollback to specific version (restore archived to production).
-
#versions(name:) ⇒ ActiveRecord::Relation
Get all versions for a prompt.
Instance Method Details
#create(name:, prompt:, config: {}, commit_message: nil, created_by: nil, promote_to_production: false) ⇒ Observ::Prompt
Create new version of a prompt
20 21 22 23 24 25 26 27 28 29 |
# File 'app/services/observ/prompt_manager/version_management.rb', line 20 def create(name:, prompt:, config: {}, commit_message: nil, created_by: nil, promote_to_production: false) Prompt.create_version( name: name, prompt: prompt, config: config, commit_message: , created_by: created_by, promote_to_production: promote_to_production ) end |
#demote(name:, version:) ⇒ Observ::Prompt
Demote production to archived
79 80 81 82 83 |
# File 'app/services/observ/prompt_manager/version_management.rb', line 79 def demote(name:, version:) prompt = Prompt.find_by!(name: name, version: version) prompt.demote! if prompt.production? prompt end |
#promote(name:, version:) ⇒ Observ::Prompt
Promote specific version to production
69 70 71 72 73 |
# File 'app/services/observ/prompt_manager/version_management.rb', line 69 def promote(name:, version:) prompt = Prompt.find_by!(name: name, version: version) prompt.promote! if prompt.draft? prompt end |
#restore(name:, version:) ⇒ Observ::Prompt
Restore archived to production
89 90 91 92 93 |
# File 'app/services/observ/prompt_manager/version_management.rb', line 89 def restore(name:, version:) prompt = Prompt.find_by!(name: name, version: version) prompt.restore! if prompt.archived? prompt end |
#rollback(name:, to_version:) ⇒ Observ::Prompt
Rollback to specific version (restore archived to production)
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/services/observ/prompt_manager/version_management.rb', line 51 def rollback(name:, to_version:) prompt = Prompt.find_by!(name: name, version: to_version) if prompt.archived? prompt.restore! prompt elsif prompt.production? # Already production, nothing to do prompt else raise StateTransitionError, "Cannot rollback to draft version" end end |
#versions(name:) ⇒ ActiveRecord::Relation
Get all versions for a prompt
38 39 40 |
# File 'app/services/observ/prompt_manager/version_management.rb', line 38 def versions(name:) Prompt.where(name: name).order(version: :desc) end |