Class: KubeDSL::EntrypointBuilder
- Inherits:
-
Object
- Object
- KubeDSL::EntrypointBuilder
- Includes:
- StringHelpers
- Defined in:
- lib/kube-dsl/entrypoint_builder.rb
Constant Summary
Constants included from StringHelpers
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
Instance Method Summary collapse
- #entrypoint ⇒ Object
- #entrypoint_rbi ⇒ Object
-
#initialize(builder, &block) ⇒ EntrypointBuilder
constructor
A new instance of EntrypointBuilder.
- #path ⇒ Object
- #rbi_path ⇒ Object
Methods included from StringHelpers
#capitalize, #underscore, #unkeywordify
Constructor Details
#initialize(builder, &block) ⇒ EntrypointBuilder
Returns a new instance of EntrypointBuilder.
9 10 11 12 |
# File 'lib/kube-dsl/entrypoint_builder.rb', line 9 def initialize(builder, &block) @builder = builder @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
7 8 9 |
# File 'lib/kube-dsl/entrypoint_builder.rb', line 7 def block @block end |
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
7 8 9 |
# File 'lib/kube-dsl/entrypoint_builder.rb', line 7 def builder @builder end |
Instance Method Details
#entrypoint ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kube-dsl/entrypoint_builder.rb', line 14 def entrypoint ruby_code = "# typed: strict\n\n#{module_namespace}\n" builder.each_resource do |resource| ns = resource.ref.ruby_namespace.join('::') next if block && !block.call(resource, ns) method_name = method_name_for(resource) ruby_code << "#{indent}def #{method_name}(&block)\n" ruby_code << "#{indent} ::#{ns}::#{resource.ref.kind}.new(&block)\n" ruby_code << "#{indent}end\n\n" end ruby_code.strip! (indent_level - 1).downto(0) do |idx| ruby_code << "\n#{' ' * idx}end" end "#{ruby_code}\n" end |
#entrypoint_rbi ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kube-dsl/entrypoint_builder.rb', line 37 def entrypoint_rbi rbi_code = "# typed: strict\n\n#{module_namespace}\n" builder.each_resource do |resource| ns = resource.ref.ruby_namespace.join('::') next if block && !block.call(resource, ns) method_name = method_name_for(resource) rbi_code << "#{indent}T::Sig::WithoutRuntime.sig { params(block: T.proc.void).returns(::#{ns}::#{resource.ref.kind}) }\n" rbi_code << "#{indent}def #{method_name}(&block); end\n\n" end rbi_code.strip! (indent_level - 1).downto(0) do |idx| rbi_code << "\n#{' ' * idx}end" end "#{rbi_code}\n" end |
#path ⇒ Object
59 60 61 |
# File 'lib/kube-dsl/entrypoint_builder.rb', line 59 def path @path ||= File.join(builder.output_dir, File.dirname(builder.autoload_prefix), 'entrypoint.rb') end |
#rbi_path ⇒ Object
63 64 65 66 67 68 |
# File 'lib/kube-dsl/entrypoint_builder.rb', line 63 def rbi_path @rbi_path ||= begin rbi_path = File.join('sorbet', 'rbi', *path.split(File::SEPARATOR)[1..-1]) "#{rbi_path.chomp('.rb')}.rbi" end end |