sunstore 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/sunstore.rb +30 -0
- data/lib/sunstore/handler.rb +15 -0
- data/lib/sunstore/handlers/json.rb +16 -0
- data/lib/sunstore/handlers/yaml.rb +15 -0
- data/lib/sunstore/store.rb +80 -0
- data/lib/sunstore/version.rb +3 -0
- data/sunstore.gemspec +34 -0
- data/sunstore.json +1 -0
- data/sunstore.yaml +14 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 59db6ff883ba656d379fd8324c7fc07b65d20e72
|
4
|
+
data.tar.gz: 5008ae2b94ac5e06ed9ced93942a76b0f0711910
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06ab62f5cdec528ce9ff2e458d812d4cc8fc4d6a1fec9c1a397f432cebea2c13765401ad743897d27a08d5dc703360e6edc13199d26587e41f5ae63f12af9873
|
7
|
+
data.tar.gz: 8d0a5b79632060ec385544b0092b21afd2325ceae9c1e85e5febed849b3a005eb0a733409d1adc301d89077bceb24953fe92545e8bb66dc2e0444b102d0dd10d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 etcetc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Sunstore
|
2
|
+
|
3
|
+
SunStore is a Simple UNscalable storage mechanism for saving very simple key value pairs like preferences, config parameters, etc. It's really just a wrapper for JSON or YAML.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'sunstore'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install sunstore
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
The simplest way is to say:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Sustore.put("myKey",someSerializableObject)
|
28
|
+
```
|
29
|
+
|
30
|
+
and to later retrieve it as
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
Sunstore.get("myKey")
|
34
|
+
```
|
35
|
+
|
36
|
+
## Configuration
|
37
|
+
|
38
|
+
There are a couple of configuration parameters invoked via the config message *prior* to using:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Sunstore.config(params)
|
42
|
+
```
|
43
|
+
|
44
|
+
where the params can be:
|
45
|
+
|
46
|
+
:format: :json or :yaml (default)
|
47
|
+
:basename: the basename for the storage file (sunstore by default)
|
48
|
+
:basedir: the default location to put the file (Rails/tmp if used in Rails context, else current working directory)
|
49
|
+
|
50
|
+
## Development
|
51
|
+
|
52
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
53
|
+
|
54
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/etcetc/sunstore.
|
59
|
+
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
64
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sunstore"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/sunstore.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "sunstore/version"
|
2
|
+
require "sunstore/store"
|
3
|
+
|
4
|
+
module Sunstore
|
5
|
+
|
6
|
+
def self.config(params)
|
7
|
+
Store.instance.config(params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get(key)
|
11
|
+
Store.instance.get(key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.put(key,value)
|
15
|
+
Store.instance.put(key,value)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.delete(key)
|
19
|
+
Store.instance.delete(key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.keys
|
23
|
+
Store.instance.keys
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.clear
|
27
|
+
Store.instance.clear
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module Sunstore::Handler
|
3
|
+
|
4
|
+
require_relative 'handlers/json'
|
5
|
+
require_relative 'handlers/yaml'
|
6
|
+
|
7
|
+
def self.for(protocol)
|
8
|
+
case protocol
|
9
|
+
when :yaml then YAML.new
|
10
|
+
when :json then JSON.new
|
11
|
+
else
|
12
|
+
raise "Only :yaml and :json currently supported"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative 'handler'
|
2
|
+
|
3
|
+
class Sunstore::Store
|
4
|
+
|
5
|
+
@@instance = nil
|
6
|
+
|
7
|
+
attr_reader :format, :basename, :handler, :store_file
|
8
|
+
|
9
|
+
def self.instance
|
10
|
+
@@instance ||= new
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.reset
|
14
|
+
@@instance = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
config
|
19
|
+
end
|
20
|
+
|
21
|
+
def config(params={})
|
22
|
+
@format = [:yaml,:json,nil].include?(params[:format]) ? params[:format] || :yaml : raise("Only yaml and json currently supported")
|
23
|
+
@basename = params[:basename] || "sunstore"
|
24
|
+
@basedir = params[:basedir] || (defined?(Rails) ? Rails.root.to_s : Dir.getwd)
|
25
|
+
create_dir_structure(@basedir)
|
26
|
+
@handler = Sunstore::Handler.for(format)
|
27
|
+
@store_file = File.join(@basedir,"#{@basename}.#{@handler.type}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(key)
|
31
|
+
data[key]
|
32
|
+
end
|
33
|
+
|
34
|
+
def put(key,value)
|
35
|
+
data[key] = value
|
36
|
+
save_data
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(key)
|
40
|
+
data.delete(key)
|
41
|
+
save_data
|
42
|
+
end
|
43
|
+
|
44
|
+
def keys
|
45
|
+
data.keys
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear
|
49
|
+
data.clear
|
50
|
+
save_data
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def save_data
|
56
|
+
File.open(store_file,"w") do |f|
|
57
|
+
f.write @handler.serialize(@data)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def data
|
62
|
+
unless @data
|
63
|
+
if File.exist?(store_file)
|
64
|
+
@data = @handler.deserialize(File.read(store_file)) || {}
|
65
|
+
else
|
66
|
+
@data = {}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@data
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_dir_structure(target_dir)
|
73
|
+
curdir = ''
|
74
|
+
target_dir.split('/').each do |dir|
|
75
|
+
curdir = File.join(curdir,dir)
|
76
|
+
Dir.exist?(curdir) or Dir.mkdir(curdir)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/sunstore.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sunstore/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sunstore"
|
8
|
+
spec.version = Sunstore::VERSION
|
9
|
+
spec.authors = ["etcetc"]
|
10
|
+
spec.email = ["ff@onebeat.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Very simple, unscalable model for saving key-value stores, for exmaple, preferences}
|
13
|
+
spec.description = %q{Sometimes you just want to quickly save something and retrieve it. This is a lightweight gem for doing so using YAML or JSON serialization}
|
14
|
+
spec.homepage = "https://github.com/etcetc/sunstore.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
|
34
|
+
end
|
data/sunstore.json
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"x":{"x":10,"y":"test"},"y":["test",22.4,{"x":[1,2,3],"y":{"f":20,"z":"test"}}]}
|
data/sunstore.yaml
ADDED
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sunstore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- etcetc
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Sometimes you just want to quickly save something and retrieve it. This
|
56
|
+
is a lightweight gem for doing so using YAML or JSON serialization
|
57
|
+
email:
|
58
|
+
- ff@onebeat.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/sunstore.rb
|
72
|
+
- lib/sunstore/handler.rb
|
73
|
+
- lib/sunstore/handlers/json.rb
|
74
|
+
- lib/sunstore/handlers/yaml.rb
|
75
|
+
- lib/sunstore/store.rb
|
76
|
+
- lib/sunstore/version.rb
|
77
|
+
- sunstore.gemspec
|
78
|
+
- sunstore.json
|
79
|
+
- sunstore.yaml
|
80
|
+
homepage: https://github.com/etcetc/sunstore.git
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.0.14
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Very simple, unscalable model for saving key-value stores, for exmaple, preferences
|
104
|
+
test_files: []
|