Class: WritersRoom::ContextDetector
- Inherits:
-
Object
- Object
- WritersRoom::ContextDetector
- Defined in:
- lib/writers_room/context_detector.rb
Overview
Inspects the current working directory to determine project context. Returns a Context struct describing what the user is working on.
Defined Under Namespace
Classes: Context
Instance Method Summary collapse
- #detect ⇒ Object
-
#initialize(cwd = Dir.pwd) ⇒ ContextDetector
constructor
A new instance of ContextDetector.
Constructor Details
#initialize(cwd = Dir.pwd) ⇒ ContextDetector
Returns a new instance of ContextDetector.
17 18 19 |
# File 'lib/writers_room/context_detector.rb', line 17 def initialize(cwd = Dir.pwd) @cwd = File.(cwd) end |
Instance Method Details
#detect ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/writers_room/context_detector.rb', line 21 def detect project_path = find_project_root return no_project_context unless project_path = ProjectMetadata.new(project_path) medium = MediumRegistry.find(.medium.to_sym) rescue MediumRegistry.find(:dialog) element_type = detect_element_type(project_path, medium) state = ProjectState.new(project_path, medium: medium) Context.new( project_path: project_path, medium: medium, element_type: element_type, element_slug: nil, project_state: state, in_project?: true ) end |