[フレーム]

Module: Vips::Yard

Defined in:
lib/vips/image.rb

Overview

This module generates yard comments for all the dynamically bound vips operations.

Regenerate with something like:

$ ruby > methods.rb
require "vips"; Vips::Yard.generate
^D

Constant Summary collapse

MAP_GO_TO_RUBY =

map gobject's type names to Ruby

{
 "gboolean" => "Boolean",
 "gint" => "Integer",
 "gdouble" => "Float",
 "gfloat" => "Float",
 "gchararray" => "String",
 "VipsImage" => "Vips::Image",
 "VipsInterpolate" => "Vips::Interpolate",
 "VipsConnection" => "Vips::Connection",
 "VipsSource" => "Vips::Source",
 "VipsTarget" => "Vips::Target",
 "VipsSourceCustom" => "Vips::SourceCustom",
 "VipsTargetCustom" => "Vips::TargetCustom",
 "VipsArrayDouble" => "Array<Double>",
 "VipsArrayInt" => "Array<Integer>",
 "VipsArrayImage" => "Array<Image>",
 "VipsArrayString" => "Array<String>"
}
NO_GENERATE =

these have hand-written methods, see above

["scale", "bandjoin", "composite", "ifthenelse"]
ALIAS =

these are aliased (appear under several names)

["crop"]

Class Method Summary collapse

Class Method Details

.generateObject

1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
# File 'lib/vips/image.rb', line 1680
def self.generate
 alias_gtypes = {}
 ALIAS .each do |name|
 gtype = Vips .type_find "VipsOperation", name
 alias_gtypes[gtype] = name
 end
 generate_class = lambda do |gtype, _|
 name = if alias_gtypes.key? gtype
 alias_gtypes[gtype]
 else
 Vips .nickname_find gtype
 end
 if name
 begin
 # can fail for abstract types
 introspect = Vips ::Introspect .get_yard  name
 rescue Vips ::Error 
 nil
 end
 generate_operation(introspect) if introspect
 end
 Vips .vips_type_map gtype, generate_class, nil
 end
 puts "module Vips"
 puts " class Image"
 puts ""
 generate_class.call(GObject .g_type_from_name("VipsOperation"), nil)
 puts " end"
 puts "end"
end

.generate_operation(introspect) ⇒ Object

1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
# File 'lib/vips/image.rb', line 1613
def self.generate_operation introspect
 return if (introspect.flags & OPERATION_DEPRECATED) != 0
 return if NO_GENERATE .include? introspect.name
 method_args = introspect.method_args
 required_output = introspect.required_output
 optional_input = introspect.optional_input
 optional_output = introspect.optional_output
 print "# @!method "
 print "self." unless introspect.member_x
 print "#{introspect.name}("
 print method_args.map { |x| x[:yard_name] }.join(", ")
 print ", " if method_args.length > 0
 puts "**opts)"
 puts "# #{introspect.description.capitalize}."
 method_args.each do |details|
 yard_name = details[:yard_name]
 gtype = details[:gtype]
 blurb = details[:blurb]
 puts "# @param #{yard_name} [#{gtype_to_ruby(gtype)}] #{blurb}"
 end
 puts "# @param opts [Hash] Set of options"
 optional_input.each do |arg_name, details|
 yard_name = details[:yard_name]
 gtype = details[:gtype]
 blurb = details[:blurb]
 puts "# @option opts [#{gtype_to_ruby(gtype)}] :#{yard_name}#{blurb}"
 end
 optional_output.each do |arg_name, details|
 yard_name = details[:yard_name]
 gtype = details[:gtype]
 blurb = details[:blurb]
 print "# @option opts [#{gtype_to_ruby(gtype)}] :#{yard_name}"
 puts " Output #{blurb}"
 end
 print "# @return ["
 if required_output.length == 0
 print "nil"
 elsif required_output.length == 1
 print gtype_to_ruby(required_output.first[:gtype])
 else
 print "Array<"
 print required_output.map { |x| gtype_to_ruby(x[:gtype]) }.join(", ")
 print ">"
 end
 if optional_output.length > 0
 print ", Hash<Symbol => Object>"
 end
 print "] "
 print required_output.map { |x| x[:blurb] }.join(", ")
 if optional_output.length > 0
 print ", " if required_output.length > 0
 print "Hash of optional output items"
 end
 puts ""
 puts ""
end

.gtype_to_ruby(gtype) ⇒ Object

turn a gtype into a ruby type name

1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
# File 'lib/vips/image.rb', line 1597
def self.gtype_to_ruby gtype
 fundamental = GObject .g_type_fundamental gtype
 type_name = GObject .g_type_name gtype
 if MAP_GO_TO_RUBY .include? type_name
 type_name = MAP_GO_TO_RUBY [type_name]
 end
 if fundamental == GObject ::GFLAGS_TYPE  ||
 fundamental == GObject ::GENUM_TYPE 
 type_name = "Vips::" + type_name[/Vips(.*)/, 1]
 end
 type_name
end

AltStyle によって変換されたページ (->オリジナル) /