Class: Xattr
- Inherits:
-
Object
- Object
- Xattr
- Includes:
- Enumerable
- Defined in:
- lib/ffi-xattr/error.rb,
lib/ffi-xattr.rb,
lib/ffi-xattr/version.rb,
lib/ffi-xattr/linux_lib.rb,
lib/ffi-xattr/darwin_lib.rb,
lib/ffi-xattr/freebsd_lib.rb,
lib/ffi-xattr/windows_lib.rb
Overview
:nodoc: all
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
-
#each(&blk) ⇒ Object
Iterates over pairs of extended attribute names and values.
-
#get(key) ⇒ Object
(also: #[])
Get an extended attribute value.
-
#initialize(path, options = {}) ⇒ Xattr
constructor
Create a new Xattr instance with path.
-
#list ⇒ Object
List extended attribute names.
-
#remove(key) ⇒ Object
Remove an extended attribute value.
-
#set(key, value) ⇒ Object
(also: #[]=)
Set an extended attribute value.
-
#to_hash ⇒ Object
(also: #to_h)
Returns hash of extended attributes.
Constructor Details
#initialize(path, options = {}) ⇒ Xattr
Create a new Xattr instance with path. Use :no_follow => true in options to work on symlink itself instead of following it.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ffi-xattr.rb', line 23 def initialize(path, = {}) @path = if path.respond_to?(:to_path) path.to_path elsif path.respond_to?(:to_str) path.to_str else path end raise Errno::ENOENT, @path unless File.exist?(@path) @no_follow = !![:no_follow] end |
Instance Method Details
#as_json(*args) ⇒ Object
77 78 79 |
# File 'lib/ffi-xattr.rb', line 77 def as_json(*args) to_hash end |
#each(&blk) ⇒ Object
Iterates over pairs of extended attribute names and values
60 61 62 63 64 |
# File 'lib/ffi-xattr.rb', line 60 def each(&blk) list.each do |key| yield key, get(key) end end |
#get(key) ⇒ Object Also known as: []
Get an extended attribute value
43 44 45 |
# File 'lib/ffi-xattr.rb', line 43 def get(key) Lib.get @path, @no_follow, key.to_s end |
#list ⇒ Object
List extended attribute names
38 39 40 |
# File 'lib/ffi-xattr.rb', line 38 def list Lib.list @path, @no_follow end |
#remove(key) ⇒ Object
Remove an extended attribute value
55 56 57 |
# File 'lib/ffi-xattr.rb', line 55 def remove(key) Lib.remove @path, @no_follow, key.to_s end |
#set(key, value) ⇒ Object Also known as: []=
Set an extended attribute value
49 50 51 |
# File 'lib/ffi-xattr.rb', line 49 def set(key, value) Lib.set @path, @no_follow, key.to_s, value.to_s end |
#to_hash ⇒ Object Also known as: to_h
Returns hash of extended attributes
68 69 70 71 72 73 |
# File 'lib/ffi-xattr.rb', line 68 def to_hash res = {} each { |k,v| res[k] = v } res end |