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.



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

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.



49
50
51
# File 'lib/docker/event.rb', line 49

def Action
  @Action
end

#ActorObject Also known as: actor

Returns the value of attribute Actor.



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

def Actor
  @Actor
end

#fromObject

Deprecated interface



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

def from
  @from
end

#statusObject

Deprecated interface



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

def status
  @status
end

#timeObject

Returns the value of attribute time.



49
50
51
# File 'lib/docker/event.rb', line 49

def time
  @time
end

#timeNanoObject Also known as: time_nano

Returns the value of attribute timeNano.



49
50
51
# File 'lib/docker/event.rb', line 49

def timeNano
  @timeNano
end

#TypeObject Also known as: type

Returns the value of attribute Type.



49
50
51
# File 'lib/docker/event.rb', line 49

def Type
  @Type
end

Class Method Details

.new_event(body, remaining, total) ⇒ Object



42
43
44
45
46
# File 'lib/docker/event.rb', line 42

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



38
39
40
# File 'lib/docker/event.rb', line 38

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

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



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

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



72
73
74
# File 'lib/docker/event.rb', line 72

def ID
  self.actor.ID
end

#to_sObject



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

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