Class: Docker::Event

Inherits:
Object
  • Object
show all
Extended by:
Error
Includes:
Error
Defined in:
lib/docker/event.rb

Overview

This class represents a Docker Event.

Defined Under Namespace

Classes: Actor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_attributes = {}) ⇒ Event

Returns a new instance of Event.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/docker/event.rb', line 56

def initialize(event_attributes = {})
  [:Type, :Action, :Actor, :time, :timeNano, :status, :from].each do |sym|
    value = event_attributes[sym]
    if value.nil?
      value = event_attributes[sym.to_s]
    end
    send("#{sym}=", value)
  end

  if @Actor.nil?
    value = event_attributes[:id]
    if value.nil?
      value = event_attributes['id']
    end
    self.Actor = Actor.new(ID: value)
  end
end

Instance Attribute Details

#ActionObject Also known as: action

Returns the value of attribute Action.



51
52
53
# File 'lib/docker/event.rb', line 51

def Action
  @Action
end

#ActorObject Also known as: actor

Returns the value of attribute Actor.



52
53
54
# File 'lib/docker/event.rb', line 52

def Actor
  @Actor
end

#fromObject

Deprecated interface



54
55
56
# File 'lib/docker/event.rb', line 54

def from
  @from
end

#statusObject

Deprecated interface



54
55
56
# File 'lib/docker/event.rb', line 54

def status
  @status
end

#timeObject

Returns the value of attribute time.



51
52
53
# File 'lib/docker/event.rb', line 51

def time
  @time
end

#timeNanoObject Also known as: time_nano

Returns the value of attribute timeNano.



51
52
53
# File 'lib/docker/event.rb', line 51

def timeNano
  @timeNano
end

#TypeObject Also known as: type

Returns the value of attribute Type.



51
52
53
# File 'lib/docker/event.rb', line 51

def Type
  @Type
end

Class Method Details

.new_event(body, remaining, total) ⇒ Object



44
45
46
47
48
# File 'lib/docker/event.rb', line 44

def new_event(body, remaining, total)
  return if body.nil? || body.empty?
  json = Docker::Util.parse_json(body)
  Docker::Event.new(json)
end

.since(since, opts = {}, conn = Docker.connection, &block) ⇒ Object



40
41
42
# File 'lib/docker/event.rb', line 40

def since(since, opts = {}, conn = Docker.connection, &block)
  stream(opts.merge(:since => since), conn, &block)
end

.stream(opts = {}, conn = Docker.connection, &block) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/docker/event.rb', line 32

def stream(opts = {}, conn = Docker.connection, &block)
  conn.get('/events', opts, :response_block => lambda { |b, r, t|
    b.each_line do |line|
      block.call(new_event(line, r, t))
    end
  })
end

Instance Method Details

#IDObject Also known as: id



74
75
76
# File 'lib/docker/event.rb', line 74

def ID
  self.actor.ID
end

#to_sObject



93
94
95
96
97
98
99
# File 'lib/docker/event.rb', line 93

def to_s
  if type.nil? && action.nil?
    to_s_legacy
  else
    to_s_actor_style
  end
end