Class: Agentilda::Creator
- Inherits:
-
Object
- Object
- Agentilda::Creator
- Defined in:
- lib/agentilda/creator.rb
Overview
Mints new plan folders. Backs /spec-create.
Every failure is a Failure, never an exception: creating a folder is the
one place a typo becomes permanent, so the caller is made to look.
Constant Summary collapse
- DEFAULT_STATUS =
The state a new plan opens in — a specification and nothing else yet.
:new- RETROACTIVE_STATUS =
The state a retroactive plan is born in: the work is live, but it has neither a specification nor a plan.
:retroactive
Instance Attribute Summary collapse
-
#dir ⇒ String
readonly
The
.plansdirectory.
Class Method Summary collapse
-
.slugify(words) ⇒ String
Turn free text into the kebab tail of a folder name.
Instance Method Summary collapse
-
#create(words:, after: nil, status: nil, prs: nil) ⇒ Dry::Monads::Result
Create a plan folder.
-
#existing ⇒ Array<Agentilda::Ordinal>
Every number already taken.
-
#initialize(dir:) ⇒ Creator
constructor
A new instance of Creator.
Constructor Details
#initialize(dir:) ⇒ Creator
Returns a new instance of Creator.
19 20 21 |
# File 'lib/agentilda/creator.rb', line 19 def initialize(dir:) @dir = File.(dir) end |
Instance Attribute Details
#dir ⇒ String (readonly)
Returns the .plans directory.
24 25 26 |
# File 'lib/agentilda/creator.rb', line 24 def dir @dir end |
Class Method Details
.slugify(words) ⇒ String
Turn free text into the kebab tail of a folder name.
64 65 66 |
# File 'lib/agentilda/creator.rb', line 64 def self.slugify(words) Array(words).join(" ").downcase.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "") end |
Instance Method Details
#create(words:, after: nil, status: nil, prs: nil) ⇒ Dry::Monads::Result
Create a plan folder.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/agentilda/creator.rb', line 34 def create(words:, after: nil, status: nil, prs: nil) resolved = resolve_status(status, after) or return Failure("unknown status: #{status}") slug = self.class.slugify(words) return Failure("the topic produced an empty slug") if slug.empty? ordinal = after ? retroactive_ordinal(after) : Ordinal.next_major(existing) return ordinal if ordinal.is_a?(Dry::Monads::Result) build(ordinal, resolved, slug).fmap { |path| record_pull_requests(path, prs) } rescue Agentilda::Error => e Failure(e.) end |
#existing ⇒ Array<Agentilda::Ordinal>
Returns every number already taken.
50 51 52 53 54 55 56 57 58 |
# File 'lib/agentilda/creator.rb', line 50 def existing @existing ||= begin return [] unless File.directory?(dir) Dir.children(dir) .select { |c| File.directory?(File.join(dir, c)) } .filter_map { |c| Ordinal.from_dirname(c) } end end |