PackingPeanut 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -15
- data/lib/project/PackingPeanut.rb +24 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98a56da3d30642faebb8dda8ba695b5eb14bf95a
|
4
|
+
data.tar.gz: 6025bffcaf7d9c5043f99d31280505e7bc2e52b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f38cf057b95e26e27e735bad06a1bde33a52939ad80f86a68ee911ce436066205ff5522ecc860d6d6182fd8172e8bbd45d47bff0eea9404979994ef1f3aa5bd
|
7
|
+
data.tar.gz: bafbe8748b9b246aa8eb7153ccac0bea64359263740a25e7555c04a36cea99b25c76ffee1cb3ba7e9112678239772fe7a41584f4587de6bbdda59a3450f5eadd
|
data/README.md
CHANGED
@@ -1,47 +1,68 @@
|
|
1
|
-
# PackingPeanut
|
1
|
+
# ![PackingPeanut Logo](./_art/logo_100.png) PackingPeanut
|
2
2
|
|
3
|
-
iOS has [BubbleWrap](https://github.com/rubymotion/BubbleWrap) for App Persistence : Android has
|
3
|
+
iOS has [BubbleWrap](https://github.com/rubymotion/BubbleWrap) for App Persistence : Android has PackingPeanut
|
4
4
|
|
5
|
-
There is a sedulous effort to make this syntax fit BubbleWrap's as much as possible, but differences simply exist, either for good, technical, or sometimes diabolical reasons
|
5
|
+
There is a sedulous effort to make this syntax fit BubbleWrap's as much as possible, but differences simply exist, either for good, technical, or sometimes diabolical reasons :smiling_imp:
|
6
|
+
|
7
|
+
[**GITHUB HOMEPAGE**](http://gantman.github.io/PackingPeanut/)
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
9
|
-
Add this line to your application's Gemfile:
|
11
|
+
**Step 1:** Add this line to your application's Gemfile:
|
10
12
|
|
11
13
|
gem 'PackingPeanut'
|
12
14
|
|
13
|
-
And then execute:
|
15
|
+
**Step 2:** And then execute:
|
14
16
|
|
15
17
|
$ bundle
|
16
18
|
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install PackingPeanut
|
20
|
-
|
21
19
|
## Usage
|
22
20
|
|
23
21
|
Example Usage from REPL
|
24
22
|
```
|
25
|
-
# PP automatically has context if the module is included
|
26
|
-
#
|
23
|
+
# PP automatically has context if the module is included
|
24
|
+
# In this case we need to set the context
|
27
25
|
$ App::Persistence.context = self
|
28
26
|
=> #<MainActivity:0x1d20058e>
|
29
27
|
$ App::Persistence['dinner'] = "nachos"
|
30
28
|
=> true # This differs from Bubblewrap.... boolean on success for save (more informative)
|
31
29
|
$ App::Persistence['dinner']
|
32
30
|
=> "nachos"
|
33
|
-
$ App::Persistence[
|
31
|
+
$ App::Persistence[:lunch] = "tacos"
|
32
|
+
=> "tacos" # Use symbols or strings as you please
|
34
33
|
$ App::Persistence.all
|
35
|
-
=> {
|
34
|
+
=> [{:dinner=>"nachos"}, {:lunch=>"tacos"}]
|
36
35
|
$ App::Persistence.storage_file = "some_new_file"
|
37
36
|
=> "some_new_file"
|
37
|
+
$ App::Persistence['dinner']
|
38
|
+
=> "" # empty because we're now outside the default storage file.
|
38
39
|
$ App::Persistence.preference_mode = :world_readable
|
39
40
|
=> :world_redable
|
40
|
-
$ App::Persistence['dinner']
|
41
|
-
=> "" # empty because we're now in a new storage file.
|
42
41
|
|
43
42
|
```
|
44
43
|
|
44
|
+
`App::Persistence` has been Aliasted to `PP::Persistence` for the bold.
|
45
|
+
|
46
|
+
## What are preference modes?
|
47
|
+
|
48
|
+
Preference Modes are ANdroid Operating modes. Use 0 or MODE_PRIVATE for the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions. The bit MODE_MULTI_PROCESS can also be used if multiple processes are mutating the same SharedPreferences file. MODE_MULTI_PROCESS is always on in apps targeting Gingerbread (Android 2.3) and below, and off by default in later versions.
|
49
|
+
|
50
|
+
Memorizable symbols and their corresponding constants:
|
51
|
+
```ruby
|
52
|
+
PREFERENCE_MODES = {
|
53
|
+
private: MODE_PRIVATE,
|
54
|
+
readable: MODE_WORLD_READABLE,
|
55
|
+
world_readable: MODE_WORLD_READABLE,
|
56
|
+
writable: MODE_WORLD_WRITEABLE,
|
57
|
+
world_writable: MODE_WORLD_WRITEABLE,
|
58
|
+
multi: MODE_MULTI_PROCESS,
|
59
|
+
multi_process: MODE_MULTI_PROCESS
|
60
|
+
}
|
61
|
+
```
|
62
|
+
|
63
|
+
## Limitations?
|
64
|
+
Achilles, the Death Star, and video game villians always have a significant catch. As of right now, you can only store strings, ints, and booleans. The data is serialized, and should support hashes, arrays, and floats but alas, I claim there be bugs in conversions via RM Android.
|
65
|
+
|
45
66
|
## Contributing
|
46
67
|
|
47
68
|
1. Fork it
|
@@ -2,9 +2,14 @@
|
|
2
2
|
# Potential fixes for type specifics
|
3
3
|
# Super fix #1 -> Serialize it: http://stackoverflow.com/questions/7057845/save-arraylist-to-sharedpreferences
|
4
4
|
# ObjectSerializer: https://github.com/apache/pig/blob/89c2e8e76c68d0d0abe6a36b4e08ddc56979796f/src/org/apache/pig/impl/util/ObjectSerializer.java
|
5
|
+
# https://pig.apache.org/releases.html
|
5
6
|
# Super fix #2 -> Store depending on the class and retrieve with either
|
6
7
|
# A: Failover defaults calling methods
|
7
8
|
# B: Grab ALL data, and use that hash
|
9
|
+
# Super fix #3 -> Serialize with JSON
|
10
|
+
# new Gson().toJson(obj)
|
11
|
+
# And for deserialization,
|
12
|
+
|
8
13
|
|
9
14
|
module App
|
10
15
|
module Persistence
|
@@ -14,6 +19,8 @@ module App
|
|
14
19
|
MODE_WORLD_WRITEABLE = 2
|
15
20
|
MODE_MULTI_PROCESS = 4
|
16
21
|
|
22
|
+
JSONObject = Org::Json::JSONObject
|
23
|
+
|
17
24
|
PREFERENCE_MODES = {
|
18
25
|
private: MODE_PRIVATE,
|
19
26
|
readable: MODE_WORLD_READABLE,
|
@@ -26,15 +33,29 @@ module App
|
|
26
33
|
|
27
34
|
module_function
|
28
35
|
|
36
|
+
# Serialize key/value as json then
|
37
|
+
# store that string with the settings key == json key
|
29
38
|
def []=(key, value)
|
30
39
|
settings = get_settings
|
31
40
|
editor = settings.edit
|
32
|
-
|
41
|
+
json = serialize(key,value)
|
42
|
+
editor.putString(key, json.toString)
|
33
43
|
editor.commit
|
34
44
|
end
|
35
45
|
|
36
46
|
def [](key)
|
37
|
-
get_value
|
47
|
+
json_string = get_value(key)
|
48
|
+
deserialize(key, json_string)
|
49
|
+
end
|
50
|
+
|
51
|
+
def serialize(key, value)
|
52
|
+
json = JSONObject.new
|
53
|
+
json.put(key, value)
|
54
|
+
end
|
55
|
+
|
56
|
+
def deserialize(key, json_string)
|
57
|
+
json = JSONObject.new(json_string)
|
58
|
+
json.get(key)
|
38
59
|
end
|
39
60
|
|
40
61
|
def get_value key
|
@@ -60,7 +81,7 @@ module App
|
|
60
81
|
|
61
82
|
def all
|
62
83
|
settings = get_settings
|
63
|
-
settings.getAll
|
84
|
+
settings.getAll.map { |key, value| {key.to_sym => JSONObject.new(value).get(key)} }
|
64
85
|
end
|
65
86
|
|
66
87
|
def get_settings
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: PackingPeanut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gant
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -34,7 +34,7 @@ files:
|
|
34
34
|
- README.md
|
35
35
|
- lib/PackingPeanut.rb
|
36
36
|
- lib/project/PackingPeanut.rb
|
37
|
-
homepage:
|
37
|
+
homepage: http://gantman.github.io/PackingPeanut/
|
38
38
|
licenses:
|
39
39
|
- MIT
|
40
40
|
metadata: {}
|
@@ -57,5 +57,6 @@ rubyforge_project:
|
|
57
57
|
rubygems_version: 2.4.5
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
|
-
summary: App persistent data for RubyMotion Android
|
60
|
+
summary: App persistent data for RubyMotion Android, designed to fit the API stylings
|
61
|
+
of the popular iOS Gem BubbleWrap which also supplies persistence.
|
61
62
|
test_files: []
|