Class: RubyHToGo::EnumDefinition
- Inherits:
-
Object
- Object
- RubyHToGo::EnumDefinition
- Extended by:
- Forwardable
- Defined in:
- _tools/ruby_h_to_go/lib/ruby_h_to_go/enum_definition.rb
Overview
Proxy class for generating go enum
Instance Method Summary collapse
- #generate_go_content ⇒ String
-
#initialize(definition:) ⇒ EnumDefinition
constructor
A new instance of EnumDefinition.
-
#write_go_file(dist_dir) ⇒ Object
Write definition as go file.
Constructor Details
#initialize(definition:) ⇒ EnumDefinition
Returns a new instance of EnumDefinition.
11 12 13 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/enum_definition.rb', line 11 def initialize(definition:) @definition = definition end |
Instance Method Details
#generate_go_content ⇒ String
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/enum_definition.rb', line 28 def generate_go_content go_type_name = GoUtil.snake_to_camel(name) go_enum_lines = [ "// #{go_type_name} is a type for passing `C.#{name}` in and out of package", "type #{go_type_name} int", "", "// #{go_type_name} enumeration", "const (", ] values.each do |value| go_enum_lines << "#{value} #{go_type_name} = C.#{value}" end go_enum_lines << ")" go_enum_lines << "" go_enum_lines << "" go_enum_lines.join("\n") end |
#write_go_file(dist_dir) ⇒ Object
Write definition as go file
17 18 19 20 21 22 23 24 25 |
# File '_tools/ruby_h_to_go/lib/ruby_h_to_go/enum_definition.rb', line 17 def write_go_file(dist_dir) go_file_path = File.join(dist_dir, "enum_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 |