motion-icebox 0.1.1
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.
- data/README.md +79 -0
- data/lib/motion-icebox.rb +64 -0
- metadata +48 -0
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#Icebox
|
2
|
+
|
3
|
+
Fed up with only using puts statements to debug your rubymotion programs?
|
4
|
+
|
5
|
+
Wish you could see what your objects' state are at any given time?
|
6
|
+
|
7
|
+
**Enter Icebox!**
|
8
|
+
|
9
|
+
Icebox presents a simple key/value store for your rubymotion debugging needs.
|
10
|
+
|
11
|
+
Freeze an object! Extract it later! Examine what your objects are doing at a given time!
|
12
|
+
|
13
|
+
Icebox Deep duplicates your objects if possible. If not, it makes a clone.
|
14
|
+
|
15
|
+
|
16
|
+
##API
|
17
|
+
|
18
|
+
```
|
19
|
+
Icebox.freeze(object, :tag) # => freezes your object in memory at it's given state
|
20
|
+
Icebox.unfreeze(:tag) # => unfreezes the object you saved.
|
21
|
+
```
|
22
|
+
|
23
|
+
##Does Icebox have any Dependencies?
|
24
|
+
no
|
25
|
+
|
26
|
+
##Can I See an example?
|
27
|
+
yes.
|
28
|
+
```
|
29
|
+
class Human
|
30
|
+
|
31
|
+
attr_reader :name
|
32
|
+
def initialize(name)
|
33
|
+
@name = name
|
34
|
+
@heartbeats_left = 1_000
|
35
|
+
end
|
36
|
+
|
37
|
+
def heartbeat
|
38
|
+
@heartbeats_left -= 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def status
|
42
|
+
if dead?
|
43
|
+
"#{name} is dead."
|
44
|
+
else
|
45
|
+
"#{name} still has crazy wizard eyes."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def dead?
|
50
|
+
@heartbeats_left <= 0
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
simon = Human.new('Simon Petrikov')
|
56
|
+
|
57
|
+
Icebox.freeze(simon, :ice_king)
|
58
|
+
|
59
|
+
1_000.times do
|
60
|
+
simon.heartbeat
|
61
|
+
end
|
62
|
+
|
63
|
+
puts simon.status
|
64
|
+
puts simon.object_id
|
65
|
+
|
66
|
+
ice_king = Icebox.unfreeze(:ice_king)
|
67
|
+
puts ice_king.status
|
68
|
+
puts ice_king.object_id
|
69
|
+
```
|
70
|
+
|
71
|
+
##Future Development ideas
|
72
|
+
1. Passing in an option the method by which you want to save your object.
|
73
|
+
2. Meta-data about how the object was saved, and when.
|
74
|
+
|
75
|
+
##Does Icebox have a mascot?
|
76
|
+
yes
|
77
|
+
|
78
|
+
|
79
|
+

|
@@ -0,0 +1,64 @@
|
|
1
|
+
class Icebox
|
2
|
+
|
3
|
+
def self.freeze(obj, name, options = {})
|
4
|
+
instance.freeze(obj, name, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.unfreeze(name = nil)
|
8
|
+
instance.unfreeze(name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.instance
|
12
|
+
@instance ||= new
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :storage
|
16
|
+
|
17
|
+
def freeze(obj, name, options)
|
18
|
+
storage[name] = val(obj)
|
19
|
+
end
|
20
|
+
|
21
|
+
def unfreeze(name)
|
22
|
+
storage[name].load
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@storage = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def val(obj)
|
30
|
+
StoredObject.new(obj)
|
31
|
+
end
|
32
|
+
|
33
|
+
class StoredObject
|
34
|
+
|
35
|
+
attr_reader :time_stored
|
36
|
+
attr_accessor :storage_type
|
37
|
+
|
38
|
+
def initialize(original_obj)
|
39
|
+
@obj = save(original_obj)
|
40
|
+
@time_stored = Time.now
|
41
|
+
end
|
42
|
+
|
43
|
+
def save(obj)
|
44
|
+
begin
|
45
|
+
self.storage_type = :marshal
|
46
|
+
Marshal.dump obj
|
47
|
+
rescue
|
48
|
+
self.storage_type = :clone
|
49
|
+
obj.clone
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def load
|
54
|
+
case storage_type
|
55
|
+
when :marshal
|
56
|
+
Marshal.load @obj
|
57
|
+
when :clone
|
58
|
+
@obj
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-icebox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Watts
|
9
|
+
- justalisteningman
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Motion Icebox - A way to save your objects for later inspection
|
16
|
+
email: ben@benjaminclaywatts.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- lib/motion-icebox.rb
|
23
|
+
homepage: http://rubymotionquery.com
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.28
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Motion Icebox
|
48
|
+
test_files: []
|