Class: Rbind::GeneratorExtern
- Inherits:
-
Object
- Object
- Rbind::GeneratorExtern
- Defined in:
- lib/rbind/generator_extern.rb
Defined Under Namespace
Classes: Config
Instance Attribute Summary collapse
-
#file_prefix ⇒ Object
Returns the value of attribute file_prefix.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#ruby_module_name ⇒ Object
Returns the value of attribute ruby_module_name.
Class Method Summary collapse
Instance Method Summary collapse
- #generate(path = @output_path, ruby_module_name = @ruby_module_name, file_prefix = @file_prefix) ⇒ Object
-
#initialize(root) ⇒ GeneratorExtern
constructor
A new instance of GeneratorExtern.
Constructor Details
#initialize(root) ⇒ GeneratorExtern
Returns a new instance of GeneratorExtern.
18 19 20 |
# File 'lib/rbind/generator_extern.rb', line 18 def initialize(root) @root = root end |
Instance Attribute Details
#file_prefix ⇒ Object
Returns the value of attribute file_prefix.
9 10 11 |
# File 'lib/rbind/generator_extern.rb', line 9 def file_prefix @file_prefix end |
#output_path ⇒ Object
Returns the value of attribute output_path.
7 8 9 |
# File 'lib/rbind/generator_extern.rb', line 7 def output_path @output_path end |
#ruby_module_name ⇒ Object
Returns the value of attribute ruby_module_name.
8 9 10 |
# File 'lib/rbind/generator_extern.rb', line 8 def ruby_module_name @ruby_module_name end |
Class Method Details
.normalize_operation_name(name) ⇒ Object
14 15 16 |
# File 'lib/rbind/generator_extern.rb', line 14 def self.normalize_operation_name(name) name.gsub('::','.').gsub(" ","") end |
.normalize_type_name(name) ⇒ Object
10 11 12 |
# File 'lib/rbind/generator_extern.rb', line 10 def self.normalize_type_name(name) name.gsub('::','.').gsub(" ","") end |
Instance Method Details
#generate(path = @output_path, ruby_module_name = @ruby_module_name, file_prefix = @file_prefix) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rbind/generator_extern.rb', line 22 def generate(path = @output_path,ruby_module_name = @ruby_module_name,file_prefix = @file_prefix) @output_path = path @ruby_module_name = ruby_module_name @file_prefix = file_prefix FileUtils.mkdir_p(path) if path && !File.directory?(path) file_extern = File.new(File.join(path,"extern.rbind"),"w") file_config = File.new(File.join(path,"config.rbind"),"w") #write all types so they get parsed first @root.each_type do |t| if t.is_a? RClass file_extern.write "class #{GeneratorExtern.normalize_type_name(t.full_name)}\n" end end # write all consts @root.each_const do |c| file_extern.write "const #{GeneratorExtern.normalize_type_name(c.full_name)}\n" end #write all operations @root.each_type do |t| if t.is_a? RClass t.each_operation do |op| r = if op.return_type GeneratorExtern.normalize_type_name(op.return_type.full_name) end file_extern.write "#{GeneratorExtern.normalize_operation_name(op.full_name)} #{r}\n" op.parameters.each do |p| file_extern.write " #{GeneratorExtern.normalize_type_name(p.type.full_name)} #{p.name}"\ "#{" #{p.default_value}" if p.default_value}#{" /O" unless p.const?}\n" end end end end file_extern.write("\n") file_config.write Config.new(ruby_module_name,file_prefix).to_yaml end |