Class: SSH::Bookmarks::Config
- Inherits:
-
Object
- Object
- SSH::Bookmarks::Config
- Defined in:
- lib/ssh/bookmarks.rb
Overview
This class handle the configuration file
Constant Summary collapse
- PATH =
Constant which stored path of ssh config file
"#{ENV['HOME']}/.ssh/config"
- OPTIONS =
Constant which stored of array custom options of ssh config
%w(hidden)
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#comment?(block) ⇒ Boolean
private
Determine whether the block is comment?.
-
#construct(raw) ⇒ Hash
private
Parse and build configuration.
-
#exist? ⇒ Boolean
private
Determine whether the config is exist.
-
#initialize ⇒ Config
constructor
load and initialize parsing configuration file.
-
#option?(block) ⇒ Boolean
private
Determine whether the block in the list of allowed.
-
#options(raw, index) ⇒ Array
private
Parse options placed in comments which allowed in OPTIONS constant.
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
85 86 87 |
# File 'lib/ssh/bookmarks.rb', line 85 def data @data end |
Instance Method Details
#comment?(block) ⇒ Boolean (private)
Determine whether the block is comment?
70 71 72 |
# File 'lib/ssh/bookmarks.rb', line 70 def comment?(block) block[0] == '#' ? true : false end |
#construct(raw) ⇒ Hash (private)
Parse and build configuration
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ssh/bookmarks.rb', line 29 def construct(raw) container = [] raw.each_with_index do |block, index| next if block.empty? || comment?(block) if block[0] == 'Host' container << {} container.last.merge!(options: (raw, index)) end container.last.merge!(block[0].downcase.to_sym => block[1]) if defined? container end container end |
#exist? ⇒ Boolean (private)
Determine whether the config is exist
76 77 78 79 80 81 82 83 |
# File 'lib/ssh/bookmarks.rb', line 76 def exist? # ssh configuration file if File.exist?(PATH) return true else abort "Error: no configuration file is found.\nExpected path: #{path}" end end |
#option?(block) ⇒ Boolean (private)
Determine whether the block in the list of allowed
63 64 65 |
# File 'lib/ssh/bookmarks.rb', line 63 def option?(block) OPTIONS.include?(block[1]) end |
#options(raw, index) ⇒ Array (private)
Parse options placed in comments which allowed in OPTIONS constant
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ssh/bookmarks.rb', line 46 def (raw, index) @prev_index = 0 unless defined? @prev_index = {} index += 1 if index > 0 # catch options between range raw[@prev_index..index].each do |opt| if comment?(opt) && option?(opt) .merge!(opt[1].downcase.to_sym => true) end end @prev_index = index end |