collectd-dsl 0.3.0 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-19mode
6
+ - 1.8.7
7
+ script: "rake spec"
data/README.md CHANGED
@@ -18,21 +18,36 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ Note that the collectd-dsl converts snake-case to CamelCase
22
+
21
23
  ```ruby
22
24
  config = Collectd::DSL.parse do
23
- LoadPlugin :redis
24
- LoadPlugin :java
25
- LoadPlugin :disk
25
+ load_plugin :redis
26
+ load_plugin :java
27
+ load_plugin :disk
26
28
 
27
- Plugin :disk do
28
- Disk "/dev/sda"
29
- Disk "/dev/sdb"
30
- IgnoreSelected "false"
29
+ plugin :disk do
30
+ disk "/dev/sda"
31
+ disk "/dev/sdb"
32
+ ignore_selected "false"
31
33
  end
32
34
  end
33
35
 
34
36
  ```
35
37
 
38
+ The following will be output
39
+ ```
40
+ LoadPlugin redis
41
+ LoadPlugin java
42
+ LoadPlugin disk
43
+ <Plugin disk>
44
+ Disk "/dev/sda"
45
+ Disk "/dev/sdb"
46
+ IgnoreSelected "false"
47
+ </Plugin>
48
+
49
+ ```
50
+
36
51
 
37
52
  ## Contributing
38
53
 
data/collectd-dsl.gemspec CHANGED
@@ -16,5 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+ gem.add_development_dependency "rake"
19
20
  gem.add_development_dependency "rspec", ">= 2.0.0"
20
21
  end
data/lib/collectd-dsl.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Collectd
2
2
  class DSL
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.5"
4
4
 
5
5
  def initialize(&block)
6
6
  @directives = []
@@ -20,18 +20,30 @@ module Collectd
20
20
  ("\t" * @indent) + str
21
21
  end
22
22
 
23
+ def snake_to_camel method_name
24
+ method_name.split("_").map{|w| w.capitalize }.join("")
25
+ end
26
+
23
27
  def method_missing method_name, *args
24
- mapped_args = args.map{|a| a.to_s}.join(" ")
28
+ mapped_args = args.map do |a|
29
+ if a.class == String
30
+ "\"" + a.to_s + "\""
31
+ else
32
+ a.to_s
33
+ end
34
+ end.join(" ")
35
+
25
36
  mapped_args = (" " + mapped_args) unless mapped_args.empty?
26
37
 
38
+ camel_method_name = snake_to_camel method_name.to_s
27
39
  if block_given?
28
- @directives << indent("<#{method_name.to_s}#{mapped_args}>")
40
+ @directives << indent("<#{camel_method_name}#{mapped_args}>")
29
41
  @indent += 1
30
42
  yield # rely on the outer scope
31
43
  @indent -= 1
32
- @directives << indent("</#{method_name.to_s}>")
44
+ @directives << indent("</#{camel_method_name}>")
33
45
  else
34
- @directives << indent("#{method_name.to_s}#{mapped_args}")
46
+ @directives << indent("#{camel_method_name}#{mapped_args}")
35
47
  end
36
48
  end
37
49
  end
data/spec/dsl_spec.rb CHANGED
@@ -4,35 +4,35 @@ describe Collectd::DSL do
4
4
  context "simple options" do
5
5
  it "no args given" do
6
6
  config = Collectd::DSL.parse do
7
- LoadPlugin :disk
7
+ load_plugin :disk
8
8
  end
9
9
  config.should == "LoadPlugin disk\n"
10
10
  end
11
11
  it "one arg given" do
12
12
  config = Collectd::DSL.parse do
13
- LoadPlugin :disk, '/dev/sda'
13
+ load_plugin :disk, '/dev/sda'
14
14
  end
15
- config.should == "LoadPlugin disk /dev/sda\n"
15
+ config.should == "LoadPlugin disk \"/dev/sda\"\n"
16
16
  end
17
17
  it "section" do
18
18
  config = Collectd::DSL.parse do
19
- Plugin :disk do
20
- Disk '/dev/sda'
19
+ plugin :disk do
20
+ disk '/dev/sda'
21
21
  end
22
22
  end
23
- config.should == "<Plugin disk>\n\tDisk /dev/sda\n</Plugin>\n"
23
+ config.should == "<Plugin disk>\n\tDisk \"/dev/sda\"\n</Plugin>\n"
24
24
  end
25
25
  it "section with no args" do
26
26
  config = Collectd::DSL.parse do
27
- Plugin do
28
- Disk '/dev/sda'
27
+ plugin do
28
+ disk '/dev/sda'
29
29
  end
30
30
  end
31
- config.should == "<Plugin>\n\tDisk /dev/sda\n</Plugin>\n"
31
+ config.should == "<Plugin>\n\tDisk \"/dev/sda\"\n</Plugin>\n"
32
32
  end
33
33
  it "empty section" do
34
34
  config = Collectd::DSL.parse do
35
- Plugin do
35
+ plugin do
36
36
  end
37
37
  end
38
38
  config.should == "<Plugin>\n</Plugin>\n"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collectd-dsl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pierre-Yves Ritschard
@@ -15,12 +15,26 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-11 00:00:00 Z
18
+ date: 2012-10-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
21
+ name: rake
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
24
38
  none: false
25
39
  requirements:
26
40
  - - ">="
@@ -32,7 +46,7 @@ dependencies:
32
46
  - 0
33
47
  version: 2.0.0
34
48
  type: :development
35
- version_requirements: *id001
49
+ version_requirements: *id002
36
50
  description: Produce Valid Collectd configurations from ruby
37
51
  email:
38
52
  - pyr@spootnik.org
@@ -44,6 +58,7 @@ extra_rdoc_files: []
44
58
 
45
59
  files:
46
60
  - .gitignore
61
+ - .travis.yml
47
62
  - Gemfile
48
63
  - LICENSE.txt
49
64
  - README.md