collectd-dsl 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in collectd-dsl.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Pierre-Yves Ritschard <pyr@spootnik.org>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Collectd::DSL
2
+
3
+ Write Collectd configurations in Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'collectd-dsl'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install collectd-dsl
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ config = Collectd::DSL.parse do
23
+ LoadPlugin :redis
24
+ LoadPlugin :java
25
+ LoadPlugin :disk
26
+
27
+ Plugin :disk do
28
+ Disk "/dev/sda"
29
+ Disk "/dev/sdb"
30
+ IgnoreSelected "false"
31
+ end
32
+ end
33
+
34
+ ```
35
+
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'collectd-dsl'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "collectd-dsl"
8
+ gem.version = Collectd::DSL::VERSION
9
+ gem.authors = ["Pierre-Yves Ritschard"]
10
+ gem.email = ["pyr@spootnik.org"]
11
+ gem.description = %q{Produce Valid Collectd configurations from ruby}
12
+ gem.summary = %q{collectd configuration dsl}
13
+ gem.homepage = "https://github.com/pyr/collectd-dsl"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_development_dependency "rspec", ">= 2.0.0"
20
+ end
@@ -0,0 +1,38 @@
1
+ module Collectd
2
+ class DSL
3
+ VERSION = "0.3.0"
4
+
5
+ def initialize(&block)
6
+ @directives = []
7
+ @indent = 0
8
+ instance_eval(&block) if block_given?
9
+ end
10
+
11
+ def dump
12
+ @directives.join("\n") + "\n"
13
+ end
14
+
15
+ def self.parse(&block)
16
+ DSL.new(&block).dump if block_given?
17
+ end
18
+
19
+ def indent str
20
+ ("\t" * @indent) + str
21
+ end
22
+
23
+ def method_missing method_name, *args
24
+ mapped_args = args.map{|a| a.to_s}.join(" ")
25
+ mapped_args = (" " + mapped_args) unless mapped_args.empty?
26
+
27
+ if block_given?
28
+ @directives << indent("<#{method_name.to_s}#{mapped_args}>")
29
+ @indent += 1
30
+ yield # rely on the outer scope
31
+ @indent -= 1
32
+ @directives << indent("</#{method_name.to_s}>")
33
+ else
34
+ @directives << indent("#{method_name.to_s}#{mapped_args}")
35
+ end
36
+ end
37
+ end
38
+ end
data/spec/dsl_spec.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Collectd::DSL do
4
+ context "simple options" do
5
+ it "no args given" do
6
+ config = Collectd::DSL.parse do
7
+ LoadPlugin :disk
8
+ end
9
+ config.should == "LoadPlugin disk\n"
10
+ end
11
+ it "one arg given" do
12
+ config = Collectd::DSL.parse do
13
+ LoadPlugin :disk, '/dev/sda'
14
+ end
15
+ config.should == "LoadPlugin disk /dev/sda\n"
16
+ end
17
+ it "section" do
18
+ config = Collectd::DSL.parse do
19
+ Plugin :disk do
20
+ Disk '/dev/sda'
21
+ end
22
+ end
23
+ config.should == "<Plugin disk>\n\tDisk /dev/sda\n</Plugin>\n"
24
+ end
25
+ it "section with no args" do
26
+ config = Collectd::DSL.parse do
27
+ Plugin do
28
+ Disk '/dev/sda'
29
+ end
30
+ end
31
+ config.should == "<Plugin>\n\tDisk /dev/sda\n</Plugin>\n"
32
+ end
33
+ it "empty section" do
34
+ config = Collectd::DSL.parse do
35
+ Plugin do
36
+ end
37
+ end
38
+ config.should == "<Plugin>\n</Plugin>\n"
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'collectd-dsl' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: collectd-dsl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
+ platform: ruby
12
+ authors:
13
+ - Pierre-Yves Ritschard
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-10-11 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 0
33
+ version: 2.0.0
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: Produce Valid Collectd configurations from ruby
37
+ email:
38
+ - pyr@spootnik.org
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - LICENSE.txt
49
+ - README.md
50
+ - Rakefile
51
+ - collectd-dsl.gemspec
52
+ - lib/collectd-dsl.rb
53
+ - spec/dsl_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage: https://github.com/pyr/collectd-dsl
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.24
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: collectd configuration dsl
88
+ test_files:
89
+ - spec/dsl_spec.rb
90
+ - spec/spec_helper.rb