motion-support 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ class NSDictionary
2
+ # Returns a new Hash which is a copy of this hash, except that all keys have turned into symbols,
3
+ # if possible. That is all keys that respond to to_sym.
4
+ def symbolize_keys
5
+ inject({}) do |hash, pair|
6
+ if pair.first.respond_to?(:to_sym)
7
+ hash[pair.first.to_sym] = pair.last
8
+ else
9
+ hash[pair.first] = pair.last
10
+ end
11
+ hash
12
+ end
13
+ end
14
+ end
15
+
16
+ class Hash
17
+ # Changes all keys in this hash into symbols, if possible. That is all keys that respond to to_sym.
18
+ def symbolize_keys!
19
+ replace(symbolize_keys)
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ module MotionSupport
2
+ class NullLogger
3
+ def log(string)
4
+ end
5
+ end
6
+
7
+ class StdoutLogger
8
+ def log(string)
9
+ puts string
10
+ end
11
+ end
12
+
13
+ class NetworkLogger
14
+ def initialize(host = "localhost", port = 2000)
15
+ readStream = Pointer.new(:object)
16
+ writeStream = Pointer.new(:object)
17
+ CFStreamCreatePairWithSocketToHost(nil, host, port, readStream, writeStream)
18
+ @output_stream = writeStream[0]
19
+ @output_stream.setDelegate(self)
20
+ @output_stream.scheduleInRunLoop(NSRunLoop.currentRunLoop, forMode:NSDefaultRunLoopMode)
21
+ @output_stream.open
22
+ end
23
+
24
+ def log(string)
25
+ data = NSData.alloc.initWithData("#{string}\n".dataUsingEncoding(NSASCIIStringEncoding))
26
+ @output_stream.write(data.bytes, maxLength:data.length);
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module MotionSupport
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,15 @@
1
+ describe "hash" do
2
+ it "should return copy with symbolized keys" do
3
+ { 'foo' => 'bar', 'bla' => 'blub' }.symbolize_keys.should == { :foo => 'bar', :bla => 'blub' }
4
+ end
5
+
6
+ it "should not modify keys that can not be symbolized" do
7
+ { :foo => 'bar', 1 => 'blub' }.symbolize_keys.should == { :foo => 'bar', 1 => 'blub' }
8
+ end
9
+
10
+ it "should symbolize keys in place" do
11
+ hash = { 'foo' => 'bar', 'bla' => 'blub' }
12
+ hash.symbolize_keys!
13
+ hash.should == { :foo => 'bar', :bla => 'blub' }
14
+ end
15
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: motion-support
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Thomas Kadauke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-11-29 00:00:00 Z
13
+ date: 2012-12-31 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bubble-wrap
@@ -54,6 +54,8 @@ files:
54
54
  - lib/motion-support/cattr_accessor.rb
55
55
  - lib/motion-support/class_inheritable_accessor.rb
56
56
  - lib/motion-support/class_inheritable_array.rb
57
+ - lib/motion-support/hash.rb
58
+ - lib/motion-support/logger.rb
57
59
  - lib/motion-support/metaclass.rb
58
60
  - lib/motion-support/string.rb
59
61
  - lib/motion-support/version.rb
@@ -62,6 +64,7 @@ files:
62
64
  - spec/motion-support/cattr_accessor_spec.rb
63
65
  - spec/motion-support/class_inheritable_accessor_spec.rb
64
66
  - spec/motion-support/class_inheritable_array_spec.rb
67
+ - spec/motion-support/hash_spec.rb
65
68
  - spec/motion-support/metaclass_spec.rb
66
69
  - spec/motion-support/string_spec.rb
67
70
  homepage: https://github.com/tkadauke/motion-support
@@ -77,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
80
  requirements:
78
81
  - - ">="
79
82
  - !ruby/object:Gem::Version
80
- hash: -1369982760169453256
83
+ hash: -760150939951472099
81
84
  segments:
82
85
  - 0
83
86
  version: "0"
@@ -86,14 +89,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
89
  requirements:
87
90
  - - ">="
88
91
  - !ruby/object:Gem::Version
89
- hash: -1369982760169453256
92
+ hash: -760150939951472099
90
93
  segments:
91
94
  - 0
92
95
  version: "0"
93
96
  requirements: []
94
97
 
95
98
  rubyforge_project:
96
- rubygems_version: 1.8.17
99
+ rubygems_version: 1.8.19
97
100
  signing_key:
98
101
  specification_version: 3
99
102
  summary: Commonly useful extensions to the standard library for RubyMotion
@@ -102,5 +105,6 @@ test_files:
102
105
  - spec/motion-support/cattr_accessor_spec.rb
103
106
  - spec/motion-support/class_inheritable_accessor_spec.rb
104
107
  - spec/motion-support/class_inheritable_array_spec.rb
108
+ - spec/motion-support/hash_spec.rb
105
109
  - spec/motion-support/metaclass_spec.rb
106
110
  - spec/motion-support/string_spec.rb