Class: Hook0::EventType
- Inherits:
-
Object
- Object
- Hook0::EventType
- 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
-
#resource_type ⇒ String
readonly
The middle segment.
-
#service ⇒ String
readonly
The leading segment.
-
#verb ⇒ String
readonly
The trailing segment.
Class Method Summary collapse
-
.parse(written) ⇒ EventType
Reads an event type, refusing one that does not name all three of its parts.
Instance Method Summary collapse
-
#initialize(service, resource_type, verb) ⇒ EventType
constructor
A new instance of EventType.
-
#to_s ⇒ String
The event type as the API reads one.
Constructor Details
#initialize(service, resource_type, verb) ⇒ EventType
Returns a new instance of EventType.
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_type ⇒ String (readonly)
Returns the middle segment.
305 306 307 |
# File 'lib/hook0/client.rb', line 305 def resource_type @resource_type end |
#service ⇒ String (readonly)
Returns the leading segment.
302 303 304 |
# File 'lib/hook0/client.rb', line 302 def service @service end |
#verb ⇒ String (readonly)
Returns 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.
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_s ⇒ String
Returns 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 |