Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dsl/prototype.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# typed: false
# typed: true
# frozen_string_literal: true

#: self as Roast::DSL::Executor

config do
cmd(:echo) { print_all! }
end
Expand Down
11 changes: 9 additions & 2 deletions lib/roast/dsl/cog/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ def merge(config_object)
self.class.new(values.merge(config_object.values))
end

def configure!(&block)
instance_exec(&block)
# It is recommended to implement a custom config object for a nicer interface,
# but for simple cases where it would just be a key value store we provide one by default.

def []=(key, value)
@values[key] = value
end

def [](key)
@values[key]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/roast/dsl/config_context.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Roast
Expand Down
2 changes: 1 addition & 1 deletion lib/roast/dsl/execution_context.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Roast
Expand Down
2 changes: 2 additions & 0 deletions lib/roast/dsl/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ def completed?
@completed ||= false
end

#: { () [self: ConfigContext] -> void} -> void
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This RBS type is what allows us to transparently rebind the self of the config and execute blocks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this

def config(&block)
@config_proc = block
end

#: { () [self: ExecutionContext] -> void} -> void
def execute(&block)
@execution_proc = block
end
Expand Down
11 changes: 11 additions & 0 deletions sorbet/rbi/shims/lib/roast/dsl/config_context.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# typed: true
# frozen_string_literal: true

module Roast
module DSL
class ConfigContext
#: (?Symbol?) {() [self: Roast::DSL::Cogs::Cmd::Config] -> void} -> void
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handwriting RBIs is a stopgap - I'll investigate doing this via a Tapioca compiler next, which will also give the same benefits to third party cogs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it makes sense to get it working first in a bare-bones way before investing in automation

def cmd(name = nil, &block); end
end
end
end
11 changes: 11 additions & 0 deletions sorbet/rbi/shims/lib/roast/dsl/execution_context.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# typed: true
# frozen_string_literal: true

module Roast
module DSL
class ExecutionContext
#: (?Symbol?) {() [self: Roast::DSL::Cogs::Cmd] -> String} -> void
def cmd(name = nil, &block); end
end
end
end