Class: RubyHToGo::FunctionDefinition
- Inherits:
-
Object
- Object
- RubyHToGo::FunctionDefinition
- Extended by:
- Forwardable
- Defined in:
- _tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb
Overview
Proxy class for generating go function
Instance Method Summary collapse
- #args ⇒ Array<RubyHToGo::ArgumentDefinition>
- #generate_go_content ⇒ String
- #go_function_name ⇒ String
-
#initialize(definition:) ⇒ FunctionDefinition
constructor
A new instance of FunctionDefinition.
- #typeref ⇒ RubyHToGo::TyperefDefinition
-
#write_go_file(dist_dir) ⇒ Object
Write definition as go file.
Constructor Details
#initialize(definition:) ⇒ FunctionDefinition
Returns a new instance of FunctionDefinition.
11 12 13 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb', line 11 def initialize(definition:) @definition = definition end |
Instance Method Details
#args ⇒ Array<RubyHToGo::ArgumentDefinition>
21 22 23 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb', line 21 def args @args ||= @definition.args.map { |arg| RubyHToGo::ArgumentDefinition.new(definition: arg) } end |
#generate_go_content ⇒ String
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb', line 38 def generate_go_content go_function_lines = generate_function_header_lines casted_go_args, before_call_function_lines, after_call_function_lines = analyze_args call_c_method = "C.#{name}(#{casted_go_args.join(", ")})" append_function_body(call_c_method:, go_function_lines:, before_call_function_lines:, after_call_function_lines:) go_function_lines.append("}", "", "") go_function_lines.join("\n") end |
#go_function_name ⇒ String
53 54 55 56 57 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb', line 53 def go_function_name return name if name.match?(/^[A-Z0-9_]+$/) GoUtil.snake_to_camel(name) end |
#typeref ⇒ RubyHToGo::TyperefDefinition
16 17 18 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb', line 16 def typeref @typeref ||= RubyHToGo::TyperefDefinition.new(definition: @definition.typeref) end |
#write_go_file(dist_dir) ⇒ Object
Write definition as go file
27 28 29 30 31 32 33 34 35 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb', line 27 def write_go_file(dist_dir) go_file_path = File.join(dist_dir, "function_generated.go") GoUtil.generate_initial_go_file(go_file_path) File.open(go_file_path, "a") do |f| f.write(generate_go_content) end end |