Class: Gitlab::Tracking::EventDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/tracking/event_definition.rb

Constant Summary collapse

EVENT_SCHEMA_PATH =
Rails.root.join('config', 'events', 'schema.json')
BASE_REPO_PATH =
'https://gitlab.com/gitlab-org/gitlab/-/blob/master'
SCHEMA =
::JSONSchemer.schema(Pathname.new(EVENT_SCHEMA_PATH))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, opts = {}) ⇒ EventDefinition

Returns a new instance of EventDefinition.


46
47
48
49
# File 'lib/gitlab/tracking/event_definition.rb', line 46

def initialize(path, opts = {})
  @path = path
  @attributes = opts
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)


76
77
78
# File 'lib/gitlab/tracking/event_definition.rb', line 76

def method_missing(method, *args)
  attributes[method] || super
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.


13
14
15
# File 'lib/gitlab/tracking/event_definition.rb', line 13

def attributes
  @attributes
end

#pathObject (readonly)

Returns the value of attribute path.


12
13
14
# File 'lib/gitlab/tracking/event_definition.rb', line 12

def path
  @path
end

Class Method Details

.definitionsObject


20
21
22
23
24
# File 'lib/gitlab/tracking/event_definition.rb', line 20

def definitions
  paths.each_with_object({}) do |glob_path, definitions|
    load_all_from_path!(definitions, glob_path)
  end
end

.pathsObject


16
17
18
# File 'lib/gitlab/tracking/event_definition.rb', line 16

def paths
  @paths ||= [Rails.root.join('config', 'events', '*.yml'), Rails.root.join('ee', 'config', 'events', '*.yml')]
end

Instance Method Details

#to_hObject Also known as: to_dictionary


51
52
53
# File 'lib/gitlab/tracking/event_definition.rb', line 51

def to_h
  attributes
end

#validate!Object


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gitlab/tracking/event_definition.rb', line 60

def validate!
  SCHEMA.validate(attributes.stringify_keys).each do |error|
    error_message = <<~ERROR_MSG
      Error type: #{error['type']}
      Data: #{error['data']}
      Path: #{error['data_pointer']}
      Details: #{error['details']}
      Definition file: #{path}
    ERROR_MSG

    Gitlab::ErrorTracking.track_and_raise_for_dev_exception(Gitlab::Tracking::InvalidEventError.new(error_message))
  end
end

#yaml_pathObject


56
57
58
# File 'lib/gitlab/tracking/event_definition.rb', line 56

def yaml_path
  path.delete_prefix(Rails.root.to_s)
end