Class: AppMap::Feature::Function

Inherits:
Base show all
Defined in:
lib/appmap/feature.rb

Overview

Function is a feature which represents a code function. It can be an instance function or static (aka ‘class’) function. Instance functions operate on the instance data of the class on which they are defined. Static functions are used to perform operations which don’t have want or need of instance data.

  • ‘handler_id` If provided, identifies a trace handler which can apply specialized logic to the event data which is recorded for this function. For example, if the function represents a handler method for a web server, the custom handler can inspect and record the HTTP request method and path info.

Instance Attribute Summary collapse

Attributes inherited from Base

#children, #parent

Attributes inherited from FeatureStruct

#attributes, #location, #name

Instance Method Summary collapse

Methods inherited from Base

#add_child, #collect_functions, #enclosing_type_name, #enclosing_type_name?, expand_path, #include_option, #initialize, #prune, #prune?, #remove_child, #reparent, #to_json, #type?

Constructor Details

This class inherits a constructor from AppMap::Feature::Base

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



231
232
233
# File 'lib/appmap/feature.rb', line 231

def class_name
  @class_name
end

#handler_idObject

Returns the value of attribute handler_id.



231
232
233
# File 'lib/appmap/feature.rb', line 231

def handler_id
  @handler_id
end

#staticObject Also known as: static?

Returns the value of attribute static.



231
232
233
# File 'lib/appmap/feature.rb', line 231

def static
  @static
end

Instance Method Details

#instance?Boolean

Returns:

  • (Boolean)


234
235
236
# File 'lib/appmap/feature.rb', line 234

def instance?
  !static?
end

#to_hObject



243
244
245
246
247
248
249
# File 'lib/appmap/feature.rb', line 243

def to_h
  super.tap do |h|
    # Suppress the class name when it can be inferred from the enclosing type.
    h[:class_name] = class_name if class_name && class_name != enclosing_type_name.join('::')
    h[:static] = static?
  end
end

#valid?Boolean

Static functions must have an enclosing class defined in order to be traced.

Returns:

  • (Boolean)


239
240
241
# File 'lib/appmap/feature.rb', line 239

def valid?
  super && (instance? || !class_name.blank?)
end