Class: Utils::Config::ConfigFile

Inherits:
Object
  • Object
show all
Includes:
DSLKit::Interpreter
Defined in:
lib/utils/config/config_file.rb

Defined Under Namespace

Classes: BlockConfig, ConfigFileError, Discover, Edit, FileFinder, Probe, Search, SshTunnel, StripSpaces

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigFile

Returns a new instance of ConfigFile.



18
19
# File 'lib/utils/config/config_file.rb', line 18

def initialize
end

Class Attribute Details

.config_file_pathsObject

Returns the value of attribute config_file_paths.



6
7
8
# File 'lib/utils/config/config_file.rb', line 6

def config_file_paths
  @config_file_paths
end

Instance Method Details

#configure_from_paths(paths = self.class.config_file_paths) ⇒ Object



21
22
23
24
25
# File 'lib/utils/config/config_file.rb', line 21

def configure_from_paths(paths = self.class.config_file_paths)
  for config_file_path in paths
    parse_config_file config_file_path
  end
end

#discover(&block) ⇒ Object



136
137
138
139
140
141
# File 'lib/utils/config/config_file.rb', line 136

def discover(&block)
  if block
    @discover = Discover.new(&block)
  end
  @discover ||= Discover.new
end

#edit(&block) ⇒ Object



240
241
242
243
244
245
# File 'lib/utils/config/config_file.rb', line 240

def edit(&block)
  if block
    @edit = Edit.new(&block)
  end
  @edit ||= Edit.new
end

#parse(source) ⇒ Object



39
40
41
42
# File 'lib/utils/config/config_file.rb', line 39

def parse(source)
  interpret_with_binding source, binding
  self
end

#parse_config_file(config_file_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/utils/config/config_file.rb', line 27

def parse_config_file(config_file_path)
  config_file_path = File.expand_path(config_file_path)
  File.open(config_file_path) do |cf|
    parse cf.read
  end
  self
rescue SystemCallError => e
  $DEBUG and warn "Couldn't read config file "\
    "#{config_file_path.inspect}: #{e.class} #{e}"
  return nil
end

#probe(&block) ⇒ Object



98
99
100
101
102
103
# File 'lib/utils/config/config_file.rb', line 98

def probe(&block)
  if block
    @probe = Probe.new(&block)
  end
  @probe ||= Probe.new
end

#search(&block) ⇒ Object



121
122
123
124
125
126
# File 'lib/utils/config/config_file.rb', line 121

def search(&block)
  if block
    @search = Search.new(&block)
  end
  @search ||= Search.new
end

#ssh_tunnel(&block) ⇒ Object



227
228
229
230
231
232
# File 'lib/utils/config/config_file.rb', line 227

def ssh_tunnel(&block)
  if block
    @ssh_tunnel = SshTunnel.new(&block)
  end
  @ssh_tunnel ||= SshTunnel.new
end

#strip_spaces(&block) ⇒ Object



149
150
151
152
153
154
# File 'lib/utils/config/config_file.rb', line 149

def strip_spaces(&block)
  if block
    @strip_spaces = StripSpaces.new(&block)
  end
  @strip_spaces ||= StripSpaces.new
end

#to_rubyObject



247
248
249
250
251
252
253
# File 'lib/utils/config/config_file.rb', line 247

def to_ruby
  result = "# vim: set ft=ruby:\n"
  for bc in %w[search discover strip_spaces probe ssh_tunnel]
    result << "\n" << __send__(bc).to_ruby
  end
  result
end