Class: OneWire::Directory
- Inherits:
-
Object
- Object
- OneWire::Directory
- Includes:
- Retry
- Defined in:
- lib/one_wire/directory.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #directories ⇒ Object
-
#initialize(path, options = {}) ⇒ Directory
constructor
include Enumerable.
- #inspect ⇒ Object
- #ls ⇒ Object
- #members ⇒ Object
- #to_s ⇒ Object
- #tree ⇒ Object
Methods included from Retry
Constructor Details
#initialize(path, options = {}) ⇒ Directory
include Enumerable
6 7 8 9 10 11 12 |
# File 'lib/one_wire/directory.rb', line 6 def initialize(path, = {}) @path = path dirall = .has_key?(:dir_all) ? [:dirall] : Config.dirall @entries = dirall ? with_retry { Transaction.dirall(path) }.response.data.split(",") : with_retry { Transaction.dir(path) }.response.map { |r| r.data } end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
28 29 30 |
# File 'lib/one_wire/directory.rb', line 28 def path @path end |
Instance Method Details
#directories ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/one_wire/directory.rb', line 14 def directories @directories ||= @entries.collect do |entry| begin Directory.new(entry) rescue Errno::ENOTDIR nil end end.compact end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/one_wire/directory.rb', line 46 def inspect to_s end |
#ls ⇒ Object
30 31 32 33 34 |
# File 'lib/one_wire/directory.rb', line 30 def ls [ "+ " + @path.split("/").last.to_s ] + members.map { |member| " . " + member.split("/").last } + directories.map { |directory| " - " + directory.path.split("/").last } end |
#members ⇒ Object
24 25 26 |
# File 'lib/one_wire/directory.rb', line 24 def members @members ||= @entries - directories.map { |directory| directory.path } end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/one_wire/directory.rb', line 42 def to_s ls.join("\n") end |
#tree ⇒ Object
36 37 38 39 40 |
# File 'lib/one_wire/directory.rb', line 36 def tree [ "+ " + @path.split("/").last.to_s ] + members.map { |member| " . " + member.split("/").last } + directories.map { |directory| directory.tree.map { |line| " #{line}"} }.flatten end |