Class: Docker::Id

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/id.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Id

Returns a new instance of Id.



9
10
11
12
# File 'lib/docker/id.rb', line 9

def initialize(id)
  @id = id.to_s[0..11]
  validate!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/docker/id.rb', line 24

def method_missing(method, *args, &block)
  if id.respond_to?(method)
    id.__send__(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#idObject (readonly) Also known as: to_s, to_str

Returns the value of attribute id.



8
9
10
# File 'lib/docker/id.rb', line 8

def id
  @id
end

Class Method Details

.create(id) ⇒ Object



3
4
5
6
# File 'lib/docker/id.rb', line 3

def self.create(id)
  id = new(id)
  id.id.empty? ? nil : id
end

Instance Method Details

#validate!Object



17
18
19
20
21
22
# File 'lib/docker/id.rb', line 17

def validate!
  valid = id.length >= 12 && 
    id =~ /^[0-9a-z]+$/ && id !~ /^[^0-9a-z]$/ &&
    id =~/[0-9]/ && id =~ /[a-z]/
  valid ? id : (@id = '')
end