Class: Gitlab::Audit::Type::Definition
- Inherits:
-
Object
- Object
- Gitlab::Audit::Type::Definition
- Extended by:
- Utils::StrongMemoize
- Includes:
- ActiveModel::Validations, Shared
- Defined in:
- lib/gitlab/audit/type/definition.rb
Constant Summary collapse
- InvalidAuditEventTypeError =
Class.new(StandardError)
- AUDIT_EVENT_TYPE_SCHEMA_PATH =
Rails.root.join('config', 'audit_events', 'types', 'type_schema.json')
- AUDIT_EVENT_TYPE_SCHEMA =
JSONSchemer.schema(AUDIT_EVENT_TYPE_SCHEMA_PATH)
Constants included from Shared
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .declarative_policy_class ⇒ Object
- .defined?(key) ⇒ Boolean
- .definitions ⇒ Object
- .event_names ⇒ Object
- .get(key) ⇒ Object
- .names_with_category ⇒ Object
- .paths ⇒ Object
- .stream_only?(key) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(path, opts = {}) ⇒ Definition
constructor
A new instance of Definition.
- #key ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ Definition
Returns a new instance of Definition.
31 32 33 34 35 36 37 38 39 |
# File 'lib/gitlab/audit/type/definition.rb', line 31 def initialize(path, opts = {}) @path = path @attributes = {} # assign nil, for all unknown opts PARAMS.each do |param| @attributes[param] = opts[param] end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/gitlab/audit/type/definition.rb', line 11 def attributes @attributes end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/gitlab/audit/type/definition.rb', line 10 def path @path end |
Class Method Details
.declarative_policy_class ⇒ Object
16 17 18 |
# File 'lib/gitlab/audit/type/definition.rb', line 16 def self.declarative_policy_class 'AuditEvents::DefinitionPolicy' end |
.defined?(key) ⇒ Boolean
91 92 93 |
# File 'lib/gitlab/audit/type/definition.rb', line 91 def defined?(key) get(key).present? end |
.definitions ⇒ Object
72 73 74 |
# File 'lib/gitlab/audit/type/definition.rb', line 72 def definitions load_all! end |
.event_names ⇒ Object
81 82 83 |
# File 'lib/gitlab/audit/type/definition.rb', line 81 def event_names definitions.keys.map(&:to_s) end |
.get(key) ⇒ Object
77 78 79 |
# File 'lib/gitlab/audit/type/definition.rb', line 77 def get(key) definitions[key.to_sym] end |
.names_with_category ⇒ Object
85 86 87 88 89 |
# File 'lib/gitlab/audit/type/definition.rb', line 85 def names_with_category definitions.map do |event_name, value| { event_name: event_name, feature_category: value.attributes[:feature_category] } end end |
.paths ⇒ Object
68 69 70 |
# File 'lib/gitlab/audit/type/definition.rb', line 68 def paths @paths ||= [Rails.root.join('config', 'audit_events', 'types', '*.yml')] end |
.stream_only?(key) ⇒ Boolean
95 96 97 98 99 100 |
# File 'lib/gitlab/audit/type/definition.rb', line 95 def stream_only?(key) event_definition = get(key) return false unless event_definition event_definition.streamed && !event_definition.saved_to_database end |
Instance Method Details
#key ⇒ Object
41 42 43 |
# File 'lib/gitlab/audit/type/definition.rb', line 41 def key name.to_sym end |