Class: Traquitana::Config
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #default ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load(file = nil) ⇒ Object
- #method_missing(meth) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 |
# File 'lib/config.rb', line 8 def initialize @configs = {} @filename = 'config/traq.yml' @target = nil load end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
25 26 27 |
# File 'lib/config.rb', line 25 def method_missing(meth) @configs[meth.to_s] || '' end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/config.rb', line 6 def filename @filename end |
#target ⇒ Object
Returns the value of attribute target.
6 7 8 |
# File 'lib/config.rb', line 6 def target @target end |
Instance Method Details
#default ⇒ Object
15 16 17 |
# File 'lib/config.rb', line 15 def default "#{File.dirname(File.(__FILE__))}/../config/default.yml" end |
#load(file = nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/config.rb', line 19 def load(file = nil) check_configs(file) check_target check_default_target end |
#setup ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/config.rb', line 29 def setup STDOUT.puts 'Running setup' if File.exist?(self.filename) STDERR.puts "The configuration file #{self.filename} already exists." return false end dir = File.dirname(filename) Dir.mkdir(dir) if !File.exist?(dir) STDOUT.puts "Writing #{filename}" File.open(filename, "w") do |file| file << File.read(self.default) end STDOUT.puts "Setup completed!" STDOUT.puts "You MUST check the configurations on #{self.filename} before deploying!" true end |