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
- .cont_indent_str ⇒ Object
- .context_str(method_caller) ⇒ Object
- .count ⇒ Object
- .count_str ⇒ Object
- .end_indent_str ⇒ Object
- .file_str(method_caller) ⇒ Object
- .inc ⇒ Object
- .indent ⇒ Object
- .indent_changed? ⇒ Boolean
- .indent_level ⇒ Object
- .indent_str ⇒ Object
- .method_str(method_name, *args) ⇒ Object
- .outdent ⇒ Object
- .remember_indent ⇒ Object
- .reset ⇒ Object
- .result_str(result, indent_str) ⇒ Object
- .self_str(passed_self) ⇒ Object
- .start_indent_str ⇒ Object
- .time_str(seconds) ⇒ Object
Instance Method Summary collapse
- #tell_me_about(*method_names) ⇒ Object
- #tell_me_about_class_method(*method_names) ⇒ Object (also: #tell_me_about_class_methods)
- #tell_me_about_instance_method(*method_names) ⇒ Object (also: #tell_me_about_instance_methods)
Class Method Details
.cont_indent_str ⇒ Object
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 |
.count ⇒ Object
40 41 42 |
# File 'lib/tell_me_about_it.rb', line 40 def self.count $_tma_count ||= 0 end |
.count_str ⇒ Object
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_str ⇒ Object
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 |
.inc ⇒ Object
24 25 26 |
# File 'lib/tell_me_about_it.rb', line 24 def self.inc $_tma_count += 1 end |
.indent ⇒ Object
28 29 30 |
# File 'lib/tell_me_about_it.rb', line 28 def self.indent $_tma_indent += 1 end |
.indent_changed? ⇒ Boolean
48 49 50 |
# File 'lib/tell_me_about_it.rb', line 48 def self.indent_changed? $_tma_indent < $_tma_last_indent end |
.indent_level ⇒ Object
44 45 46 |
# File 'lib/tell_me_about_it.rb', line 44 def self.indent_level $_tma_indent ||= 0 end |
.indent_str ⇒ Object
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 |
.outdent ⇒ Object
32 33 34 |
# File 'lib/tell_me_about_it.rb', line 32 def self.outdent $_tma_indent -= 1 end |
.remember_indent ⇒ Object
36 37 38 |
# File 'lib/tell_me_about_it.rb', line 36 def self.remember_indent $_tma_last_indent = $_tma_indent end |
.reset ⇒ Object
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_str ⇒ Object
85 86 87 |
# File 'lib/tell_me_about_it.rb', line 85 def self.start_indent_str indent_str.reverse.sub(" │", "─├").reverse + "─┬─" 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 |