This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e97d206
commit c00b76d
Showing
13 changed files
with
108 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
D = Steep::Diagnostic | ||
|
||
target :lib do | ||
signature "sig" | ||
|
||
check "lib" | ||
|
||
configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting | ||
configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'rbs_inline_data' | ||
require 'rbs_inline_data/cli' | ||
require "rbs_inline_data" | ||
require "rbs_inline_data/cli" | ||
|
||
RbsInlineData::CLI.new.run(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module RbsInlineData | ||
class Writer | ||
#:: (Pathname, Array[RbsInlineData::Parser::TypedDefinition]) -> void | ||
def self.write(file, definitions) | ||
new(file, definitions).write | ||
#:: (Array[RbsInlineData::Parser::TypedDefinition], Pathname?) -> void | ||
def self.write(definitions, output_path) | ||
new(definitions).write(output_path) | ||
end | ||
|
||
# @rbs @file: Pathname | ||
# @rbs @definitions: Array[RbsInlineData::Parser::TypedDefinition] | ||
|
||
#:: (Pathname, Array[RbsInlineData::Parser::TypedDefinition]) -> void | ||
def initialize(file, definitions) | ||
@file = file | ||
#:: (Array[RbsInlineData::Parser::TypedDefinition]) -> void | ||
def initialize(definitions) | ||
@definitions = definitions | ||
end | ||
|
||
# () -> void | ||
def write | ||
#:: (Pathname?) -> void | ||
def write(output_path) | ||
return if @definitions.empty? | ||
|
||
puts "file: #{@file}" | ||
rbs = "" | ||
@definitions.each do |definition| | ||
if output_path | ||
output_path.parent.mkpath unless output_path.parent.directory? | ||
output_path.write(build_rbs(@definitions)) | ||
else | ||
puts build_rbs(@definitions) | ||
end | ||
end | ||
|
||
private | ||
|
||
#:: (Array[RbsInlineData::Parser::TypedDefinition]) -> String | ||
def build_rbs(definitions) | ||
rbs_text = "" | ||
definitions.each do |definition| | ||
source = <<~RBS | ||
class #{definition.class_name} | ||
extend Data::_DataClass | ||
#{definition.fields.map { |field| "attr_reader #{field.field_name}: #{field.type}" }.join("\n ")} | ||
def self.new: (*untyped) -> #{definition.class_name} | ||
| (**untyped) -> #{definition.class_name} | ||
def self.new: (*untyped) -> ::#{definition.class_name} | ||
| (**untyped) -> ::#{definition.class_name} | ||
| ... | ||
end | ||
RBS | ||
rbs += source + "\n" | ||
end | ||
|
||
puts rbs | ||
rbs_text += "#{source}\n" | ||
end | ||
rbs_text | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class RbsInlineData::Parser::TypedDefinition | ||
extend Data::_DataClass | ||
attr_reader class_name: String | ||
attr_reader fields: Array[TypedField] | ||
def self.new: (*untyped) -> ::RbsInlineData::Parser::TypedDefinition | ||
| (**untyped) -> ::RbsInlineData::Parser::TypedDefinition | ||
| ... | ||
end | ||
|
||
class RbsInlineData::Parser::TypedField | ||
extend Data::_DataClass | ||
attr_reader field_name: String | ||
attr_reader type: String | ||
def self.new: (*untyped) -> ::RbsInlineData::Parser::TypedField | ||
| (**untyped) -> ::RbsInlineData::Parser::TypedField | ||
| ... | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.