Class: Hook0::EventType

Inherits:
Object
  • Object
show all
Defined in:
lib/hook0/client.rb

Overview

An event type, read out of the service.resource_type.verb it is written as.

Constant Summary collapse

PATTERN =

What an event type reads as.

/\A([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, resource_type, verb) ⇒ EventType

Returns a new instance of EventType.

Parameters:

  • service (String)
  • resource_type (String)
  • verb (String)


313
314
315
316
317
318
# File 'lib/hook0/client.rb', line 313

def initialize(service, resource_type, verb)
  @service = service
  @resource_type = resource_type
  @verb = verb
  freeze
end

Instance Attribute Details

#resource_typeString (readonly)

Returns the middle segment.

Returns:

  • (String)

    the middle segment



305
306
307
# File 'lib/hook0/client.rb', line 305

def resource_type
  @resource_type
end

#serviceString (readonly)

Returns the leading segment.

Returns:

  • (String)

    the leading segment



302
303
304
# File 'lib/hook0/client.rb', line 302

def service
  @service
end

#verbString (readonly)

Returns the trailing segment.

Returns:

  • (String)

    the trailing segment



308
309
310
# File 'lib/hook0/client.rb', line 308

def verb
  @verb
end

Class Method Details

.parse(written) ⇒ EventType

Reads an event type, refusing one that does not name all three of its parts.

Parameters:

  • written (String)

Returns:

Raises:



325
326
327
328
329
330
# File 'lib/hook0/client.rb', line 325

def self.parse(written)
  read = PATTERN.match(written.to_s)
  raise ClientError.invalid_event_type(written) if read.nil?

  new(read[1], read[2], read[3])
end

Instance Method Details

#to_sString

Returns the event type as the API reads one.

Returns:

  • (String)

    the event type as the API reads one



333
334
335
# File 'lib/hook0/client.rb', line 333

def to_s
  "#{@service}.#{@resource_type}.#{@verb}"
end