Class: Mackerel::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/mackerel/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Service

Returns a new instance of Service.



7
8
9
10
11
# File 'lib/mackerel/service.rb', line 7

def initialize(args = {})
  @name                            = args["name"]
  @memo                            = args["memo"]
  @roles                           = args["roles"]
end

Instance Attribute Details

#memoObject

Returns the value of attribute memo.



5
6
7
# File 'lib/mackerel/service.rb', line 5

def memo
  @memo
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/mackerel/service.rb', line 5

def name
  @name
end

#rolesObject

Returns the value of attribute roles.



5
6
7
# File 'lib/mackerel/service.rb', line 5

def roles
  @roles
end

Instance Method Details

#to_hObject



13
14
15
16
17
18
19
# File 'lib/mackerel/service.rb', line 13

def to_h
  instance_variables.flat_map do |name|
    respond_to?(name[1..-1]) ? [name[1..-1]] : []
  end.each_with_object({}) do |name, hash|
    hash[name] = public_send(name)
  end.delete_if { |key, val| val == nil }
end

#to_json(options = nil) ⇒ Object



21
22
23
# File 'lib/mackerel/service.rb', line 21

def to_json(options = nil)
  return to_h.to_json(options)
end