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, FileFinder, Probe, Search, 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



131
132
133
134
135
136
# File 'lib/utils/config/config_file.rb', line 131

def discover(&block)
  if block
    @discover = Discover.new(&block)
  end
  @discover ||= Discover.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



93
94
95
96
97
98
# File 'lib/utils/config/config_file.rb', line 93

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

#search(&block) ⇒ Object



116
117
118
119
120
121
# File 'lib/utils/config/config_file.rb', line 116

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

#strip_spaces(&block) ⇒ Object



144
145
146
147
148
149
# File 'lib/utils/config/config_file.rb', line 144

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

#to_rubyObject



151
152
153
154
155
156
157
# File 'lib/utils/config/config_file.rb', line 151

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