Class: NewrelicTag

Inherits:
Object
  • Object
show all
Defined in:
lib/newrelic_tag.rb,
lib/newrelic_tag/version.rb

Defined Under Namespace

Modules: Version

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.allowed_environmentsObject

Returns the value of attribute allowed_environments.



14
15
16
# File 'lib/newrelic_tag.rb', line 14

def allowed_environments
  @allowed_environments
end

.aws_access_key_idObject

Returns the value of attribute aws_access_key_id.



11
12
13
# File 'lib/newrelic_tag.rb', line 11

def aws_access_key_id
  @aws_access_key_id
end

.aws_secret_access_keyObject

Returns the value of attribute aws_secret_access_key.



12
13
14
# File 'lib/newrelic_tag.rb', line 12

def aws_secret_access_key
  @aws_secret_access_key
end

.instance_id_urlObject

Returns the value of attribute instance_id_url.



13
14
15
# File 'lib/newrelic_tag.rb', line 13

def instance_id_url
  @instance_id_url
end

.tagObject

Returns the value of attribute tag.



9
10
11
# File 'lib/newrelic_tag.rb', line 9

def tag
  @tag
end

.valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/newrelic_tag.rb', line 10

def value
  @value
end

Class Method Details

.computeObject



39
40
41
42
43
44
# File 'lib/newrelic_tag.rb', line 39

def compute
  @compute ||= Fog::Compute.new(
    :provider               => 'AWS',
    :aws_access_key_id      => aws_access_key_id,
    :aws_secret_access_key  => aws_secret_access_key)
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (NewrelicTag)

    the object that the method was called on



31
32
33
# File 'lib/newrelic_tag.rb', line 31

def configure      
  yield(self) if block_given?
end

.enabled?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/newrelic_tag.rb', line 35

def enabled?
  instance.enabled?
end

.instanceObject



23
24
25
# File 'lib/newrelic_tag.rb', line 23

def instance
  @instance ||= self.new
end

.reset!Object



27
28
29
# File 'lib/newrelic_tag.rb', line 27

def reset!
  @instance = nil
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
# File 'lib/newrelic_tag.rb', line 47

def enabled?
  @enabled = begin
    environment_allowed? && newrelic_allowed? && has_tag?
  rescue => e
    puts "Error reading NewRelic tag: #{e}"
    false
  end
end

#environment_allowed?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/newrelic_tag.rb', line 61

def environment_allowed?
  self.class.allowed_environments.include?(environment)
end

#has_tag?Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/newrelic_tag.rb', line 56

def has_tag?
  !self.class.compute.tags.all('key' => self.class.tag, 'value' => self.class.value, 
    'resource-id' => instance_id).empty?
end