Class: EMaily::Servers
- Inherits:
-
Object
- Object
- EMaily::Servers
- Defined in:
- lib/emaily/servers.rb
Constant Summary collapse
- SERVERS_PATH =
ENV["HOME"] + "/.emaily_servers"
Class Method Summary collapse
Instance Method Summary collapse
- #[](arg) ⇒ Object
- #create(name, values = {}) ⇒ Object
- #delete(arg) ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ Servers
constructor
A new instance of Servers.
- #select_server(arg) ⇒ Object
Constructor Details
#initialize ⇒ Servers
Returns a new instance of Servers.
15 16 17 |
# File 'lib/emaily/servers.rb', line 15 def initialize File.exist?(SERVERS_PATH) ? @servers = YAML.load_file(SERVERS_PATH) : @servers = [] end |
Class Method Details
.load ⇒ Object
35 36 37 |
# File 'lib/emaily/servers.rb', line 35 def self.load self.new end |
Instance Method Details
#[](arg) ⇒ Object
31 32 33 |
# File 'lib/emaily/servers.rb', line 31 def [](arg) select_server(arg) end |
#create(name, values = {}) ⇒ Object
19 20 21 |
# File 'lib/emaily/servers.rb', line 19 def create(name, values = {}) @servers << {:name => name, :values => values } end |
#delete(arg) ⇒ Object
23 24 25 |
# File 'lib/emaily/servers.rb', line 23 def delete(arg) @servers.delete_if {|x| x[:name] == arg } end |
#flush ⇒ Object
39 40 41 |
# File 'lib/emaily/servers.rb', line 39 def flush File.open(SERVERS_PATH, 'w') { |f| f.puts(YAML::dump(@servers)) } end |
#select_server(arg) ⇒ Object
27 28 29 |
# File 'lib/emaily/servers.rb', line 27 def select_server(arg) @servers.select {|x| x[:name] == arg} end |