motion_print 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffac142eccd2d2f73bf506a2dab1bbf90efb2aff
4
- data.tar.gz: 12bed335eb67226e364bbb7d6742b009c496d544
3
+ metadata.gz: 58c6363a17cffb78937db16bff5317262d4cc700
4
+ data.tar.gz: 213a818bd37fd10de6aa55bf228468ae013c6b0c
5
5
  SHA512:
6
- metadata.gz: 544a094b259d414701ec119bd9a40ab7e645b5f13ae459cc7069f6281c4fd648153cb51538009a1f102c7f5a3758d68d710b5509449a1547c8d349b69406fabc
7
- data.tar.gz: 0f26af35ff66f03b926c32fa4dae2a861817f670c6cfb9376e70fb33dd3222d2f9218b1fe43a9b98ca7fbe4a0b32cd8d9bd846dabde6c872296a71706018f17b
6
+ metadata.gz: c117eed2673e4d12a4a218f979ceaa3614af27a56b14778950c2037bf96bd212642e2e8f6c5eba570c059a6bfa55e5a45dd4008fbbde5361242b553838c0f713
7
+ data.tar.gz: bb93fcd5d85beae72ad81fa272e20cfeca0cb2ed842dac97a236661f3f818c737daded4cf301fbbf489e46a586ceef7bfe5fbefcb739ea27d8a78ca551246887
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  A RubyMotion pretty printer.
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/motion_print.svg)](http://badge.fury.io/rb/motion_print) [![Build Status](https://travis-ci.org/OTGApps/motion_print.svg)](https://travis-ci.org/OTGApps/motion_print) [![Code Climate](https://codeclimate.com/github/OTGapps/motion_print.png)](https://codeclimate.com/github/OTGApps/motion_print)
5
+ [![Gem Version](https://badge.fury.io/rb/motion_print.svg)](http://badge.fury.io/rb/motion_print)
6
+ [![Build Status](https://travis-ci.org/OTGApps/motion_print.svg)](https://travis-ci.org/OTGApps/motion_print)
7
+ [![Code Climate](https://codeclimate.com/github/OTGApps/motion_print/badges/gpa.svg)](https://codeclimate.com/github/OTGApps/motion_print)
6
8
 
7
9
  instead of using `p` or `puts`, use `mp` to log your debug values to the RubyMotion REPL.
8
10
 
@@ -65,6 +67,37 @@ And then execute:
65
67
  ```bash
66
68
  bundle
67
69
  ```
70
+
71
+ ## Woah! This is great! How can I make my gem support `motion_print`?
72
+
73
+ `motion_print` supports other gems (or even your own classes in your project ) with an opt-in feature. All you have to do is implement the `motion_print` method in your class (with option `mp` and `options` arguments). You can see an example implementation of this [in the specs](https://github.com/OTGApps/motion_print/blob/master/spec/opt_in_spec.rb).
74
+
75
+ ### Essentially:
76
+
77
+ ```ruby
78
+ def MyCustomClass
79
+ def motion_print(mp)
80
+ # This will output in red!
81
+ mp.colorize("Some Output Here!", :red)
82
+ end
83
+ end
84
+ ```
85
+
86
+ Here's CDQ's implementation:
87
+
88
+ ```ruby
89
+ class CDQManagedObject
90
+ def motion_print(mp, options)
91
+ if respond_to? :attributes
92
+ "OID: " + mp.colorize(oid.gsub('"',''), options[:force_color]) + "\n" + mp.l_hash(attributes, options)
93
+ else
94
+ # old colorless method, still more informative than nothing
95
+ log
96
+ end
97
+ end
98
+ end
99
+ ```
100
+
68
101
  ## Fancy Debugging Tips
69
102
 
70
103
  Ruby comes with some great methods for method introspection. These methods look great in motion_print.
@@ -33,7 +33,7 @@ module MotionPrint
33
33
  when cdq_object
34
34
  l_cdq(object, options)
35
35
  else
36
- colorize(object, options[:force_color])
36
+ l_custom(object, options)
37
37
  end
38
38
  end
39
39
 
@@ -52,13 +52,7 @@ module MotionPrint
52
52
  out = []
53
53
 
54
54
  a.each do |arr|
55
-
56
- if arr.is_a?(Array) || arr.is_a?(Hash)
57
- v = logger(arr, options.merge({indent_level: options[:indent_level] + 1}))
58
- else
59
- v = logger(arr, options)
60
- end
61
- out << (indent_by(options[:indent_level]) << v)
55
+ out << (indent_by(options[:indent_level]) << array_hash_logger(arr, options))
62
56
  end
63
57
 
64
58
  "[\n" << out.join(",\n") << "\n#{indent_by(options[:indent_level]-1)}]"
@@ -76,17 +70,20 @@ module MotionPrint
76
70
  width += indent_by(options[:indent_level]).length
77
71
 
78
72
  data.each do |key, value|
79
- if value.is_a?(Array) || value.is_a?(Hash)
80
- v = logger(value, options.merge({indent_level: options[:indent_level] + 1}))
81
- else
82
- v = logger(value, options)
83
- end
84
- out << (align(key, width, options[:indent_level]) << hash_rocket(options[:force_color]) << v)
73
+ out << (align(key, width, options[:indent_level]) << hash_rocket(options[:force_color]) << array_hash_logger(value, options))
85
74
  end
86
75
 
87
76
  "{\n" << out.join(",\n") << "\n#{indent_by(options[:indent_level]-1)}}"
88
77
  end
89
78
 
79
+ def array_hash_logger(value, options)
80
+ if value.is_a?(Array) || value.is_a?(Hash)
81
+ logger(value, options.merge({indent_level: options[:indent_level] + 1}))
82
+ else
83
+ logger(value, options)
84
+ end
85
+ end
86
+
90
87
  def l_dir(d, options)
91
88
  ls = `ls -alF #{d.path.shellescape}`
92
89
  colorize(ls.empty? ? d.inspect : "#{d.inspect}\n#{ls.chop}", options[:force_color])
@@ -96,6 +93,21 @@ module MotionPrint
96
93
  colorize(object, options[:force_color])
97
94
  end
98
95
 
96
+ def l_custom(object, options)
97
+ if object.respond_to?(:motion_print)
98
+ case object.method(:motion_print).arity
99
+ when 1
100
+ return object.motion_print(self)
101
+ when 2
102
+ return object.motion_print(self, options)
103
+ else
104
+ return colorize(object.motion_print, options[:force_color])
105
+ end
106
+ end
107
+
108
+ colorize(object, options[:force_color])
109
+ end
110
+
99
111
  def colorize(object, force_color = nil)
100
112
  Colorizer.send(force_color || decide_color(object), object.inspect)
101
113
  end
@@ -1,3 +1,3 @@
1
1
  module MotionPrint
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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.0.0
4
+ version: 1.1.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-04-28 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bacon