Class: Terminalwire::Shells::Collection
- Inherits:
-
Object
- Object
- Terminalwire::Shells::Collection
- Includes:
- Enumerable
- Defined in:
- lib/terminalwire/shells.rb
Overview
Encapsulates a collection of shells.
Instance Attribute Summary collapse
-
#shells ⇒ Object
readonly
Returns the value of attribute shells.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
- #files ⇒ Object
- #find_by_shell(name) ⇒ Object
- #find_by_shell_path(path) ⇒ Object
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
- #interactive_files ⇒ Object
- #login_files ⇒ Object
- #logout_files ⇒ Object
- #names ⇒ Object
- #shell(name) ⇒ Object
Constructor Details
#initialize ⇒ Collection
Returns a new instance of Collection.
50 51 52 |
# File 'lib/terminalwire/shells.rb', line 50 def initialize @shells = [] end |
Instance Attribute Details
#shells ⇒ Object (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
#each ⇒ Object
58 59 60 |
# File 'lib/terminalwire/shells.rb', line 58 def each(&) shells.each(&) end |
#files ⇒ Object
87 88 89 |
# File 'lib/terminalwire/shells.rb', line 87 def files login_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_files ⇒ Object
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_files ⇒ Object
62 63 64 |
# File 'lib/terminalwire/shells.rb', line 62 def login_files shells.flat_map { |shell| shell.login_files.to_a }.reject(&:empty?) end |
#logout_files ⇒ Object
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 |
#names ⇒ Object
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 |