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 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
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sunstore.gemspec
4
+ gemspec
5
+
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
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ rescue LoadError
10
+ # no rspec available
11
+ end
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
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,16 @@
1
+ class Sunstore::Handler::JSON
2
+
3
+ require 'JSON'
4
+
5
+ def serialize(h)
6
+ h.to_json
7
+ end
8
+
9
+ def deserialize(txt)
10
+ JSON.parse(txt)
11
+ end
12
+
13
+ def type
14
+ "json"
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ class Sunstore::Handler::YAML
2
+ require 'Psych'
3
+
4
+ def serialize(h)
5
+ h.to_yaml
6
+ end
7
+
8
+ def deserialize(txt)
9
+ Psych.load(txt)
10
+ end
11
+
12
+ def type
13
+ "yaml"
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
@@ -0,0 +1,3 @@
1
+ module Sunstore
2
+ VERSION = "0.1.1"
3
+ 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
@@ -0,0 +1,14 @@
1
+ ---
2
+ x:
3
+ :x: 10
4
+ :y: test
5
+ y:
6
+ - test
7
+ - 22.4
8
+ - :x:
9
+ - 1
10
+ - 2
11
+ - 3
12
+ :y:
13
+ :f: 20
14
+ :z: test
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: []