Class: WatchmonkeyCli::Checker::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/watchmonkey_cli/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(checker, *args) ⇒ Result

Returns a new instance of Result.



65
66
67
68
69
70
71
72
# File 'lib/watchmonkey_cli/checker.rb', line 65

def initialize checker, *args
  @checker = checker
  @args = args
  @mutex = Monitor.new
  @type = :info
  @tags = []
  @spool = { error: [], info: [], debug: []}
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



62
63
64
# File 'lib/watchmonkey_cli/checker.rb', line 62

def args
  @args
end

#checkerObject (readonly)

Returns the value of attribute checker.



62
63
64
# File 'lib/watchmonkey_cli/checker.rb', line 62

def checker
  @checker
end

#commandObject

Returns the value of attribute command.



63
64
65
# File 'lib/watchmonkey_cli/checker.rb', line 63

def command
  @command
end

#dataObject

Returns the value of attribute data.



63
64
65
# File 'lib/watchmonkey_cli/checker.rb', line 63

def data
  @data
end

#resultObject

Returns the value of attribute result.



63
64
65
# File 'lib/watchmonkey_cli/checker.rb', line 63

def result
  @result
end

#tagsObject

Returns the value of attribute tags.



63
64
65
# File 'lib/watchmonkey_cli/checker.rb', line 63

def tags
  @tags
end

#typeObject (readonly)

Returns the value of attribute type.



62
63
64
# File 'lib/watchmonkey_cli/checker.rb', line 62

def type
  @type
end

Instance Method Details

#descriptorObject



85
86
87
# File 'lib/watchmonkey_cli/checker.rb', line 85

def descriptor
  "[#{@checker.class.checker_name} | #{args.join(" | ")}]"
end

#dump!Object



105
106
107
108
109
110
111
112
113
# File 'lib/watchmonkey_cli/checker.rb', line 105

def dump!
  sync do
    @spool.each do |t, messages|
      while messages.any?
        @checker.send(t, "#{str_descriptor}#{messages.shift}", self)
      end
    end
  end
end

#fatal!(msg = nil) ⇒ Object



130
131
132
133
134
135
136
# File 'lib/watchmonkey_cli/checker.rb', line 130

def fatal! msg = nil
  sync do
    @spool[:error] << msg if msg
    @type = :error
    throw(:checker, :fatal)
  end
end

#messagesObject



101
102
103
# File 'lib/watchmonkey_cli/checker.rb', line 101

def messages
  @spool.map(&:second).flatten
end

#str_descriptorObject



97
98
99
# File 'lib/watchmonkey_cli/checker.rb', line 97

def str_descriptor
  "#{descriptor}\n\t"
end

#str_runningObject



93
94
95
# File 'lib/watchmonkey_cli/checker.rb', line 93

def str_running
  "Running checker #{@checker.class.checker_name} with [#{args.join(" | ")}]"
end

#str_safeObject



89
90
91
# File 'lib/watchmonkey_cli/checker.rb', line 89

def str_safe
  "#{descriptor}\n\t"
end

#sync(&block) ⇒ Object



81
82
83
# File 'lib/watchmonkey_cli/checker.rb', line 81

def sync &block
  @mutex.synchronize(&block)
end

#uniqid(additional = []) ⇒ Object



74
75
76
77
78
79
# File 'lib/watchmonkey_cli/checker.rb', line 74

def uniqid additional = []
  ([
    self.class.name,
    @args.map(&:to_s).to_s,
  ] + additional).join("/")
end