Class: Docker::UniversalFileMode
- Inherits:
-
Object
- Object
- Docker::UniversalFileMode
- 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
- .bit_for(name) ⇒ Object
- .file_mode_mask ⇒ Object
- .flags ⇒ Object
- .short_flag_for(name) ⇒ Object
- .type_mode_mask ⇒ Object
- .value_for(name) ⇒ Object
Instance Method Summary collapse
- #file_mode ⇒ Object
- #flags ⇒ Object
-
#initialize(value) ⇒ UniversalFileMode
constructor
A new instance of UniversalFileMode.
- #regular? ⇒ Boolean
- #short_flags ⇒ Object
- #to_s ⇒ Object
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_mask ⇒ Object
127 128 129 |
# File 'lib/drydock/docker_api_patch.rb', line 127 def self.file_mode_mask 0777 end |
.flags ⇒ Object
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_mask ⇒ Object
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_mode ⇒ Object
147 148 149 |
# File 'lib/drydock/docker_api_patch.rb', line 147 def file_mode (@value & self.class.file_mode_mask) end |
#flags ⇒ Object
151 152 153 |
# File 'lib/drydock/docker_api_patch.rb', line 151 def flags self.class.flags.select { |name| send("#{name}?") } end |
#regular? ⇒ Boolean
155 156 157 |
# File 'lib/drydock/docker_api_patch.rb', line 155 def regular? (@value & self.class.type_mode_mask) == 0 end |
#short_flags ⇒ Object
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_s ⇒ Object
163 164 165 |
# File 'lib/drydock/docker_api_patch.rb', line 163 def to_s short_flags.join end |