omnistore 0.0.2

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/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omnistore.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 arukoh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # OmniStore
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'omnistore'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install omnistore
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "bundler/gem_tasks"
5
+ require 'rspec/core/rake_task'
6
+ require "omnistore/version"
7
+
8
+ task :default => :spec
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
data/data/.gitkeep ADDED
File without changes
data/lib/omnistore.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'logger'
2
+ require 'active_support/inflector'
3
+ require "omnistore/version"
4
+ require 'omnistore/config'
5
+ require 'omnistore/errors'
6
+ require 'omnistore/storage'
7
+
8
+ module OmniStore
9
+ extend self
10
+
11
+ def configure
12
+ block_given? ? yield(OmniStore::Config) : OmniStore::Config
13
+ OmniStore::Storage.remount!
14
+ end
15
+ alias :config :configure
16
+
17
+ def logger
18
+ OmniStore::Config.logger
19
+ end
20
+
21
+ end
@@ -0,0 +1,32 @@
1
+ require 'omnistore/config/option'
2
+
3
+ module OmniStore
4
+ module Config
5
+ extend self
6
+ extend Options
7
+
8
+ option :logger, :default => defined?(Rails)
9
+ option :storage, :default => 'local'
10
+ option :mountpoint, :default => '/tmp/data'
11
+ option :access_key
12
+ option :secret_key
13
+ option :endpoint
14
+ option :proxy_uri
15
+
16
+ def default_logger
17
+ defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new($stdout)
18
+ end
19
+
20
+ def logger
21
+ @logger ||= default_logger
22
+ end
23
+
24
+ def logger=(logger)
25
+ @logger = case logger
26
+ when false, nil then nil
27
+ when true then default_logger
28
+ else logger.respond_to?(:info) ? logger : @logger
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ module OmniStore
2
+ module Config
3
+ module Options
4
+
5
+ def defaults
6
+ @defaults ||= {}
7
+ end
8
+
9
+ def option(name, options = {})
10
+ defaults[name] = settings[name] = options[:default]
11
+
12
+ class_eval <<-RUBY
13
+ def #{name}
14
+ settings[#{name.inspect}]
15
+ end
16
+
17
+ def #{name}=(value)
18
+ settings[#{name.inspect}] = value
19
+ end
20
+
21
+ def #{name}?
22
+ #{name}
23
+ end
24
+
25
+ def reset_#{name}
26
+ settings[#{name.inspect}] = defaults[#{name.inspect}]
27
+ end
28
+ RUBY
29
+ end
30
+
31
+ def reset
32
+ settings.replace(defaults)
33
+ end
34
+
35
+ def settings
36
+ @settings ||= {}
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ module OmniStore
2
+ module Errors
3
+ class Error < StandardError; end
4
+
5
+ class InvalidMountpoint < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module OmniStore
2
+ module Storage
3
+ extend self
4
+
5
+ def storage
6
+ remount! unless @storage
7
+ @storage
8
+ end
9
+
10
+ def remount!
11
+ unless OmniStore::Storage.const_defined?(OmniStore::Config.storage.camelcase)
12
+ require "omnistore/storage/#{OmniStore::Config.storage}"
13
+ end
14
+ @storage = OmniStore::Storage.const_get(OmniStore::Config.storage.camelcase)
15
+ @storage.mount!
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module OmniStore
2
+ module Storage
3
+ module Local
4
+ extend self
5
+
6
+ @@mountpoint = nil
7
+
8
+ def mount!
9
+ mountpoint = OmniStore::Config.mountpoint.to_s
10
+ raise OmniStore::Errors::InvalidMountpoint unless File.exist?(mountpoint) && File.directory?(mountpoint)
11
+ @@mountpoint = mountpoint
12
+ end
13
+
14
+ def exist?(path)
15
+ File.exist?(File.join(@@mountpoint, path))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ require 'aws-sdk'
2
+
3
+ module OmniStore
4
+ module Storage
5
+ module S3
6
+ extend self
7
+
8
+ @@bucket = nil
9
+
10
+ def mount!
11
+ bucket = AWS::S3.new(options).buckets[OmniStore::Config.mountpoint]
12
+ raise OmniStore::Errors::InvalidMountpoint unless bucket.exists?
13
+ @@bucket = bucket
14
+ end
15
+
16
+ def exist?(path)
17
+ @@bucket.objects[path].exists?
18
+ end
19
+
20
+ def write(path, options_or_data = nil, options = nil)
21
+ @@bucket.objects[path].write(options_or_data, options)
22
+ end
23
+
24
+ private
25
+
26
+ def options
27
+ opts = {}
28
+ opts[:access_key_id] = OmniStore::Config.access_key if OmniStore::Config.access_key
29
+ opts[:secret_access_key] = OmniStore::Config.secret_key if OmniStore::Config.secret_key
30
+ opts[:s3_endpoint] = OmniStore::Config.endpoint if OmniStore::Config.endpoint
31
+ opts[:proxy_uri] = OmniStore::Config.proxy_uri if OmniStore::Config.proxy_uri
32
+ opts
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module OmniStore
2
+ VERSION = "0.0.2"
3
+ end
data/omnistore.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omnistore/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["arukoh"]
6
+ gem.email = ["arukoh10@gmail.com"]
7
+ gem.description = %q{Providers a single point of entry for storage}
8
+ gem.summary = %q{Providers a single point of entry for storage}
9
+ gem.homepage = "https://github.com/arukoh/omnistore"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "omnistore"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniStore::VERSION
17
+
18
+ gem.add_dependency "aws-sdk", ">=1.6.0"
19
+ gem.add_dependency "activesupport"
20
+
21
+ gem.add_development_dependency "rake", ">= 0.8.7"
22
+ gem.add_development_dependency "rspec", ">= 2.4.0"
23
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniStore::Config do
4
+
5
+ it 'should return logger' do
6
+ OmniStore::Config.logger = true
7
+ OmniStore::Config.logger.class.should == ::Logger
8
+ end
9
+
10
+ it 'should return logger when set false' do
11
+ OmniStore::Config.logger = false
12
+ OmniStore::Config.logger.class.should == ::Logger
13
+ end
14
+
15
+ it 'should return logger when set nil' do
16
+ OmniStore::Config.logger = nil
17
+ OmniStore::Config.logger.class.should == ::Logger
18
+ end
19
+
20
+ it 'should return Rails logger for Rails apps' do
21
+ class Rails; end
22
+ class MyLogger < Logger; end
23
+ Rails.stub(:logger) { MyLogger.new($stdout) }
24
+ OmniStore::Config.logger = true
25
+ OmniStore::Config.logger.class.should == ::MyLogger
26
+ end
27
+
28
+ it 'should return storage' do
29
+ OmniStore::Config.storage = 'local'
30
+ OmniStore::Config.storage.should == 'local'
31
+ end
32
+
33
+ it 'should return mountpoint' do
34
+ OmniStore::Config.mountpoint = '/tmp/data'
35
+ OmniStore::Config.mountpoint.should == '/tmp/data'
36
+ end
37
+
38
+ it 'should return access_key' do
39
+ OmniStore::Config.access_key = 'key'
40
+ OmniStore::Config.access_key.should == 'key'
41
+ end
42
+
43
+ it 'should return secret_key' do
44
+ OmniStore::Config.secret_key = 'secret'
45
+ OmniStore::Config.secret_key.should == 'secret'
46
+ end
47
+
48
+ it 'should return endpoint' do
49
+ OmniStore::Config.endpoint = 'endpoint'
50
+ OmniStore::Config.endpoint.should == 'endpoint'
51
+ end
52
+
53
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe OmniStore::Storage::Local do
5
+
6
+ it 'should mount' do
7
+ OmniStore::Storage::Local.mount!.should_not be_nil
8
+ end
9
+
10
+ it 'should raise error when mount fails' do
11
+ OmniStore::Config.mountpoint = nil
12
+ lambda { OmniStore::Storage::Local.mount! }.should raise_error(OmniStore::Errors::InvalidMountpoint)
13
+ end
14
+
15
+ it 'should exist' do
16
+ path = 'test.txt'
17
+ FileUtils.touch(File.join(OmniStore::Config.mountpoint, path))
18
+ OmniStore::Storage::Local.exist?(path).should be_true
19
+ OmniStore::Storage::Local.exist?(path+'.bk').should be_false
20
+ end
21
+
22
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe "OmniStore::Storage::S3" do
5
+
6
+ before(:each) do
7
+ OmniStore::Config.storage = 's3'
8
+ OmniStore::Config.mountpoint = ENV['AWS_BUCKET']
9
+ OmniStore::Storage.remount!
10
+ end
11
+
12
+ it 'should mount' do
13
+ OmniStore::Storage::S3.mount!.should_not be_nil
14
+ end
15
+
16
+ it 'should raise error when mount fails' do
17
+ OmniStore::Config.mountpoint = "a"
18
+ lambda { OmniStore::Storage::S3.mount! }.should raise_error(OmniStore::Errors::InvalidMountpoint)
19
+ end
20
+
21
+ it 'should exist' do
22
+ path = 'test.txt'
23
+ OmniStore::Storage::S3.write(path, '')
24
+ OmniStore::Storage::S3.exist?(path).should be_true
25
+ OmniStore::Storage::S3.exist?(path+'.bk').should be_false
26
+ end
27
+
28
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniStore::Storage do
4
+
5
+ it 'should return storage' do
6
+ OmniStore::Config.storage = 'local'
7
+ OmniStore::Storage.remount!
8
+ OmniStore::Storage.storage.should == OmniStore::Storage::Local
9
+ end
10
+
11
+ it 'should return storage for s3' do
12
+ OmniStore::Config.storage = 's3'
13
+ OmniStore::Storage.remount!
14
+ OmniStore::Storage.storage.should == OmniStore::Storage::S3
15
+ end
16
+
17
+ it 'should return storage when remount' do
18
+ OmniStore::Storage.remount!
19
+ OmniStore::Storage.storage.should_not be_nil
20
+ end
21
+
22
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniStore do
4
+
5
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'aws-sdk'
7
+ require 'omnistore'
8
+
9
+ MOUNTPOINT = File.join(File.dirname(__FILE__), '/../data')
10
+ OmniStore.configure do |config|
11
+ config.storage = 'local'
12
+ config.mountpoint = MOUNTPOINT
13
+ end
14
+
15
+ RSpec.configure do |config|
16
+
17
+ config.before(:each) do
18
+ end
19
+
20
+ config.after(:each) do
21
+ OmniStore::Config.reset_logger
22
+ OmniStore::Config.storage = 'local'
23
+ OmniStore::Config.mountpoint = MOUNTPOINT
24
+ OmniStore::Config.reset_access_key
25
+ OmniStore::Config.reset_secret_key
26
+ OmniStore::Config.reset_endpoint
27
+ OmniStore::Config.reset_proxy_uri
28
+ OmniStore.logger.level = Logger::FATAL
29
+ FileUtils.rm_rf(Dir.glob(File.join(MOUNTPOINT, '*')))
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omnistore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - arukoh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-sdk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.7
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.7
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.4.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.4.0
78
+ description: Providers a single point of entry for storage
79
+ email:
80
+ - arukoh10@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - Gemfile
88
+ - LICENSE
89
+ - README.md
90
+ - Rakefile
91
+ - data/.gitkeep
92
+ - lib/omnistore.rb
93
+ - lib/omnistore/config.rb
94
+ - lib/omnistore/config/option.rb
95
+ - lib/omnistore/errors.rb
96
+ - lib/omnistore/storage.rb
97
+ - lib/omnistore/storage/local.rb
98
+ - lib/omnistore/storage/s3.rb
99
+ - lib/omnistore/version.rb
100
+ - omnistore.gemspec
101
+ - spec/omnistore/config_spec.rb
102
+ - spec/omnistore/storage/local_spec.rb
103
+ - spec/omnistore/storage/s3_spec.rb
104
+ - spec/omnistore/storage_spec.rb
105
+ - spec/omnistore_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/arukoh/omnistore
108
+ licenses: []
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ hash: 671942063
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
129
+ - 0
130
+ hash: 671942063
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.24
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Providers a single point of entry for storage
137
+ test_files:
138
+ - spec/omnistore/config_spec.rb
139
+ - spec/omnistore/storage/local_spec.rb
140
+ - spec/omnistore/storage/s3_spec.rb
141
+ - spec/omnistore/storage_spec.rb
142
+ - spec/omnistore_spec.rb
143
+ - spec/spec_helper.rb