Class: Rufio::DirectoryListing

Inherits:
Object
  • Object
show all
Defined in:
lib/rufio/directory_listing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = Dir.pwd) ⇒ DirectoryListing

Returns a new instance of DirectoryListing.



9
10
11
12
13
14
# File 'lib/rufio/directory_listing.rb', line 9

def initialize(path = Dir.pwd)
  @current_path = File.expand_path(path)
  @start_directory = @current_path  # 起動時のディレクトリを保存
  @entries = []
  refresh
end

Instance Attribute Details

#current_pathObject (readonly)

Returns the value of attribute current_path.



7
8
9
# File 'lib/rufio/directory_listing.rb', line 7

def current_path
  @current_path
end

#start_directoryObject (readonly)

Returns the value of attribute start_directory.



7
8
9
# File 'lib/rufio/directory_listing.rb', line 7

def start_directory
  @start_directory
end

Instance Method Details

#list_entriesObject



16
17
18
# File 'lib/rufio/directory_listing.rb', line 16

def list_entries
  @entries
end


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rufio/directory_listing.rb', line 35

def navigate_to(target)
  return false if target.nil? || target.empty?

  new_path = File.join(@current_path, target)

  if File.directory?(new_path) && File.readable?(new_path)
    @current_path = File.expand_path(new_path)
    refresh
    true
  else
    false
  end
end


49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rufio/directory_listing.rb', line 49

def navigate_to_parent
  parent_path = File.dirname(@current_path)

  # 同じパスの場合は移動しない(ルートディレクトリに到達)
  return false if parent_path == @current_path

  if File.directory?(parent_path) && File.readable?(parent_path)
    @current_path = parent_path
    refresh
    true
  else
    false
  end
end


64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rufio/directory_listing.rb', line 64

def navigate_to_path(path)
  return false if path.nil? || path.empty?

  expanded_path = File.expand_path(path)

  if File.directory?(expanded_path) && File.readable?(expanded_path)
    @current_path = expanded_path
    refresh
    true
  else
    false
  end
end

#refreshObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rufio/directory_listing.rb', line 20

def refresh
  return unless File.directory?(@current_path)

  @entries = []

  # NativeScannerが利用可能な場合は使用
  if use_native_scanner?
    scan_with_native_scanner
  else
    scan_with_ruby
  end

  sort_entries!
end