Module: TellMeAboutIt

Included in:
Object
Defined in:
lib/tell_me_about_it.rb,
lib/tell_me_about_it/version.rb

Constant Summary collapse

COLORS =
{ :count => '00a0b0',
:file => '444',
:context => '999',
:self => '793A57',
:method => 'fff',
:args => 'EB6841',
:result => '2DE04D',
:result_yaml => '105023',
:time_good => 'EDC951',
:time_bad => 'CC333F' }
VERSION =
"0.0.4"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cont_indent_strObject



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

def self.cont_indent_str
  "#{indent_str}"
end

.context_str(method_caller) ⇒ Object



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

def self.context_str method_caller
  file_name, line_number, context = method_caller[0].split(':', 3)
  begin
    actual_line = File.readlines(file_name)[line_number.to_i - 1].strip
  rescue Exception => e
    actual_line = "Unable to open #{file_name}:#{line_number}"
  end
  "#{context} ... #{actual_line}".color(COLORS[:context])
end

.countObject



40
41
42
# File 'lib/tell_me_about_it.rb', line 40

def self.count
  $_tma_count ||= 0
end

.count_strObject



52
53
54
# File 'lib/tell_me_about_it.rb', line 52

def self.count_str
  " ##{count.to_s} ".color(COLORS[:count]).bold
end

.end_indent_strObject



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

def self.end_indent_str
  "#{indent_str} └─"
end

.file_str(method_caller) ⇒ Object



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

def self.file_str method_caller
  file_name, line_number = method_caller[0].split(':', 3)
  "#{file_name}:#{line_number}".color(COLORS[:file])
end

.incObject



24
25
26
# File 'lib/tell_me_about_it.rb', line 24

def self.inc
  $_tma_count += 1
end

.indentObject



28
29
30
# File 'lib/tell_me_about_it.rb', line 28

def self.indent
  $_tma_indent += 1
end

.indent_changed?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/tell_me_about_it.rb', line 48

def self.indent_changed?
  $_tma_indent < $_tma_last_indent
end

.indent_levelObject



44
45
46
# File 'lib/tell_me_about_it.rb', line 44

def self.indent_level
  $_tma_indent ||= 0
end

.indent_strObject



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

def self.indent_str
  indent_level.times.inject('') {|m| m += ""}
end

.method_str(method_name, *args) ⇒ Object



75
76
77
78
79
# File 'lib/tell_me_about_it.rb', line 75

def self.method_str method_name, *args
  name_str = "#{method_name}".bold
  args_str = "(#{args.map {|a| a.inspect.size > 150 ? a.to_s : a.inspect}.map {|a| a.color(COLORS[:args])}.join(', ')})"
  name_str + args_str
end

.outdentObject



32
33
34
# File 'lib/tell_me_about_it.rb', line 32

def self.outdent
  $_tma_indent -= 1
end

.remember_indentObject



36
37
38
# File 'lib/tell_me_about_it.rb', line 36

def self.remember_indent
  $_tma_last_indent = $_tma_indent
end

.resetObject



18
19
20
21
22
# File 'lib/tell_me_about_it.rb', line 18

def self.reset
  $_tma_count = 0
  $_tma_indent = 0
  $_tma_last_indent = 0
end

.result_str(result, indent_str) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/tell_me_about_it.rb', line 102

def self.result_str result, indent_str
  result.to_s.color(COLORS[:result]) + if result.instance_variables.any? && ENV['SHOW_YAML']
                        "\n" + indent_str + "         " + result.to_yaml.each_line.map do |l|
                          l.gsub(/\n/,'').color(COLORS[:result_yaml])
                        end.join("\n").gsub(/\n/, "\n#{indent_str}           ")
                      else
                        ''
                      end
end

.self_str(passed_self) ⇒ Object



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

def self.self_str passed_self
  passed_self.to_s.color(COLORS[:self])
end

.start_indent_strObject



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

def self.start_indent_str
  indent_str.reverse.sub("", "─├").reverse + "─┬─"
end

.time_str(seconds) ⇒ Object



97
98
99
100
# File 'lib/tell_me_about_it.rb', line 97

def self.time_str seconds
  time_str = (' ' * count.to_s.size) + ("%.4f sec" % seconds)
  seconds > 0.05 ? time_str.color(COLORS[:time_bad]) : time_str.color(COLORS[:time_good])
end

Instance Method Details

#tell_me_about(*method_names) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'lib/tell_me_about_it.rb', line 112

def tell_me_about(*method_names)
  method_names.each do |method_name|
    if class_method? method_name
      tell_me_about_class_method method_name
    else
      tell_me_about_instance_method method_name
    end
  end
end

#tell_me_about_class_method(*method_names) ⇒ Object Also known as: tell_me_about_class_methods



122
123
124
125
126
127
128
129
130
# File 'lib/tell_me_about_it.rb', line 122

def tell_me_about_class_method(*method_names)
  method_names.each do |method_name|
    class_eval <<-EOS, __FILE__, __LINE__ + 1
      class << self
        #{make_talk method_name}
      end
    EOS
  end
end

#tell_me_about_instance_method(*method_names) ⇒ Object Also known as: tell_me_about_instance_methods



133
134
135
136
137
138
139
# File 'lib/tell_me_about_it.rb', line 133

def tell_me_about_instance_method(*method_names)
  method_names.each do |method_name|
    class_eval <<-EOS, __FILE__, __LINE__ + 1
      #{make_talk method_name}
    EOS
  end
end