Created
November 4, 2012 04:57
-
-
Save jinzhu/4010380 to your computer and use it in GitHub Desktop.
Qor DSL examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'qor_dsl' | |
module Gemfile | |
class Configuration | |
include Qor::Dsl | |
default_configs [ENV['BUNDLE_GEMFILE'], 'Gemfile'] | |
node :gem | |
[:git, :path, :group].map do |name| | |
node name do | |
node :gem | |
end | |
end | |
end | |
end | |
Gemfile::Configuration.load do | |
gem "rails", :git => "git://github.com/rails/rails.git" | |
gem 'capistrano-confirm', '>= 0.0.6' | |
gem 'paygent', :path => '~/Develop/paygent' | |
path "~/Develop/qor_dsl" do | |
gem "qor_dsl" | |
end | |
git "git://github.com/rails/rails.git" do | |
gem "activesupport" | |
gem "actionpack" | |
end | |
group :development do | |
gem 'pry-rails' | |
end | |
group :test do | |
gem "timecop" | |
end | |
end | |
puts Gemfile::Configuration.first('gem', 'rails').name #=> rails | |
puts Gemfile::Configuration.first('gem', 'rails').options #=> {:git=>"git://github.com/rails/rails.git"} | |
development_gems = Gemfile::Configuration.deep_find('gem') do |n| | |
parent = n.parent | |
parent.root? || !parent.is_node?(:group) || parent.is_node?(:group, :development) | |
end | |
puts development_gems.map(&:name).inspect | |
#=> ["rails", "capistrano-confirm", "paygent", "qor_dsl", "activesupport", "actionpack", "pry-rails"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'qor_dsl' | |
module Nagios | |
class Configuration | |
include Qor::Dsl | |
node :contact_emails | |
node :mail do | |
node :address | |
end | |
node :server do | |
node :contact_emails, inherit: true | |
node :host | |
node :port, default_value: 22 | |
node :username, default_value: 'app' | |
node :check_disk, default_options: {warning: '10%', critical: '8%'} | |
node :check_load, default_options: {warning: '8,5,5', critical: '20,15,10'} | |
node :check_memcached, default_options: {port: 11211, host: '127.0.0.1'} | |
node :check_mysql_slave | |
end | |
end | |
end | |
Nagios::Configuration.load do | |
contact_emails ["[email protected]"] | |
mail do | |
address 'smtp.example.com' | |
end | |
server 'server1' do | |
host '100.200.200.10' | |
username 'app' | |
check_disk :warning => '10%', :critical => '8%' | |
check_load :warning => '8,5,5', :critical => '20,15,10' | |
check_memcached :port => 11211, :host => '10.0.0.1' | |
check_mysql_slave :user => 'nagios_check', :password => 'xxxxxx' | |
end | |
server 'server2' do | |
contact_emails ["[email protected]"] | |
host '111.111.111.11' | |
username 'app' | |
check_disk :warning => '10%', :critical => '8%' | |
check_load :warning => '8,5,5', :critical => '20,15,10' | |
port 222 | |
end | |
end | |
# 继承父级 | |
Nagios::Configuration.first('server', 'server1').first(:contact_emails).value | |
#=> "[email protected]" | |
# 重写继承 | |
Nagios::Configuration.first('server', 'server2').first(:contact_emails).value | |
#=> [email protected] | |
# 默认 | |
Nagios::Configuration.first('server', 'server1').first(:check_load).options | |
Nagios::Configuration.first('server', 'server1').first(:check_load).value | |
#=> {:warning=>"8,5,5", :critical=>"20,15,10"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment