Class: AWS::CloudWatch::MetricBase
- Inherits:
-
Object
- Object
- AWS::CloudWatch::MetricBase
show all
- Includes:
- Core::Model
- Defined in:
- lib/aws/cloud_watch/metric_base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ MetricBase
Returns a new instance of MetricBase.
24
25
26
27
28
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 24
def initialize options
super
@dimensions = {}
set_attributes options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 61
def method_missing name, *args
if args.length == 1 && name.to_s =~ /^(.*)=/ then
@dimensions[$1.to_sym] = args[0]
else
super
end
end
|
Instance Attribute Details
#dimensions ⇒ Object
Returns the value of attribute dimensions.
43
44
45
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 43
def dimensions
@dimensions
end
|
#name ⇒ Object
Returns the value of attribute name.
42
43
44
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 42
def name
@name
end
|
#namespace ⇒ Object
Returns the value of attribute namespace.
42
43
44
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 42
def namespace
@namespace
end
|
Instance Method Details
#attr_names ⇒ Object
57
58
59
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 57
def attr_names
[:dimensions, :name, :namespace]
end
|
#camel_case(s) ⇒ Object
81
82
83
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 81
def camel_case s
Core::Inflection.class_name s.to_s
end
|
#inspect ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 89
def inspect
attrs = []
attr_names.each do |attr|
val = self.send attr
attrs << "#{attr}:#{val.inspect}" if val
end
"<#{self::class} #{attrs.join ' '}>"
end
|
#options ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 69
def options
opts = !dimensions.empty? ? {:dimensions =>
dimensions.keys.map {|key|
{ :name => camel_case(key),
:value => dimensions[key] }}
} : {}
opts[:metric_name] = name if name
opts[:namespace] = namespace if namespace
opts
end
|
#set_attributes(attrs) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 30
def set_attributes attrs
attrs.keys.each do |k|
key = k
key = :name if key == :metric_name
if key.kind_of? Symbol
send("#{key}=", attrs[k]) unless key == :config
else
dimensions[key] = attrs[k]
end
end
end
|
#to_sym(s) ⇒ Object
85
86
87
|
# File 'lib/aws/cloud_watch/metric_base.rb', line 85
def to_sym s
Core::Inflection.ruby_name(s.to_s).to_sym
end
|