Class: Docker::UniversalFileMode

Inherits:
Object
  • Object
show all
Defined in:
lib/drydock/docker_api_patch.rb

Overview

Go implementation of cross-system file modes: https://golang.org/pkg/os/#FileMode

Constant Summary collapse

BIT_FIELDS =
[
  {directory:        'd'},
  {append_only:      'a'},
  {exclusive:        'l'},
  {temporary:        'T'},
  {link:             'L'},
  {device:           'D'},
  {named_pipe:       'p'},
  {socket:           'S'},
  {setuid:           'u'},
  {setgid:           'g'},
  {character_device: 'c'},
  {sticky:           't'}
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ UniversalFileMode

Returns a new instance of UniversalFileMode.



143
144
145
# File 'lib/drydock/docker_api_patch.rb', line 143

def initialize(value)
  @value = value
end

Class Method Details

.bit_for(name) ⇒ Object



119
120
121
# File 'lib/drydock/docker_api_patch.rb', line 119

def self.bit_for(name)
  32 - 1 - BIT_FIELDS.index { |field| field.keys.first == name }
end

.file_mode_maskObject



127
128
129
# File 'lib/drydock/docker_api_patch.rb', line 127

def self.file_mode_mask
  0777
end

.flagsObject



123
124
125
# File 'lib/drydock/docker_api_patch.rb', line 123

def self.flags
  BIT_FIELDS.map { |field| field.keys.first }
end

.short_flag_for(name) ⇒ Object



131
132
133
# File 'lib/drydock/docker_api_patch.rb', line 131

def self.short_flag_for(name)
  BIT_FIELDS.find { |field| field.keys.first == name }.values.first
end

.type_mode_maskObject



135
136
137
# File 'lib/drydock/docker_api_patch.rb', line 135

def self.type_mode_mask
  value_for(:directory) | value_for(:link) | value_for(:named_pipe) | value_for(:socket) | value_for(:device)
end

.value_for(name) ⇒ Object



139
140
141
# File 'lib/drydock/docker_api_patch.rb', line 139

def self.value_for(name)
  1 << bit_for(name)
end

Instance Method Details

#file_modeObject



147
148
149
# File 'lib/drydock/docker_api_patch.rb', line 147

def file_mode
  (@value & self.class.file_mode_mask)
end

#flagsObject



151
152
153
# File 'lib/drydock/docker_api_patch.rb', line 151

def flags
  self.class.flags.select { |name| send("#{name}?") }
end

#regular?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/drydock/docker_api_patch.rb', line 155

def regular?
  (@value & self.class.type_mode_mask) == 0
end

#short_flagsObject



159
160
161
# File 'lib/drydock/docker_api_patch.rb', line 159

def short_flags
  flags.map { |flag| self.class.short_flag_for(flag) }
end

#to_sObject



163
164
165
# File 'lib/drydock/docker_api_patch.rb', line 163

def to_s
  short_flags.join
end