Class: RubyAiGemContext::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_ai_gem_context/platform.rb

Overview

Base class for AI platform definitions

Each platform (Claude, Cursor, Windsurf, etc.) defines:

  • The filename and location for context files
  • The template/format for the context file
  • The prompt to use when generating content

Class Method Summary collapse

Class Method Details

.backup(project_root = Dir.pwd) ⇒ Object

Create backup of existing file



70
71
72
73
74
75
76
# File 'lib/ruby_ai_gem_context/platform.rb', line 70

def backup(project_root = Dir.pwd)
  return nil unless exists?(project_root)

  backup_path = "#{full_path(project_root)}.backup"
  FileUtils.cp(full_path(project_root), backup_path)
  backup_path
end

.description ⇒ Object

Description shown in the interactive menu

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/ruby_ai_gem_context/platform.rb', line 29

def description
  raise NotImplementedError
end

.exists?(project_root = Dir.pwd) ⇒ Boolean

Check if the context file already exists

Returns:

  • (Boolean)


45
46
47
# File 'lib/ruby_ai_gem_context/platform.rb', line 45

def exists?(project_root = Dir.pwd)
  File.exist?(File.join(project_root, path))
end

.filename ⇒ Object

The filename for the context file (e.g., "CLAUDE.md", ".cursorrules")

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/ruby_ai_gem_context/platform.rb', line 18

def filename
  raise NotImplementedError
end

.full_path(project_root = Dir.pwd) ⇒ Object

Full path to the context file



50
51
52
# File 'lib/ruby_ai_gem_context/platform.rb', line 50

def full_path(project_root = Dir.pwd)
  File.join(project_root, path)
end

.generation_prompt ⇒ Object

The prompt template for generating content This tells the AI what format and structure to use

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/ruby_ai_gem_context/platform.rb', line 35

def generation_prompt
  raise NotImplementedError
end

.name ⇒ Object

Human-readable name of the platform

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/ruby_ai_gem_context/platform.rb', line 13

def name
  raise NotImplementedError
end

.path ⇒ Object

Where the file should be placed relative to project root Most platforms expect files at the project root



24
25
26
# File 'lib/ruby_ai_gem_context/platform.rb', line 24

def path
  filename
end

.read(project_root = Dir.pwd) ⇒ Object

Read existing content



63
64
65
66
67
# File 'lib/ruby_ai_gem_context/platform.rb', line 63

def read(project_root = Dir.pwd)
  return nil unless exists?(project_root)

  File.read(full_path(project_root))
end

.template ⇒ Object

Template content for empty boilerplate

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/ruby_ai_gem_context/platform.rb', line 40

def template
  raise NotImplementedError
end

.write(content, project_root = Dir.pwd) ⇒ Object

Write content to the context file



55
56
57
58
59
60
# File 'lib/ruby_ai_gem_context/platform.rb', line 55

def write(content, project_root = Dir.pwd)
  file_path = full_path(project_root)
  FileUtils.mkdir_p(File.dirname(file_path))
  File.write(file_path, content)
  file_path
end