Class: Vips::Introspect

Inherits:
Object
  • Object
show all
Defined in:
lib/vips/operation.rb

Overview

Introspect a vips operation and return a large structure containing everything we know about it. This is used for doc generation as well as call.

Constant Summary collapse

@@introspect_cache =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Introspect

Returns a new instance of Introspect.


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/vips/operation.rb', line 54

def initialize name
  @op = Operation.new name
  @args = []
  @required_input = []
  @optional_input = {}
  @required_output = []
  @optional_output = {}

  # find all the arguments the operator can take
  @op.argument_map do |pspec, argument_class, _argument_instance|
    flags = argument_class[:flags]
    if (flags & ARGUMENT_CONSTRUCT) != 0
      # names can include - as punctuation, but we always use _ in
      # Ruby
      arg_name = pspec[:name].tr("-", "_")
      args << {
        :arg_name => arg_name,
        :flags => flags,
        :gtype => pspec[:value_type]
      }
    end
  end

  @args.each do |details|
    arg_name = details[:arg_name]
    flags = details[:flags]

    if (flags & ARGUMENT_INPUT) != 0
      if (flags & ARGUMENT_REQUIRED) != 0 && 
         (flags & ARGUMENT_DEPRECATED) == 0
        @required_input << details
      else
        # we allow deprecated optional args
        @optional_input[arg_name] = details
      end

      # MODIFY INPUT args count as OUTPUT as well
      if (flags & ARGUMENT_MODIFY) != 0
        if (flags & ARGUMENT_REQUIRED) != 0 && 
           (flags & ARGUMENT_DEPRECATED) == 0
          @required_output << details
        else
          @optional_output[arg_name] = details
        end
      end
    elsif (flags & ARGUMENT_OUTPUT) != 0
      if (flags & ARGUMENT_REQUIRED) != 0 && 
         (flags & ARGUMENT_DEPRECATED) == 0
        @required_output << details
      else
        # again, allow deprecated optional args
        @optional_output[arg_name] = details
      end
    end
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args


48
49
50
# File 'lib/vips/operation.rb', line 48

def args
  @args
end

#descriptionObject (readonly)

Returns the value of attribute description


48
49
50
# File 'lib/vips/operation.rb', line 48

def description
  @description
end

#flagsObject (readonly)

Returns the value of attribute flags


48
49
50
# File 'lib/vips/operation.rb', line 48

def flags
  @flags
end

#member_xObject (readonly)

Returns the value of attribute member_x


48
49
50
# File 'lib/vips/operation.rb', line 48

def member_x
  @member_x
end

#method_argsObject (readonly)

Returns the value of attribute method_args


48
49
50
# File 'lib/vips/operation.rb', line 48

def method_args
  @method_args
end

#nameObject (readonly)

Returns the value of attribute name


48
49
50
# File 'lib/vips/operation.rb', line 48

def name
  @name
end

#optional_inputObject (readonly)

Returns the value of attribute optional_input


48
49
50
# File 'lib/vips/operation.rb', line 48

def optional_input
  @optional_input
end

#optional_outputObject (readonly)

Returns the value of attribute optional_output


48
49
50
# File 'lib/vips/operation.rb', line 48

def optional_output
  @optional_output
end

#required_inputObject (readonly)

Returns the value of attribute required_input


48
49
50
# File 'lib/vips/operation.rb', line 48

def required_input
  @required_input
end

#required_outputObject (readonly)

Returns the value of attribute required_output


48
49
50
# File 'lib/vips/operation.rb', line 48

def required_output
  @required_output
end

Class Method Details

.get(name) ⇒ Object


144
145
146
# File 'lib/vips/operation.rb', line 144

def self.get name
  @@introspect_cache[name] ||= Introspect.new name
end

.get_yard(name) ⇒ Object


148
149
150
151
152
# File 'lib/vips/operation.rb', line 148

def self.get_yard name
  introspect = Introspect.get name
  introspect.add_yard_introspection name
  introspect
end

Instance Method Details

#add_yard_introspection(name) ⇒ Object

Yard comment generation needs a little more introspection. We add this extra metadata in a separate method to keep the main path as fast as we can.


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/vips/operation.rb', line 114

def add_yard_introspection name
  @name = name
  @description = Vips::vips_object_get_description @op
  @flags = Vips::vips_operation_get_flags @op
  @member_x = nil
  @method_args = []

  @args.each do |details|
    arg_name = details[:arg_name]
    flags = details[:flags]
    gtype = details[:gtype]

    details[:yard_name] = arg_name == "in" ? "im" : arg_name
    pspec = @op.get_pspec arg_name
    details[:blurb] = GObject::g_param_spec_get_blurb pspec

    if (flags & ARGUMENT_INPUT) != 0 && 
       (flags & ARGUMENT_REQUIRED) != 0 && 
       (flags & ARGUMENT_DEPRECATED) == 0
      # the first required input image is the thing we will be a method 
      # of
      if @member_x == nil && gtype == IMAGE_TYPE
        @member_x = details 
      else
        @method_args << details
      end
    end
  end
end