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')
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.



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

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)



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

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.definitionsObject



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

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

.pathsObject



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

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



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

def to_h
  attributes
end

#validate!Object



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

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



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

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