Class: Mackerel::Role

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Role

Returns a new instance of Role.



6
7
8
9
# File 'lib/mackerel/role.rb', line 6

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

Instance Attribute Details

#memoObject

Returns the value of attribute memo.



4
5
6
# File 'lib/mackerel/role.rb', line 4

def memo
  @memo
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/mackerel/role.rb', line 4

def name
  @name
end

Instance Method Details

#to_hObject



11
12
13
14
15
16
17
# File 'lib/mackerel/role.rb', line 11

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



19
20
21
# File 'lib/mackerel/role.rb', line 19

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