Module: RoSupport::Debug

Defined in:
lib/ro_support/debug.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

ro is my name, ro_raise mean my raise



4
5
6
7
# File 'lib/ro_support/debug.rb', line 4

def self.included(base)
  base.send(:alias_method, :ro_raise, :eval)
  base.send(:alias_method, :ro_return, :eval)
end

Instance Method Details

#err(msg = 'error', opt = {output: []}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ro_support/debug.rb', line 9

def err(msg='error', opt={output: []})
  err = [""]
  err << msg
  err << "Instance Variables:"
  instance_variables.each do |ivar|
    err << "    #{ivar.to_s}: #{instance_variable_get(ivar)}"
  end

  print err.join("\n")

  "  err = [\"\"]\n\n  err << \"\"\n  err << \"Output Variables:\"\n  err << \"\"\n\#{opt[:output]}.each do |var|\n    if var.is_a?(String)\n      err << \"  \\\#{var}:\\\#{eval var}\"\n    end\n  end\n\n  raise err.join(\"\\n\") + \"\\n\\n\"\n  ERROR\nend\n"

#valid(smth, opt = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ro_support/debug.rb', line 35

def valid(smth, opt={})
  if opt[:valid?].nil?
    if smth.is_a?(Array) or smth.is_a?(Hash)
      is_valid = !smth.empty?
    else
      is_valid = !smth.nil?
    end

    if is_valid
      return smth
    else
      if opt[:output]
        err('return nil or empty', output: opt[:output])
      else
        err('return nil or empty')
      end
    end
  end
end