Class: Conf
- Inherits:
-
Object
- Object
- Conf
- Includes:
- Singleton
- Defined in:
- lib/magicmonkey/configuration.rb
Constant Summary collapse
- VHT =
<<EOT <VirtualHost *:80> ServerName $SERVER_NAME ProxyPass / http://127.0.0.1:$PORT/ ProxyPassReverse / http://127.0.0.1:$PORT/ </VirtualHost> EOT
- DEFAULT =
{ :app_server => nil, :app_server_options => nil, :port => nil, :ruby => 'default', :app_path => '/var/sites/$APP_NAME/current', :server_name => '$APP_NAME.local', :vhost_template => VHT, :vhost_path => '/etc/apache2/sites-available', :overwrite_files => false, :create_vhost => true, :enable_site => false, :reload_apache => false }
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
- .applications ⇒ Object
- .delete(key) ⇒ Object
- .next_port(range = (3000..5000)) ⇒ Object
- .ports ⇒ Object
- .save ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Conf
constructor
A new instance of Conf.
- #load ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize ⇒ Conf
Returns a new instance of Conf.
31 32 33 |
# File 'lib/magicmonkey/configuration.rb', line 31 def initialize load end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/magicmonkey/configuration.rb', line 6 def config @config end |
Class Method Details
.[](key) ⇒ Object
50 51 52 |
# File 'lib/magicmonkey/configuration.rb', line 50 def self.[](key) Conf.instance.config[key.to_sym] end |
.[]=(key, value) ⇒ Object
54 55 56 |
# File 'lib/magicmonkey/configuration.rb', line 54 def self.[]=(key, value) Conf.instance.config[key.to_sym] = value end |
.applications ⇒ Object
66 67 68 |
# File 'lib/magicmonkey/configuration.rb', line 66 def self.applications Conf.instance.config.keys.select{|k| ![:default, :uid].include?(k)} end |
.delete(key) ⇒ Object
58 59 60 |
# File 'lib/magicmonkey/configuration.rb', line 58 def self.delete(key) Conf.instance.config.delete(key.to_sym) if key.to_sym != :default end |
.next_port(range = (3000..5000)) ⇒ Object
78 79 80 |
# File 'lib/magicmonkey/configuration.rb', line 78 def self.next_port(range = (3000..5000)) return (range.to_a - self.ports).first end |
.ports ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/magicmonkey/configuration.rb', line 70 def self.ports p = [] Conf.instance.config.each do |k,v| p << v[:port] if ![:default, :uid].include?(k) && v[:port] end return p end |
.save ⇒ Object
62 63 64 |
# File 'lib/magicmonkey/configuration.rb', line 62 def self.save Conf.instance.save end |
Instance Method Details
#load ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/magicmonkey/configuration.rb', line 35 def load @file = "#{Dir.home}/.magicmonkey.yml" if File.exist?(@file) @config = YAML.load_file(@file) else @config = {:default => DEFAULT} self.save end end |
#save ⇒ Object
45 46 47 48 |
# File 'lib/magicmonkey/configuration.rb', line 45 def save File.open(@file, 'w') { |f| f.write(@config.to_yaml) } self.load end |