Skip to content

Instantly share code, notes, and snippets.

@madwork
Created October 31, 2012 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madwork/3988043 to your computer and use it in GitHub Desktop.
Save madwork/3988043 to your computer and use it in GitHub Desktop.
Manager
class Manager
def self.configure(&block)
::Template.new(&block)
end
end
class Template
attr_reader :assets, :events
def initialize(&block)
@assets = {}
@events = {}
instance_eval(&block)
end
def asset(value, properties = {})
@assets[value] ||= []
@assets[value] << properties
end
def event(name, &block)
@events[name] = block
end
def send(action, options = {})
puts "send #{action} #{options}"
end
def update(asset, name)
@assets[asset].select{|asset| asset[:name] == name}.pop[:reboot] ||= 0
@assets[asset].select{|asset| asset[:name] == name}.pop[:reboot] += 1
end
end
t = Manager.configure do
asset :serveur,
:name => 'DBX-001',
:ip => '10.0.10.1'
asset :serveur,
:name => 'DBX-002',
:ip => '10.0.10.2'
event :down do
send :mail, :to => 'vincent@yoolink.fr'
send :notificaion, :to => 'vincent@yoolink.fr'
end
event :restart do
update :serveur, 'DBX-002'
end
end
puts t.assets
puts t.events
t.events[:down].call
t.events[:restart].call
t.events[:restart].call
puts t.assets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment