motion_print 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/motion/motion_print/motion_print.rb +39 -2
- data/motion/motion_print/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4557eb04c62bc6167ce65690d2961282035af816
|
4
|
+
data.tar.gz: 8cd9c998fa66752736a4406ec96c3abe8dc45319
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e083b5223cf9116fd2afb930ea4c056eb1caece75f29bb83c13efe5ba9118bdad9bf0eebcae2b31338debc3175f2ed8028864c3cf12dd64f1883824db24fec
|
7
|
+
data.tar.gz: 9ea84fbd1e435b993c92d56d9f8f24a0ea2d92187195246ac33ad8acfc31649f8019c91ffe467ca99f60f5acc7a3a220c5a80e25f20394ce12999c7369f64a14
|
data/README.md
CHANGED
@@ -126,7 +126,7 @@ That, coupled with the fact that the developer of awesome_print_motion doesn't s
|
|
126
126
|
|
127
127
|
`awesome_print_motion` is 793 lines of code and extends `Array`, `Kernel`, `Class`, and `Object`, and is _not_ tested.
|
128
128
|
|
129
|
-
`motion_print` is
|
129
|
+
`motion_print` is 174 lines of code, adds one method each to `String`, and `Kernel`, and is _fully_ tested (run `rake spec` to see the tests pass).
|
130
130
|
|
131
131
|
## Contributing
|
132
132
|
|
@@ -8,7 +8,8 @@ module MotionPrint
|
|
8
8
|
def logger(object, options = {})
|
9
9
|
options = {
|
10
10
|
indent_level: 1,
|
11
|
-
force_color: nil
|
11
|
+
force_color: nil,
|
12
|
+
ivar: true
|
12
13
|
}.merge(options)
|
13
14
|
|
14
15
|
case object
|
@@ -87,11 +88,38 @@ module MotionPrint
|
|
87
88
|
else
|
88
89
|
return colorize(object.motion_print, options[:force_color])
|
89
90
|
end
|
91
|
+
elsif object.respond_to?(:instance_variables) && !object.instance_variables.empty?
|
92
|
+
return l_instance_variables(object, options)
|
90
93
|
end
|
91
94
|
|
92
95
|
colorize(object, options[:force_color])
|
93
96
|
end
|
94
97
|
|
98
|
+
# Output a list of instance variables. only allows one level to avoid excessive output
|
99
|
+
# and circular references. Will also show a different color for instance variables that
|
100
|
+
# have accessors or not.
|
101
|
+
def l_instance_variables(object, options)
|
102
|
+
ivars = object.instance_variables.reject {|item| !item.to_s.start_with?('@')} # only allow proper instance variables
|
103
|
+
return colorize(object, options[:force_color]) if !options[:ivar] || ivars.empty?
|
104
|
+
data = []
|
105
|
+
out = [class_address(object, options[:force_color])]
|
106
|
+
|
107
|
+
ivars.each do |ivar|
|
108
|
+
use_color = object.respond_to?(ivar.to_s[1..-1]) ? colors[:method] : colors[:ivar]
|
109
|
+
data << [logger(ivar, options.merge({force_color: specific_color(use_color, options)})), ivar]
|
110
|
+
end
|
111
|
+
|
112
|
+
width = data.map { |ivar_str, | ivar_str.size }.max || 0
|
113
|
+
width += indent_by(options[:indent_level]).length
|
114
|
+
|
115
|
+
data.each do |ivar_str, ivar|
|
116
|
+
out << (align(ivar_str, width, options[:indent_level]) << hash_rocket(options[:force_color]) <<
|
117
|
+
logger(object.instance_variable_get(ivar), options.merge({ivar: false, force_color: specific_color(:pale, options)})))
|
118
|
+
end
|
119
|
+
|
120
|
+
out.join("\n") << "\n#{indent_by(options[:indent_level] - 1)}"
|
121
|
+
end
|
122
|
+
|
95
123
|
def colorize(object, force_color = nil)
|
96
124
|
Colorizer.send(force_color || decide_color(object), object.inspect)
|
97
125
|
end
|
@@ -100,9 +128,17 @@ module MotionPrint
|
|
100
128
|
Colorizer.send(force_color || decide_color(:hash), " => ")
|
101
129
|
end
|
102
130
|
|
131
|
+
def class_address(object, force_color = nil)
|
132
|
+
Colorizer.send(force_color || colors[:class], "#<#{object.class}:0x%08x>" % (object.object_id))
|
133
|
+
end
|
134
|
+
|
103
135
|
def decide_color(object)
|
104
136
|
colors[object.class.to_s.downcase.to_sym] || :white
|
105
137
|
end
|
138
|
+
|
139
|
+
def specific_color(color, options)
|
140
|
+
options[:force_color] || color
|
141
|
+
end
|
106
142
|
|
107
143
|
def colors
|
108
144
|
{
|
@@ -125,7 +161,8 @@ module MotionPrint
|
|
125
161
|
time: :greenish,
|
126
162
|
trueclass: :green,
|
127
163
|
variable: :cyanish,
|
128
|
-
dir: :white
|
164
|
+
dir: :white,
|
165
|
+
ivar: :cyanish
|
129
166
|
}
|
130
167
|
end
|
131
168
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion_print
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bacon
|