Class: GirFFI::PrettyPrinter
- Inherits:
-
Object
- Object
- GirFFI::PrettyPrinter
- Defined in:
- lib/gir_ffi-pretty_printer/pretty_printer.rb,
lib/gir_ffi-pretty_printer/version.rb
Overview
Main pretty printer
Constant Summary collapse
- VERSION =
"0.0.10"
Instance Method Summary collapse
- #pretty_print(module_name, version = nil) ⇒ Object
- #pretty_print_class(klass) ⇒ Object
- #pretty_print_constant(modul, const_name) ⇒ Object
- #pretty_print_function(modul, mname) ⇒ Object
Instance Method Details
#pretty_print(module_name, version = nil) ⇒ Object
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 |
# File 'lib/gir_ffi-pretty_printer/pretty_printer.rb', line 28 def pretty_print(module_name, version = nil) GirFFI.setup module_name, version arr = [] gir = GObjectIntrospection::IRepository.default modul = Kernel.const_get(module_name) infos = gir.infos module_name arr << "module #{module_name}" infos.each do |info| case info.info_type when :struct, :object begin klass = GirFFI::Builder.build_class info # TODO: Pass in info as well and print more stuff arr << pretty_print_class(klass).indent rescue SyntaxError warn "Skipping #{module_name}::#{info.name}: build failed" end when :constant arr << pretty_print_constant(modul, info.safe_name).indent when :function arr << pretty_print_function(modul, info.safe_name).indent else arr << "# XXX: Don't know how to print #{info.info_type}".indent end end arr << "end\n" arr.join "\n" end |
#pretty_print_class(klass) ⇒ Object
12 13 14 |
# File 'lib/gir_ffi-pretty_printer/pretty_printer.rb', line 12 def pretty_print_class(klass) ClassPrettyPrinter.new(klass).pretty_print end |
#pretty_print_constant(modul, const_name) ⇒ Object
23 24 25 26 |
# File 'lib/gir_ffi-pretty_printer/pretty_printer.rb', line 23 def pretty_print_constant(modul, const_name) value = modul.const_get(const_name) "#{const_name} = #{value.inspect}" end |
#pretty_print_function(modul, mname) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/gir_ffi-pretty_printer/pretty_printer.rb', line 16 def pretty_print_function(modul, mname) modul.setup_method mname.to_s unless modul.methods.include?(mname.to_sym) meth = modul.method mname meth.to_ruby end |