PackingPeanut 0.0.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.
- checksums.yaml +7 -0
- data/README.md +52 -0
- data/lib/PackingPeanut.rb +12 -0
- data/lib/project/PackingPeanut.rb +84 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6d208f0c0b6fbf825d0f2d38726f34d74186934
|
4
|
+
data.tar.gz: c9a3ea3e898985b0f68ddbe33a87ed9b65a1a9c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 09cf80f1b1a521e94a1d43dc507b4ad3235ad3e5761c17343c60691072e372379df46383138c4634b58e8c759f8a2c6e6171d8d43b6ba21e5e0ec02d5652c31e
|
7
|
+
data.tar.gz: 96de1ad83d856a6f2780b4c9bbd33de9c47bc0652ac567e3c77d5b211cfc1f8cf5539a82d181e481e921e4a4e5d37432d6ed4c13b5c889d7031d57251071c1ef
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# PackingPeanut
|
2
|
+
|
3
|
+
iOS has [BubbleWrap](https://github.com/rubymotion/BubbleWrap) for App Persistence : Android has **PackingPeanut**
|
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.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'PackingPeanut'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install PackingPeanut
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Example Usage from REPL
|
24
|
+
```
|
25
|
+
# PP automatically has context if the module is included but in this case
|
26
|
+
# First we need to set the context when in REPL,
|
27
|
+
$ App::Persistence.context = self
|
28
|
+
=> #<MainActivity:0x1d20058e>
|
29
|
+
$ App::Persistence['dinner'] = "nachos"
|
30
|
+
=> true # This differs from Bubblewrap.... boolean on success for save (more informative)
|
31
|
+
$ App::Persistence['dinner']
|
32
|
+
=> "nachos"
|
33
|
+
$ App::Persistence['lunch'] = "tacos"
|
34
|
+
$ App::Persistence.all
|
35
|
+
=> {"dinner"=>"nachos", "lunch"=>"tacos"}
|
36
|
+
$ App::Persistence.storage_file = "some_new_file"
|
37
|
+
=> "some_new_file"
|
38
|
+
$ App::Persistence.preference_mode = :world_readable
|
39
|
+
=> :world_redable
|
40
|
+
$ App::Persistence['dinner']
|
41
|
+
=> "" # empty because we're now in a new storage file.
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Ponder life... for at least like... 5 minutes
|
52
|
+
6. Create new Pull Request
|
@@ -0,0 +1,12 @@
|
|
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.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
|
10
|
+
# Required for android as off 4/11/2015
|
11
|
+
app.files.flatten!
|
12
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
# Potential fixes for type specifics
|
3
|
+
# Super fix #1 -> Serialize it: http://stackoverflow.com/questions/7057845/save-arraylist-to-sharedpreferences
|
4
|
+
# ObjectSerializer: https://github.com/apache/pig/blob/89c2e8e76c68d0d0abe6a36b4e08ddc56979796f/src/org/apache/pig/impl/util/ObjectSerializer.java
|
5
|
+
# Super fix #2 -> Store depending on the class and retrieve with either
|
6
|
+
# A: Failover defaults calling methods
|
7
|
+
# B: Grab ALL data, and use that hash
|
8
|
+
|
9
|
+
module App
|
10
|
+
module Persistence
|
11
|
+
|
12
|
+
MODE_PRIVATE = 0
|
13
|
+
MODE_WORLD_READABLE = 1
|
14
|
+
MODE_WORLD_WRITEABLE = 2
|
15
|
+
MODE_MULTI_PROCESS = 4
|
16
|
+
|
17
|
+
PREFERENCE_MODES = {
|
18
|
+
private: MODE_PRIVATE,
|
19
|
+
readable: MODE_WORLD_READABLE,
|
20
|
+
world_readable: MODE_WORLD_READABLE,
|
21
|
+
writable: MODE_WORLD_WRITEABLE,
|
22
|
+
world_writable: MODE_WORLD_WRITEABLE,
|
23
|
+
multi: MODE_MULTI_PROCESS,
|
24
|
+
multi_process: MODE_MULTI_PROCESS
|
25
|
+
}
|
26
|
+
|
27
|
+
module_function
|
28
|
+
|
29
|
+
def []=(key, value)
|
30
|
+
settings = get_settings
|
31
|
+
editor = settings.edit
|
32
|
+
editor.putString(key, value)
|
33
|
+
editor.commit
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](key)
|
37
|
+
get_value key
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_value key
|
41
|
+
settings = get_settings
|
42
|
+
value = settings.getString(key,nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
def storage_file=(value)
|
46
|
+
@persistence_storage_file = value
|
47
|
+
end
|
48
|
+
|
49
|
+
def storage_file
|
50
|
+
@persistence_storage_file ||= "default_persistence_file"
|
51
|
+
end
|
52
|
+
|
53
|
+
def preference_mode=(value)
|
54
|
+
@current_preference_mode = PREFERENCE_MODES[value] || value
|
55
|
+
end
|
56
|
+
|
57
|
+
def preference_mode
|
58
|
+
@current_preference_mode ||= MODE_PRIVATE
|
59
|
+
end
|
60
|
+
|
61
|
+
def all
|
62
|
+
settings = get_settings
|
63
|
+
settings.getAll
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_settings
|
67
|
+
current_context.getSharedPreferences(storage_file, preference_mode)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Allows us to use this from anywhere by setting the context
|
71
|
+
# Useful when you want to access this module from the REPL
|
72
|
+
def current_context
|
73
|
+
@context || getApplicationContext
|
74
|
+
end
|
75
|
+
|
76
|
+
# attr_accessor is not supported for modules in RMAndroid... yet.
|
77
|
+
def context= supplied_context
|
78
|
+
@context = supplied_context
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
PP = App
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: PackingPeanut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gant
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-12 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: App persistent data for RubyMotion Android
|
28
|
+
email:
|
29
|
+
- GantMan@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/PackingPeanut.rb
|
36
|
+
- lib/project/PackingPeanut.rb
|
37
|
+
homepage: https://github.com/GantMan/PackingPeanut
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.4.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: App persistent data for RubyMotion Android
|
61
|
+
test_files: []
|