Class: Terminalwire::Shells::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/terminalwire/shells.rb

Overview

Encapsulates a collection of shells.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollection

Returns a new instance of Collection.



50
51
52
# File 'lib/terminalwire/shells.rb', line 50

def initialize
  @shells = []
end

Instance Attribute Details

#shellsObject (readonly)

Returns the value of attribute shells.



47
48
49
# File 'lib/terminalwire/shells.rb', line 47

def shells
  @shells
end

Class Method Details

.configure(&block) ⇒ Object



91
92
93
94
95
# File 'lib/terminalwire/shells.rb', line 91

def self.configure(&block)
  Collection.new.tap do |collection|
    collection.instance_eval(&block) if block_given?
  end
end

Instance Method Details

#eachObject



58
59
60
# File 'lib/terminalwire/shells.rb', line 58

def each(&)
  shells.each(&)
end

#filesObject



87
88
89
# File 'lib/terminalwire/shells.rb', line 87

def files
   + interactive_files + logout_files
end

#find_by_shell(name) ⇒ Object



78
79
80
# File 'lib/terminalwire/shells.rb', line 78

def find_by_shell(name)
  shells.find { |shell| shell.name == name }
end

#find_by_shell_path(path) ⇒ Object



82
83
84
85
# File 'lib/terminalwire/shells.rb', line 82

def find_by_shell_path(path)
  return if path.nil?
  find_by_shell(File.basename(path))
end

#interactive_filesObject



66
67
68
# File 'lib/terminalwire/shells.rb', line 66

def interactive_files
  shells.flat_map { |shell| shell.interactive_files.to_a }.reject(&:empty?)
end

#login_filesObject



62
63
64
# File 'lib/terminalwire/shells.rb', line 62

def 
  shells.flat_map { |shell| shell..to_a }.reject(&:empty?)
end

#logout_filesObject



70
71
72
# File 'lib/terminalwire/shells.rb', line 70

def logout_files
  shells.flat_map { |shell| shell.logout_files.to_a }.reject(&:empty?)
end

#namesObject



74
75
76
# File 'lib/terminalwire/shells.rb', line 74

def names
  shells.map(&:name)
end

#shell(name) ⇒ Object



54
55
56
# File 'lib/terminalwire/shells.rb', line 54

def shell(name, &)
  shells << Shell.new(name).configure(&)
end