jmx4r 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require "rubygems"
6
6
 
7
7
  dir = File.dirname(__FILE__)
8
8
  lib = File.join(dir, "lib", "jmx4r.rb")
9
- version = "0.1.2"
9
+ version = "0.1.3"
10
10
 
11
11
  task :default => [:test]
12
12
 
data/lib/jmx4r.rb CHANGED
@@ -12,6 +12,14 @@ class String
12
12
  tr("-", "_").
13
13
  downcase
14
14
  end
15
+
16
+ # Transform a snake_case String to a camelCase String with a lowercase initial.
17
+ #--
18
+ # Code has been taken from ActiveSupport
19
+ def camel_case
20
+ name = gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
21
+ name[0].chr.downcase + name[1..-1]
22
+ end
15
23
  end
16
24
 
17
25
  module JMX
@@ -4,7 +4,7 @@
4
4
  # regular (read-only) Ruby Hash
5
5
  require 'java'
6
6
 
7
- JavaUtilities.extend_proxy('javax.management.openmbean.CompositeDataSupport') do
7
+ JavaUtilities.extend_proxy('javax.management.openmbean.CompositeData') do
8
8
  include Enumerable
9
9
  def each
10
10
  self.get_composite_type.key_set.each do |k|
@@ -27,9 +27,19 @@ JavaUtilities.extend_proxy('javax.management.openmbean.CompositeDataSupport') do
27
27
  def [](key)
28
28
  self.get key
29
29
  end
30
+
31
+ def method_missing(name, *args)
32
+ key = name.to_s.camel_case
33
+ super unless containsKey(key)
34
+ get(name.to_s.camel_case)
35
+ end
36
+
37
+ def respond_to?(symbol, include_private = false)
38
+ containsKey(symbol.to_s.camel_case) || super
39
+ end
30
40
  end
31
41
 
32
- JavaUtilities.extend_proxy('javax.management.openmbean.TabularDataSupport') do
42
+ JavaUtilities.extend_proxy('javax.management.openmbean.TabularData') do
33
43
  include Enumerable
34
44
  def each
35
45
  self.values.each do |value|
@@ -39,6 +39,25 @@ class TestCompositeData < Test::Unit::TestCase
39
39
  assert @heap.member?("used")
40
40
  end
41
41
 
42
+ def test_composite_data_method_missing
43
+ assert @heap.used
44
+
45
+ def @heap.containsKey(key)
46
+ "camelCaseAttributeName" == key
47
+ end
48
+
49
+ def @heap.get(key)
50
+ return "value" if "camelCaseAttributeName" == key
51
+ raise("should not happen")
52
+ end
53
+
54
+ assert_equal "value", @heap.camel_case_attribute_name
55
+
56
+ assert_raises NoMethodError do
57
+ @heap.unknown_attribute
58
+ end
59
+ end
60
+
42
61
  def test_composite_data_as_hash
43
62
  used = @heap.get "used"
44
63
  used_from_hash = @heap["used"]
metadata CHANGED
@@ -77,7 +77,7 @@ requirements: []
77
77
 
78
78
  authors:
79
79
  - Jeff Mesnil
80
- date: 2010-07-28 22:00:00 +00:00
80
+ date: 2010-11-18 23:00:00 +00:00
81
81
  platform: ruby
82
82
  test_files:
83
83
  - test/ts_all.rb
@@ -85,9 +85,9 @@ version: !ruby/object:Gem::Version
85
85
  segments:
86
86
  - 0
87
87
  - 1
88
- - 2
88
+ - 3
89
89
  prerelease: false
90
- version: 0.1.2
90
+ version: 0.1.3
91
91
  require_paths:
92
92
  - lib
93
93
  dependencies: []