motion-pool 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9bb1aaae1c541c2f4f0862057d1f66f688b6f689
4
+ data.tar.gz: 7447ee5245d03a245e687fbf1574eb9b0dbae374
5
+ SHA512:
6
+ metadata.gz: ed131fe7811ab24183e19ca5a41e07dd883e0a747dbdb1bccacc2ea8a2de1b11eba39bf417f4f41eac893d51df4cdd1e5f3ed66b4739c7f263e70380621a3169
7
+ data.tar.gz: 9a0cdc8b72098e688fe21826202193cb821f4e47757cdc3456f4b7966714550fb9ede08ea105884a5d5bb21804be0d1162a0696f4b57d1d394b9011d9b491798
data/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2014, Frédéric Mascaro
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # motion-pool
2
+
3
+ A pool for RubyMotion.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'motion-pool'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install motion-pool
18
+
19
+ ## Test
20
+
21
+ $ PLATFORM=osx rake spec output=colorized2
22
+ $ PLATFORM=ios rake spec output=colorized2
23
+
24
+ ## Usage
25
+
26
+ See spec.
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise "This file must be required within a RubyMotion project Rakefile."
5
+ end
6
+
7
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
8
+ Motion::Project::App.setup do |app|
9
+ app.files.concat(Dir.glob(File.join(lib_dir_path, "../motion/common/**/*.rb")))
10
+
11
+ if App.template == :osx
12
+ app.files.concat(Dir.glob(File.join(lib_dir_path, "../motion/osx/**/*.rb")))
13
+ elsif App.template == :ios
14
+ app.files.concat(Dir.glob(File.join(lib_dir_path, "../motion/ios/**/*.rb")))
15
+ else
16
+ raise "Incompatible platform: #{App.template}"
17
+ end
18
+ end
@@ -0,0 +1,77 @@
1
+ class Pool
2
+ class Exception < NSException
3
+ end
4
+
5
+ # --------------------------------------------------------------------------------
6
+ # --------------------------------------------------------------------------------
7
+ # --------------------------------------------------------------------------------
8
+
9
+ class PooledObject
10
+ attr_accessor :object
11
+
12
+ # --------------------------------------------------------------------------------
13
+
14
+ def initWithObject(object)
15
+ @object = object
16
+
17
+ self
18
+ end
19
+ end
20
+
21
+ # --------------------------------------------------------------------------------
22
+ # --------------------------------------------------------------------------------
23
+ # --------------------------------------------------------------------------------
24
+
25
+ def initWithDelegate(delegate)
26
+ @delegate = delegate
27
+ @idle_objects = []
28
+ @active_objects = {}
29
+
30
+ self
31
+ end
32
+
33
+ # --------------------------------------------------------------------------------
34
+
35
+ def borrow_object
36
+ pooled_object = @idle_objects.shift
37
+
38
+ if pooled_object.nil?
39
+ object = @delegate.makeObject
40
+ pooled_object = Pool::PooledObject.alloc.initWithObject(object)
41
+ else
42
+ object = pooled_object.object
43
+ end
44
+
45
+ @active_objects[object] = pooled_object
46
+
47
+ object
48
+ end
49
+
50
+ # --------------------------------------------------------------------------------
51
+
52
+ def return_object(object)
53
+ pooled_object = @active_objects[object]
54
+
55
+ if pooled_object.nil?
56
+ exception = Pool::Exception.alloc.initWithName("Pool::Exception", reason: "unkown object", userInfo: nil)
57
+ exception.raise
58
+ else
59
+ @active_objects.delete(object)
60
+ @idle_objects << pooled_object
61
+ end
62
+
63
+ nil
64
+ end
65
+
66
+ # --------------------------------------------------------------------------------
67
+
68
+ def idle_object_count
69
+ @idle_objects.count
70
+ end
71
+
72
+ # --------------------------------------------------------------------------------
73
+
74
+ def active_object_count
75
+ @active_objects.count
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def method_missing(sym, *args, &block)
3
+ Term::ANSIColor.send(sym) { self } rescue super
4
+ end
5
+ end
@@ -0,0 +1,556 @@
1
+ module Term
2
+ # The ANSIColor module can be used for namespacing and mixed into your own
3
+ # classes.
4
+ module ANSIColor
5
+ # :stopdoc:
6
+ ATTRIBUTES = [
7
+ [ :clear , 0 ],
8
+ [ :reset , 0 ], # synonym for :clear
9
+ [ :bold , 1 ],
10
+ [ :dark , 2 ],
11
+ [ :italic , 3 ], # not widely implemented
12
+ [ :underline , 4 ],
13
+ [ :underscore , 4 ], # synonym for :underline
14
+ [ :blink , 5 ],
15
+ [ :rapid_blink , 6 ], # not widely implemented
16
+ [ :negative , 7 ], # no reverse because of String#reverse
17
+ [ :concealed , 8 ],
18
+ [ :strikethrough, 9 ], # not widely implemented
19
+ [ :black , 30 ],
20
+ [ :red , 31 ],
21
+ [ :green , 32 ],
22
+ [ :yellow , 33 ],
23
+ [ :blue , 34 ],
24
+ [ :magenta , 35 ],
25
+ [ :cyan , 36 ],
26
+ [ :white , 37 ],
27
+ [ :on_black , 40 ],
28
+ [ :on_red , 41 ],
29
+ [ :on_green , 42 ],
30
+ [ :on_yellow , 43 ],
31
+ [ :on_blue , 44 ],
32
+ [ :on_magenta , 45 ],
33
+ [ :on_cyan , 46 ],
34
+ [ :on_white , 47 ],
35
+ ]
36
+
37
+ ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
38
+ # :startdoc:
39
+
40
+ # Returns true, if the coloring function of this module
41
+ # is switched on, false otherwise.
42
+ def self.coloring?
43
+ @coloring
44
+ end
45
+
46
+ # Turns the coloring on or off globally, so you can easily do
47
+ # this for example:
48
+ # Term::ANSIColor::coloring = STDOUT.isatty
49
+ def self.coloring=(val)
50
+ @coloring = val
51
+ end
52
+ self.coloring = true
53
+
54
+
55
+ def clear(string = nil)
56
+ result = ''
57
+ result << "" if Term::ANSIColor.coloring?
58
+ if block_given?
59
+ result << yield
60
+ elsif string
61
+ result << string
62
+ elsif respond_to?(:to_str)
63
+ result << self
64
+ else
65
+ return result #only switch on
66
+ end
67
+ result << "" if Term::ANSIColor.coloring?
68
+ result
69
+ end
70
+
71
+
72
+ def reset(string = nil)
73
+ result = ''
74
+ result << "" if Term::ANSIColor.coloring?
75
+ if block_given?
76
+ result << yield
77
+ elsif string
78
+ result << string
79
+ elsif respond_to?(:to_str)
80
+ result << self
81
+ else
82
+ return result #only switch on
83
+ end
84
+ result << "" if Term::ANSIColor.coloring?
85
+ result
86
+ end
87
+
88
+
89
+ def bold(string = nil)
90
+ result = ''
91
+ result << "" if Term::ANSIColor.coloring?
92
+ if block_given?
93
+ result << yield
94
+ elsif string
95
+ result << string
96
+ elsif respond_to?(:to_str)
97
+ result << self
98
+ else
99
+ return result #only switch on
100
+ end
101
+ result << "" if Term::ANSIColor.coloring?
102
+ result
103
+ end
104
+
105
+
106
+ def dark(string = nil)
107
+ result = ''
108
+ result << "" if Term::ANSIColor.coloring?
109
+ if block_given?
110
+ result << yield
111
+ elsif string
112
+ result << string
113
+ elsif respond_to?(:to_str)
114
+ result << self
115
+ else
116
+ return result #only switch on
117
+ end
118
+ result << "" if Term::ANSIColor.coloring?
119
+ result
120
+ end
121
+
122
+
123
+ def italic(string = nil)
124
+ result = ''
125
+ result << "" if Term::ANSIColor.coloring?
126
+ if block_given?
127
+ result << yield
128
+ elsif string
129
+ result << string
130
+ elsif respond_to?(:to_str)
131
+ result << self
132
+ else
133
+ return result #only switch on
134
+ end
135
+ result << "" if Term::ANSIColor.coloring?
136
+ result
137
+ end
138
+
139
+
140
+ def underline(string = nil)
141
+ result = ''
142
+ result << "" if Term::ANSIColor.coloring?
143
+ if block_given?
144
+ result << yield
145
+ elsif string
146
+ result << string
147
+ elsif respond_to?(:to_str)
148
+ result << self
149
+ else
150
+ return result #only switch on
151
+ end
152
+ result << "" if Term::ANSIColor.coloring?
153
+ result
154
+ end
155
+
156
+
157
+ def underscore(string = nil)
158
+ result = ''
159
+ result << "" if Term::ANSIColor.coloring?
160
+ if block_given?
161
+ result << yield
162
+ elsif string
163
+ result << string
164
+ elsif respond_to?(:to_str)
165
+ result << self
166
+ else
167
+ return result #only switch on
168
+ end
169
+ result << "" if Term::ANSIColor.coloring?
170
+ result
171
+ end
172
+
173
+
174
+ def blink(string = nil)
175
+ result = ''
176
+ result << "" if Term::ANSIColor.coloring?
177
+ if block_given?
178
+ result << yield
179
+ elsif string
180
+ result << string
181
+ elsif respond_to?(:to_str)
182
+ result << self
183
+ else
184
+ return result #only switch on
185
+ end
186
+ result << "" if Term::ANSIColor.coloring?
187
+ result
188
+ end
189
+
190
+
191
+ def rapid_blink(string = nil)
192
+ result = ''
193
+ result << "" if Term::ANSIColor.coloring?
194
+ if block_given?
195
+ result << yield
196
+ elsif string
197
+ result << string
198
+ elsif respond_to?(:to_str)
199
+ result << self
200
+ else
201
+ return result #only switch on
202
+ end
203
+ result << "" if Term::ANSIColor.coloring?
204
+ result
205
+ end
206
+
207
+
208
+ def negative(string = nil)
209
+ result = ''
210
+ result << "" if Term::ANSIColor.coloring?
211
+ if block_given?
212
+ result << yield
213
+ elsif string
214
+ result << string
215
+ elsif respond_to?(:to_str)
216
+ result << self
217
+ else
218
+ return result #only switch on
219
+ end
220
+ result << "" if Term::ANSIColor.coloring?
221
+ result
222
+ end
223
+
224
+
225
+ def concealed(string = nil)
226
+ result = ''
227
+ result << "" if Term::ANSIColor.coloring?
228
+ if block_given?
229
+ result << yield
230
+ elsif string
231
+ result << string
232
+ elsif respond_to?(:to_str)
233
+ result << self
234
+ else
235
+ return result #only switch on
236
+ end
237
+ result << "" if Term::ANSIColor.coloring?
238
+ result
239
+ end
240
+
241
+
242
+ def strikethrough(string = nil)
243
+ result = ''
244
+ result << "" if Term::ANSIColor.coloring?
245
+ if block_given?
246
+ result << yield
247
+ elsif string
248
+ result << string
249
+ elsif respond_to?(:to_str)
250
+ result << self
251
+ else
252
+ return result #only switch on
253
+ end
254
+ result << "" if Term::ANSIColor.coloring?
255
+ result
256
+ end
257
+
258
+
259
+ def black(string = nil)
260
+ result = ''
261
+ result << "" if Term::ANSIColor.coloring?
262
+ if block_given?
263
+ result << yield
264
+ elsif string
265
+ result << string
266
+ elsif respond_to?(:to_str)
267
+ result << self
268
+ else
269
+ return result #only switch on
270
+ end
271
+ result << "" if Term::ANSIColor.coloring?
272
+ result
273
+ end
274
+
275
+
276
+ def red(string = nil)
277
+ result = ''
278
+ result << "" if Term::ANSIColor.coloring?
279
+ if block_given?
280
+ result << yield
281
+ elsif string
282
+ result << string
283
+ elsif respond_to?(:to_str)
284
+ result << self
285
+ else
286
+ return result #only switch on
287
+ end
288
+ result << "" if Term::ANSIColor.coloring?
289
+ result
290
+ end
291
+
292
+
293
+ def green(string = nil)
294
+ result = ''
295
+ result << "" if Term::ANSIColor.coloring?
296
+ if block_given?
297
+ result << yield
298
+ elsif string
299
+ result << string
300
+ elsif respond_to?(:to_str)
301
+ result << self
302
+ else
303
+ return result #only switch on
304
+ end
305
+ result << "" if Term::ANSIColor.coloring?
306
+ result
307
+ end
308
+
309
+
310
+ def yellow(string = nil)
311
+ result = ''
312
+ result << "" if Term::ANSIColor.coloring?
313
+ if block_given?
314
+ result << yield
315
+ elsif string
316
+ result << string
317
+ elsif respond_to?(:to_str)
318
+ result << self
319
+ else
320
+ return result #only switch on
321
+ end
322
+ result << "" if Term::ANSIColor.coloring?
323
+ result
324
+ end
325
+
326
+
327
+ def blue(string = nil)
328
+ result = ''
329
+ result << "" if Term::ANSIColor.coloring?
330
+ if block_given?
331
+ result << yield
332
+ elsif string
333
+ result << string
334
+ elsif respond_to?(:to_str)
335
+ result << self
336
+ else
337
+ return result #only switch on
338
+ end
339
+ result << "" if Term::ANSIColor.coloring?
340
+ result
341
+ end
342
+
343
+
344
+ def magenta(string = nil)
345
+ result = ''
346
+ result << "" if Term::ANSIColor.coloring?
347
+ if block_given?
348
+ result << yield
349
+ elsif string
350
+ result << string
351
+ elsif respond_to?(:to_str)
352
+ result << self
353
+ else
354
+ return result #only switch on
355
+ end
356
+ result << "" if Term::ANSIColor.coloring?
357
+ result
358
+ end
359
+
360
+
361
+ def cyan(string = nil)
362
+ result = ''
363
+ result << "" if Term::ANSIColor.coloring?
364
+ if block_given?
365
+ result << yield
366
+ elsif string
367
+ result << string
368
+ elsif respond_to?(:to_str)
369
+ result << self
370
+ else
371
+ return result #only switch on
372
+ end
373
+ result << "" if Term::ANSIColor.coloring?
374
+ result
375
+ end
376
+
377
+
378
+ def white(string = nil)
379
+ result = ''
380
+ result << "" if Term::ANSIColor.coloring?
381
+ if block_given?
382
+ result << yield
383
+ elsif string
384
+ result << string
385
+ elsif respond_to?(:to_str)
386
+ result << self
387
+ else
388
+ return result #only switch on
389
+ end
390
+ result << "" if Term::ANSIColor.coloring?
391
+ result
392
+ end
393
+
394
+
395
+ def on_black(string = nil)
396
+ result = ''
397
+ result << "" if Term::ANSIColor.coloring?
398
+ if block_given?
399
+ result << yield
400
+ elsif string
401
+ result << string
402
+ elsif respond_to?(:to_str)
403
+ result << self
404
+ else
405
+ return result #only switch on
406
+ end
407
+ result << "" if Term::ANSIColor.coloring?
408
+ result
409
+ end
410
+
411
+
412
+ def on_red(string = nil)
413
+ result = ''
414
+ result << "" if Term::ANSIColor.coloring?
415
+ if block_given?
416
+ result << yield
417
+ elsif string
418
+ result << string
419
+ elsif respond_to?(:to_str)
420
+ result << self
421
+ else
422
+ return result #only switch on
423
+ end
424
+ result << "" if Term::ANSIColor.coloring?
425
+ result
426
+ end
427
+
428
+
429
+ def on_green(string = nil)
430
+ result = ''
431
+ result << "" if Term::ANSIColor.coloring?
432
+ if block_given?
433
+ result << yield
434
+ elsif string
435
+ result << string
436
+ elsif respond_to?(:to_str)
437
+ result << self
438
+ else
439
+ return result #only switch on
440
+ end
441
+ result << "" if Term::ANSIColor.coloring?
442
+ result
443
+ end
444
+
445
+
446
+ def on_yellow(string = nil)
447
+ result = ''
448
+ result << "" if Term::ANSIColor.coloring?
449
+ if block_given?
450
+ result << yield
451
+ elsif string
452
+ result << string
453
+ elsif respond_to?(:to_str)
454
+ result << self
455
+ else
456
+ return result #only switch on
457
+ end
458
+ result << "" if Term::ANSIColor.coloring?
459
+ result
460
+ end
461
+
462
+
463
+ def on_blue(string = nil)
464
+ result = ''
465
+ result << "" if Term::ANSIColor.coloring?
466
+ if block_given?
467
+ result << yield
468
+ elsif string
469
+ result << string
470
+ elsif respond_to?(:to_str)
471
+ result << self
472
+ else
473
+ return result #only switch on
474
+ end
475
+ result << "" if Term::ANSIColor.coloring?
476
+ result
477
+ end
478
+
479
+
480
+ def on_magenta(string = nil)
481
+ result = ''
482
+ result << "" if Term::ANSIColor.coloring?
483
+ if block_given?
484
+ result << yield
485
+ elsif string
486
+ result << string
487
+ elsif respond_to?(:to_str)
488
+ result << self
489
+ else
490
+ return result #only switch on
491
+ end
492
+ result << "" if Term::ANSIColor.coloring?
493
+ result
494
+ end
495
+
496
+
497
+ def on_cyan(string = nil)
498
+ result = ''
499
+ result << "" if Term::ANSIColor.coloring?
500
+ if block_given?
501
+ result << yield
502
+ elsif string
503
+ result << string
504
+ elsif respond_to?(:to_str)
505
+ result << self
506
+ else
507
+ return result #only switch on
508
+ end
509
+ result << "" if Term::ANSIColor.coloring?
510
+ result
511
+ end
512
+
513
+
514
+ def on_white(string = nil)
515
+ result = ''
516
+ result << "" if Term::ANSIColor.coloring?
517
+ if block_given?
518
+ result << yield
519
+ elsif string
520
+ result << string
521
+ elsif respond_to?(:to_str)
522
+ result << self
523
+ else
524
+ return result #only switch on
525
+ end
526
+ result << "" if Term::ANSIColor.coloring?
527
+ result
528
+ end
529
+
530
+ # Regular expression that is used to scan for ANSI-sequences while
531
+ # uncoloring strings.
532
+ COLORED_REGEXP = /\e\[([34][0-7]|[0-9])m/
533
+
534
+ # Returns an uncolored version of the string, that is all
535
+ # ANSI-sequences are stripped from the string.
536
+ def uncolored(string = nil) # :yields:
537
+ if block_given?
538
+ yield.gsub(COLORED_REGEXP, '')
539
+ elsif string
540
+ string.gsub(COLORED_REGEXP, '')
541
+ elsif respond_to?(:to_str)
542
+ gsub(COLORED_REGEXP, '')
543
+ else
544
+ ''
545
+ end
546
+ end
547
+
548
+ module_function
549
+
550
+ # Returns an array of all Term::ANSIColor attributes as symbols.
551
+ def attributes
552
+ ATTRIBUTE_NAMES
553
+ end
554
+ extend self
555
+ end
556
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-pool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Frédéric Mascaro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A pool for RubyMotion.
28
+ email:
29
+ - frederic.mascaro@wo-oo.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - lib/motion-pool.rb
37
+ - motion/common/pool.rb
38
+ - motion/common/string.rb
39
+ - motion/common/term.rb
40
+ homepage: https://github.com/wooandoo/motion-pool
41
+ licenses:
42
+ - BSD3
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A pool for RubyMotion
64
+ test_files: []