Class: Conf
- Inherits:
-
Object
- Object
- Conf
- Includes:
- Singleton
- Defined in:
- lib/magicmonkey/configuration.rb
Constant Summary collapse
- DEFAULT =
{ :app_server => nil, :app_server_options => nil, :ruby => 'default', :app_path => '/var/sites/$APP/current', :bundle_exec => true, :enabled => true, :editor => 'nano', }
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
18 19 20 |
# File 'lib/magicmonkey/configuration.rb', line 18 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
37 38 39 |
# File 'lib/magicmonkey/configuration.rb', line 37 def self.[](key) Conf.instance.config[key.to_sym] end |
.[]=(key, value) ⇒ Object
41 42 43 |
# File 'lib/magicmonkey/configuration.rb', line 41 def self.[]=(key, value) Conf.instance.config[key.to_sym] = value end |
.applications ⇒ Object
53 54 55 |
# File 'lib/magicmonkey/configuration.rb', line 53 def self.applications apps = Conf.instance.config.keys.select{|k| ![:default, :uid].include?(k)} end |
.delete(key) ⇒ Object
45 46 47 |
# File 'lib/magicmonkey/configuration.rb', line 45 def self.delete(key) Conf.instance.config.delete(key.to_sym) if key.to_sym != :default end |
.next_port(range = (3000..5000)) ⇒ Object
65 66 67 |
# File 'lib/magicmonkey/configuration.rb', line 65 def self.next_port(range = (3000..5000)) return (range.to_a - self.ports).first end |
.ports ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/magicmonkey/configuration.rb', line 57 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
49 50 51 |
# File 'lib/magicmonkey/configuration.rb', line 49 def self.save Conf.instance.save end |
Instance Method Details
#load ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/magicmonkey/configuration.rb', line 22 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
32 33 34 35 |
# File 'lib/magicmonkey/configuration.rb', line 32 def save File.open(@file, 'w') { |f| f.write(@config.to_yaml) } self.load end |