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/windows_lib.rb
Overview
:nodoc: all
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
-
#as_json(*args) ⇒ Object
Returns hash of extended attributes.
-
#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.
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.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ffi-xattr.rb', line 21 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
Returns hash of extended attributes
65 66 67 68 69 70 |
# File 'lib/ffi-xattr.rb', line 65 def as_json(*args) res = {} each { |k,v| res[k] = v } res end |
#each(&blk) ⇒ Object
Iterates over pairs of extended attribute names and values
58 59 60 61 62 |
# File 'lib/ffi-xattr.rb', line 58 def each(&blk) list.each do |key| yield key, get(key) end end |
#get(key) ⇒ Object Also known as: []
Get an extended attribute value
41 42 43 |
# File 'lib/ffi-xattr.rb', line 41 def get(key) Lib.get @path, @no_follow, key.to_s end |
#list ⇒ Object
List extended attribute names
36 37 38 |
# File 'lib/ffi-xattr.rb', line 36 def list Lib.list @path, @no_follow end |