Class: Docforge::Inputs

Inherits:
Object
  • Object
show all
Defined in:
lib/docforge/inputs.rb

Overview

Reads a feature folder. Default layout:

<folder>/
  PRD.md     (required — name configurable via input_files.prd)
  SPEC.md    (required — name configurable via input_files.spec)
  notes.md   (optional — name configurable via input_files.notes)
  _assets/   (optional)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, config: Config.new) ⇒ Inputs

Returns a new instance of Inputs.



18
19
20
21
# File 'lib/docforge/inputs.rb', line 18

def initialize(path, config: Config.new)
  @folder = File.expand_path(path)
  @config = config
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



12
13
14
# File 'lib/docforge/inputs.rb', line 12

def assets
  @assets
end

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/docforge/inputs.rb', line 12

def config
  @config
end

#folderObject (readonly)

Returns the value of attribute folder.



12
13
14
# File 'lib/docforge/inputs.rb', line 12

def folder
  @folder
end

#notesObject (readonly)

Returns the value of attribute notes.



12
13
14
# File 'lib/docforge/inputs.rb', line 12

def notes
  @notes
end

#prdObject (readonly)

Returns the value of attribute prd.



12
13
14
# File 'lib/docforge/inputs.rb', line 12

def prd
  @prd
end

#specObject (readonly)

Returns the value of attribute spec.



12
13
14
# File 'lib/docforge/inputs.rb', line 12

def spec
  @spec
end

Class Method Details

.read(path, config: Config.new) ⇒ Object



14
15
16
# File 'lib/docforge/inputs.rb', line 14

def self.read(path, config: Config.new)
  new(path, config: config).tap(&:load!)
end

Instance Method Details

#load!Object

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/docforge/inputs.rb', line 23

def load!
  raise InputError, "Folder not found: #{folder}" unless File.directory?(folder)

  prd_name   = config.input_filenames["prd"]
  spec_name  = config.input_filenames["spec"]
  notes_name = config.input_filenames["notes"]

  prd_path  = locate(prd_name)
  spec_path = locate(spec_name)
  raise InputError, "#{prd_name} not found in #{folder}"  unless prd_path
  raise InputError, "#{spec_name} not found in #{folder}" unless spec_path

  @prd    = File.read(prd_path)
  @spec   = File.read(spec_path)
  notes_p = notes_name ? locate(notes_name) : nil
  @notes  = notes_p ? File.read(notes_p) : nil
  @assets = locate_assets
  self
end

#slugObject



43
44
45
# File 'lib/docforge/inputs.rb', line 43

def slug
  File.basename(folder).downcase.gsub(/[^a-z0-9-]+/, "-").gsub(/^-|-$/, "")
end