Class: FluentECS::Container

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fluent_ecs/container.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Container

Returns a new instance of Container.



15
16
17
18
19
# File 'lib/fluent_ecs/container.rb', line 15

def initialize(attrs = {})
  @docker_id   = attrs['DockerId']
  @docker_name = attrs['DockerName']
  @name        = attrs['Name']
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &_block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/fluent_ecs/container.rb', line 21

def method_missing(method_id, *args, &_block)
  if method_id == :to_h
    self.class.class_eval hash_definition
    to_h
  else
    super
  end
end

Instance Attribute Details

#docker_idObject

Returns the value of attribute docker_id.



4
5
6
# File 'lib/fluent_ecs/container.rb', line 4

def docker_id
  @docker_id
end

#docker_nameObject

Returns the value of attribute docker_name.



4
5
6
# File 'lib/fluent_ecs/container.rb', line 4

def docker_name
  @docker_name
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/fluent_ecs/container.rb', line 4

def name
  @name
end

#taskObject

Returns the value of attribute task.



4
5
6
# File 'lib/fluent_ecs/container.rb', line 4

def task
  @task
end

Class Method Details

.cacheObject



45
46
47
48
49
50
# File 'lib/fluent_ecs/container.rb', line 45

def cache
  @cache ||= LruRedux::TTL::ThreadSafeCache.new(
    FluentECS.config.cache_size,
    FluentECS.config.cache_ttl
  )
end

.find(docker_id) ⇒ Object



52
53
54
55
56
57
# File 'lib/fluent_ecs/container.rb', line 52

def find(docker_id)
  cache.getset(docker_id) do
    Metadata.take.containers.each { |c| cache[c.docker_id] = c }
    cache[docker_id] # cache value nil if container is not in response
  end
end

Instance Method Details

#respond_to_missing?(method_id, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/fluent_ecs/container.rb', line 30

def respond_to_missing?(method_id, include_private = false)
  method_id == :to_h || super
end