Class: RbRotate::Configuration
Overview
General configuration file.
Constant Summary collapse
- @@self =
Brings self instance. (Class is singletone.)
nil
Class Method Summary collapse
-
.each_directory(&block) ⇒ Object
Traverses through each directory configuration.
-
.find_path(path) ⇒ Object
Alias for #find_path.
-
.get ⇒ Object
Returns the single instance.
-
.read(file) ⇒ Object
Opens the file.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns an item.
-
#each_directory ⇒ Object
Traverses through each directory configuration.
-
#find_path(path) ⇒ Object
Looks for directory in configuration.
-
#method_missing(name) ⇒ Object
Handles method calls.
-
#read(file) ⇒ Object
Opens the file.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
Handles method calls.
198 199 200 |
# File 'lib/rb.rotate/configuration.rb', line 198 def method_missing(name) self[name] end |
Class Method Details
.each_directory(&block) ⇒ Object
Traverses through each directory configuration. (Shortcut for instace call.)
136 137 138 |
# File 'lib/rb.rotate/configuration.rb', line 136 def self.each_directory(&block) self::get.each_directory(&block) end |
.find_path(path) ⇒ Object
Alias for #find_path.
144 145 146 |
# File 'lib/rb.rotate/configuration.rb', line 144 def self.find_path(path) self::get.find_path(path) end |
.get ⇒ Object
Returns the single instance.
124 125 126 127 128 129 130 |
# File 'lib/rb.rotate/configuration.rb', line 124 def self.get if @@self.nil? @@self = self::new end return @@self end |
.read(file) ⇒ Object
Opens the file. (Shortcut for instance call.)
116 117 118 |
# File 'lib/rb.rotate/configuration.rb', line 116 def self.read(file) self::get.read(file) end |
Instance Method Details
#[](name) ⇒ Object
Returns an item.
190 191 192 |
# File 'lib/rb.rotate/configuration.rb', line 190 def [](name) @data[name] end |
#each_directory ⇒ Object
Traverses through each directory configuration.
206 207 208 209 210 |
# File 'lib/rb.rotate/configuration.rb', line 206 def each_directory @data[:dirs].each_pair do |name, dir| yield Directory::new(name, dir) end end |
#find_path(path) ⇒ Object
Looks for directory in configuration.
216 217 218 219 220 221 222 223 224 |
# File 'lib/rb.rotate/configuration.rb', line 216 def find_path(path) @data.each_pair do |name, dir| if dir[:directory] == path return Directory::new(name, dir) end end return nil end |
#read(file) ⇒ Object
Opens the file.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/rb.rotate/configuration.rb', line 152 def read(file) data = YAML.load(::File.read(file)) @data = { } # Converts strings to symbols data.each_pair do |name, section| section_data = { } @data[name.to_sym]= section_data if section.kind_of? Hash section.each_pair do |key, value| section_data[key.to_sym] = value end end end defaults = YAML.load(::File.read(@data[:paths][:"defaults file"])) # Merges with defaults defaults.each_pair do |name, section| name = name.to_sym if not @data.has_key? name @data[name] = value elsif section.kind_of? Hash section.each_pair do |key, value| key = key.to_sym if not @data[name].has_key? key @data[name][key] = value end end end end end |