deep_store 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58c4bcca38301541eb6c59de4eeb1bb5987da2fe
4
+ data.tar.gz: 0bbed2225a84b1b09732deeee0126a9e7029fc90
5
+ SHA512:
6
+ metadata.gz: 414f73c84fc194b68199fd84cd05203d1d5850588ffb716de7ef3b5638447dc0e37f2a73c91f52b2f267c29f8bfeb9a033c580188e79d18082129ee622b22999
7
+ data.tar.gz: a4c36ee301a5730e9c6450bc1064003d885661805344e948502c339ff9215bf762150f0f6c8cb2abbf86485a8db0cf10aaaaf103f63db11c0a484975db309801
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.env
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ Metrics/LineLength:
2
+ Max: 100
3
+
4
+ Metrics/MethodLength:
5
+ CountComments: false
6
+ Max: 25
7
+
8
+ Metrics/AbcSize:
9
+ Max: 25
10
+
11
+ Style/Semicolon:
12
+ AllowAsExpressionSeparator: true
13
+
14
+ Style/EachWithObject:
15
+ Enabled: false
16
+
17
+ Style/FrozenStringLiteralComment:
18
+ Enabled: false
19
+
20
+ Documentation:
21
+ Enabled: false
22
+
23
+ Style/ExtraSpacing:
24
+ Enabled: false
25
+
26
+ AllCops:
27
+ TargetRubyVersion: 2.3
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # CHANGELOG
2
+
3
+ ## [0.1.1] 2016-10-14
4
+ ### Fixed
5
+ - Gem packaging
6
+
7
+ ## [0.1.0] 2016-10-14
8
+ ### Added
9
+ - Basic Model
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at marcelo.wiermann@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deep_store.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Marcelo Wiermann
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,82 @@
1
+ # DeepStore
2
+
3
+ DeepStore is a ODM-like solution to manage S3-backed data. It provides a familiar interface to perform basic operations on files stored in S3 and facilitates their manipulation by abstracting away its intricacies. It's an opinionated but extensible library that follows "convention over configuration" and attempts to maximize developer productivity at the expense of deeper control.
4
+
5
+ ## WARNING
6
+ This is a **Beta** version. It works, but please keep that in mind and feel free to communicate any issues, suggestions or PRs ;-)
7
+
8
+ # Configuration
9
+
10
+ ```
11
+ # /config/initializers/dd.rb
12
+ DeepStore.configure do |c|
13
+ c.bucket = bucket # defaults to ENV['DEEP_DIVE_BUCKET']
14
+ c.access_key_id = access_key_id # defaults to ENV['AWS_ACCESS_KEY_ID']
15
+ c.secret_access_key = secret_access_key # defaults to ENV['AWS_SECRET_ACCESS_KEY']
16
+ c.region = region # defaults to 'us-east-1' and fallback to ENV['AWS_REGION']
17
+ end
18
+ ```
19
+
20
+ # How to Use
21
+
22
+ ```ruby
23
+ class Log
24
+ include DeepStore::Model
25
+
26
+ bucket 'awesome-bucket' # defaults to DeepStore.settings.bucket
27
+ key ':dataset/:year/:month/:day/:hour/:minute/:filename'
28
+ codec :gzip # defaults to :null
29
+
30
+ attr_accessor :year, :month, :day, :hour, :minute
31
+
32
+ attribute :dataset
33
+ attribute :timestamp
34
+ attribute :filename
35
+
36
+ validates :dataset, presence: true
37
+ validates :timestamp, presence: true
38
+ validates :filename, presence: true
39
+
40
+ # Necessary for object instantiation from a provided key
41
+ def timestamp
42
+ @timestamp ||= Time.new(year, month, day, hour, minute, '+00:00')
43
+ end
44
+
45
+ def year
46
+ timestamp.strftime('%Y')
47
+ end
48
+
49
+ def month
50
+ timestamp.strftime('%m')
51
+ end
52
+
53
+ def day
54
+ timestamp.strftime('%d')
55
+ end
56
+
57
+ def hour
58
+ timestamp.strftime('%H')
59
+ end
60
+
61
+ def minute
62
+ timestamp.strftime('%M')
63
+ end
64
+ end
65
+
66
+ log = Log.find('events/3/2016/10/10/00/00/log-1234.gz')
67
+
68
+ # Most codecs should provide a standard IO-like interface
69
+ while (chunk = log.read(8 * 1024))
70
+ puts chunk
71
+ end
72
+
73
+ log.rewind
74
+
75
+ log.each do |line|
76
+ JSON.parse(line)
77
+ end
78
+
79
+ log.write('SOME BOGUS DATA')
80
+
81
+ log.save
82
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'deep_store'
5
+ require 'irb'
6
+ require 'pry'
7
+
8
+ if File.exist?(File.expand_path('../../.env', __FILE__))
9
+ require 'dotenv'
10
+ Dotenv.load
11
+ end
12
+
13
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'deep_store/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'deep_store'
8
+ spec.version = DeepStore::VERSION
9
+ spec.authors = ['Marcelo Wiermann']
10
+ spec.email = ['marcelo.wiermann@gmail.com']
11
+
12
+ spec.summary = 'AWS S3 ODM'
13
+ spec.description = 'AWS S3 ODM'
14
+ spec.homepage = 'https://github.com/marcelow/deep_store'
15
+ spec.license = 'MIT'
16
+
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+ spec.files = `git ls-files -z`
21
+ .split("\x0")
22
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+
24
+ spec.add_runtime_dependency 'aws-sdk'
25
+ spec.add_runtime_dependency 'activemodel'
26
+ spec.add_runtime_dependency 'mime-types'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.12'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rspec-mocks'
32
+ spec.add_development_dependency 'rubocop'
33
+ spec.add_development_dependency 'pry'
34
+ spec.add_development_dependency 'dotenv'
35
+ end
@@ -0,0 +1,13 @@
1
+ module DeepStore
2
+ class AdapterFactory
3
+ def self.call(*args)
4
+ new.call(*args)
5
+ end
6
+
7
+ def call(settings)
8
+ credentials = Aws::Credentials.new(settings.access_key_id, settings.secret_access_key)
9
+
10
+ Aws::S3::Client.new(region: settings.region, credentials: credentials)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module DeepStore
2
+ class CodecFactory
3
+ def self.call(*args)
4
+ new.call(*args)
5
+ end
6
+
7
+ def call(codec_id, options = {})
8
+ case codec_id
9
+ when :gzip
10
+ Codecs::GzipCodec.new(options)
11
+ else
12
+ Codecs::NullCodec.new(options)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ module DeepStore
2
+ module Codecs
3
+ module Codec
4
+ def self.included(base)
5
+ base.class_eval do
6
+ def initialize(options = {})
7
+ @options = options
8
+ end
9
+
10
+ def decode(_)
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def encode(_)
15
+ raise NotImplementedError
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :options
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ require 'zlib'
2
+
3
+ module DeepStore
4
+ module Codecs
5
+ class GzipCodec
6
+ include Codec
7
+
8
+ CHUNK_SIZE = 1024 * 1024
9
+
10
+ def decode(stream)
11
+ decompressed_stream = Tempfile.new
12
+
13
+ Zlib::GzipReader.open(stream) do |gz|
14
+ while (chunk = gz.read(CHUNK_SIZE))
15
+ decompressed_stream.write(chunk)
16
+ end
17
+ end
18
+
19
+ stream.rewind
20
+ decompressed_stream.rewind
21
+ decompressed_stream
22
+ end
23
+
24
+ def encode(stream)
25
+ compressed_stream = Tempfile.new
26
+
27
+ Zlib::GzipWriter.open(compressed_stream.path) do |gz|
28
+ while (chunk = stream.read(CHUNK_SIZE))
29
+ gz.write(chunk)
30
+ end
31
+ end
32
+
33
+ stream.rewind
34
+ compressed_stream.rewind
35
+ compressed_stream
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ module DeepStore
2
+ module Codecs
3
+ class NullCodec
4
+ include Codec
5
+
6
+ def encode(stream)
7
+ stream
8
+ end
9
+
10
+ def decode(stream)
11
+ stream
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module DeepStore
2
+ module Codecs
3
+ autoload :Codec, File.expand_path('../codecs/codec', __FILE__)
4
+ autoload :NullCodec, File.expand_path('../codecs/null_codec', __FILE__)
5
+ autoload :GzipCodec, File.expand_path('../codecs/gzip_codec', __FILE__)
6
+ end
7
+ end
@@ -0,0 +1,54 @@
1
+ module DeepStore
2
+ class DAO
3
+ attr_reader :adapter, :bucket, :codec, :resource_class
4
+
5
+ Result = Class.new(OpenStruct)
6
+
7
+ def initialize(data = {})
8
+ @adapter = data.fetch(:adapter, DeepStore.adapter)
9
+ @bucket = data.fetch(:bucket, DeepStore.settings.bucket)
10
+ @codec = data.fetch(:codec)
11
+ end
12
+
13
+ def head(key)
14
+ adapter.head_object(bucket: bucket, key: key)
15
+ rescue Aws::S3::Errors::NoSuchKey
16
+ raise DeepStore::Errors::RecordNotFound
17
+ end
18
+
19
+ def get(key)
20
+ stream = Tempfile.new
21
+ object = adapter.get_object(bucket: bucket, key: key, response_target: stream)
22
+ Result.new(object: object, stream: codec.decode(stream))
23
+ rescue Aws::S3::Errors::NoSuchKey
24
+ raise DeepStore::Errors::RecordNotFound
25
+ end
26
+
27
+ def put(key, stream)
28
+ encoded_stream = codec.encode(stream)
29
+ adapter.put_object(bucket: bucket, key: key, body: encoded_stream)
30
+ end
31
+
32
+ def delete(key)
33
+ adapter.delete_object(bucket: bucket, key: key)
34
+ end
35
+
36
+ def expand_path(path)
37
+ keys = []
38
+ marker = nil
39
+
40
+ while (objects = remote_objects_for(path, marker)).any?
41
+ keys.concat(objects.map(&:key))
42
+ marker = objects.last.key
43
+ end
44
+
45
+ keys.uniq
46
+ end
47
+
48
+ private
49
+
50
+ def remote_objects_for(path, marker = nil)
51
+ adapter.list_objects(bucket: bucket, prefix: path, marker: marker, max_keys: 50).contents
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module DeepStore
2
+ module Errors
3
+ RecordNotFound = Class.new(StandardError)
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module DeepStore
2
+ class KeyParser
3
+ def self.call(*args)
4
+ new.call(*args)
5
+ end
6
+
7
+ def call(key, pattern)
8
+ dimensions = pattern.scan(/\:(\w+)/).flatten.map(&:to_sym)
9
+ parser = pattern.gsub(/\:(\w+)/) { |m| '(?<' + m[1..-1] + '>[a-zA-Z0-9\-_.]+)' }
10
+ match = key.match(parser)
11
+ return {} unless match
12
+
13
+ Hash[dimensions.zip(match.to_a[1..-1])]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ module DeepStore
2
+ module Model
3
+ module ContentInterface
4
+ def self.included(base)
5
+ base.class_eval do
6
+ extend Forwardable
7
+
8
+ def_delegators :content, :read, :write, :rewind, :each, :puts, :close
9
+
10
+ def reload
11
+ @content = nil
12
+ end
13
+
14
+ def content
15
+ return @content if @content
16
+ self.content = persisted? ? __repository__.get(key).stream : Tempfile.new
17
+ end
18
+
19
+ def content=(stream)
20
+ ObjectSpace.define_finalizer(self, -> { stream.close })
21
+ @content = stream
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ module DeepStore
2
+ module Model
3
+ module DSL
4
+ def attribute(name, options = {})
5
+ attr_accessor name
6
+ schema[name] = options
7
+ end
8
+
9
+ def codec(codec_id, options = {})
10
+ settings[:codec] = CodecFactory.call(codec_id, options: options)
11
+ end
12
+
13
+ def bucket(name)
14
+ settings[:bucket] = name
15
+ end
16
+
17
+ def key(pattern)
18
+ settings[:key] = pattern
19
+ end
20
+
21
+ def schema
22
+ settings[:schema] ||= {}
23
+ end
24
+
25
+ def settings
26
+ @settings ||= { codec: CodecFactory.call(id: :null, options: {}) }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ module DeepStore
2
+ module Model
3
+ class KeyFactory
4
+ def self.call(*args)
5
+ new.call(*args)
6
+ end
7
+
8
+ def call(resource, pattern)
9
+ @resource = resource
10
+ key = pattern.gsub(/\:(\w+)/) { |m| process_match(m) }
11
+ key
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :resource
17
+
18
+ def process_match(match)
19
+ attribute = match[1..-1]
20
+ return unless resource.respond_to?(attribute)
21
+
22
+ value = resource.send(attribute)
23
+ return match unless value
24
+
25
+ value
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,48 @@
1
+ module DeepStore
2
+ module Model
3
+ module Persistence
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+
7
+ base.class_eval do
8
+ attr_accessor :persisted
9
+
10
+ def persisted?
11
+ return(@persisted) if defined?(@persisted)
12
+ @persisted = false
13
+ end
14
+
15
+ def save
16
+ return unless __repository__.save(self)
17
+ @persisted = true
18
+ end
19
+
20
+ def destroy
21
+ __repository__.destroy(key)
22
+ @persisted = true
23
+ end
24
+
25
+ def key
26
+ KeyFactory.call(self, __settings__.fetch(:key))
27
+ end
28
+ end
29
+ end
30
+
31
+ module ClassMethods
32
+ def create(data = {})
33
+ new(data).save
34
+ end
35
+
36
+ def destroy(key)
37
+ repository.destroy(key)
38
+ end
39
+
40
+ def repository
41
+ @repository ||= Repository.new(bucket: settings[:bucket],
42
+ codec: settings[:codec],
43
+ resource_class: self)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ module DeepStore
2
+ module Model
3
+ autoload :Persistence, File.expand_path('../model/persistence', __FILE__)
4
+ autoload :KeyFactory, File.expand_path('../model/key_factory', __FILE__)
5
+ autoload :ContentInterface, File.expand_path('../model/content_interface', __FILE__)
6
+ autoload :DSL, File.expand_path('../model/dsl', __FILE__)
7
+
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+
11
+ base.class_eval do
12
+ extend DeepStore::Model::DSL
13
+ include ActiveModel::Serialization
14
+ include ActiveModel::Validations
15
+ include Persistence
16
+ include ContentInterface
17
+
18
+ def initialize(data = {})
19
+ data.each { |k, v| send("#{k}=", v) }
20
+ end
21
+
22
+ def attributes
23
+ Hash[__schema__.keys.map { |k| [k, send(k)] }]
24
+ end
25
+
26
+ private
27
+
28
+ def __repository__
29
+ self.class.repository
30
+ end
31
+
32
+ def __schema__
33
+ self.class.schema
34
+ end
35
+
36
+ def __settings__
37
+ self.class.settings
38
+ end
39
+ end
40
+ end
41
+
42
+ module ClassMethods
43
+ extend Forwardable
44
+
45
+ def_delegators :repository, :find, :where, :destroy
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,12 @@
1
+ module DeepStore
2
+ module Operations
3
+ class DestroyOperation
4
+ include Operation
5
+
6
+ def result
7
+ dao.delete(data[:key])
8
+ true
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module DeepStore
2
+ module Operations
3
+ class FindQuery
4
+ include Operation
5
+
6
+ def result
7
+ return unless dao.head(data[:key])
8
+ attributes = KeyParser.call(data[:key], resource_class.settings[:key])
9
+ resource = resource_class.new(attributes)
10
+ resource.persisted = true
11
+ resource
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module DeepStore
2
+ module Operations
3
+ module Operation
4
+ def self.included(base)
5
+ base.class_eval do
6
+ attr_reader :dao, :resource_class, :data, :options
7
+
8
+ def initialize(dao, resource_class, data = {}, options = {})
9
+ @dao = dao
10
+ @resource_class = resource_class
11
+ @data = data
12
+ @options = options
13
+ end
14
+
15
+ def result
16
+ raise NotImplementedError
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module DeepStore
2
+ module Operations
3
+ class SaveOperation
4
+ include Operation
5
+
6
+ def result
7
+ resource = data[:resource]
8
+ return false unless resource.valid?
9
+
10
+ resource.rewind
11
+ dao.put(resource.key, resource.content)
12
+ true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module DeepStore
2
+ module Operations
3
+ class WhereQuery
4
+ include Operation
5
+
6
+ def result
7
+ query = data[:query]
8
+
9
+ dao.expand_path(query).map do |object|
10
+ attributes = KeyParser.call(object, resource_class.settings[:key])
11
+ resource = resource_class.new(attributes)
12
+ resource.persisted = true
13
+ resource
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module DeepStore
2
+ module Operations
3
+ autoload :Operation, File.expand_path('../operations/operation', __FILE__)
4
+ autoload :FindQuery, File.expand_path('../operations/find_query', __FILE__)
5
+ autoload :WhereQuery, File.expand_path('../operations/where_query', __FILE__)
6
+ autoload :SaveOperation, File.expand_path('../operations/save_operation', __FILE__)
7
+ autoload :DestroyOperation, File.expand_path('../operations/destroy_operation', __FILE__)
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ module DeepStore
2
+ class Repository
3
+ extend Forwardable
4
+
5
+ attr_accessor :adapter
6
+ attr_reader :bucket, :codec, :resource_class, :dao
7
+
8
+ def_delegators :dao, :head, :get, :put, :delete
9
+
10
+ def initialize(data = {})
11
+ @data = data
12
+ @adapter = data.fetch(:adapter, DeepStore.adapter)
13
+ @bucket = data.fetch(:bucket, DeepStore.settings.bucket)
14
+ @codec = data.fetch(:codec)
15
+ @resource_class = data.fetch(:resource_class)
16
+ @dao = DAO.new(adapter: @adapter, bucket: @bucket, codec: @codec)
17
+ end
18
+
19
+ def find(key)
20
+ Operations::FindQuery.new(dao, resource_class, key: key).result
21
+ end
22
+
23
+ def where(query = {})
24
+ Operations::WhereQuery.new(dao, resource_class, query: query).result
25
+ end
26
+
27
+ def save(resource)
28
+ Operations::SaveOperation.new(dao, resource_class, resource: resource).result
29
+ end
30
+
31
+ def destroy(key)
32
+ Operations::DestroyOperation.new(dao, resource_class, key: key).result
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module DeepStore
2
+ class Settings < OpenStruct
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module DeepStore
2
+ VERSION = '0.1.1'.freeze
3
+ end
data/lib/deep_store.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'deep_store/version'
2
+ require 'forwardable'
3
+ require 'ostruct'
4
+ require 'aws-sdk'
5
+ require 'active_model'
6
+ require 'mime/types'
7
+
8
+ module DeepStore
9
+ autoload :Settings, 'deep_store/settings'
10
+ autoload :AdapterFactory, 'deep_store/adapter_factory'
11
+ autoload :DAO, 'deep_store/dao'
12
+ autoload :Repository, 'deep_store/repository'
13
+ autoload :CodecFactory, 'deep_store/codec_factory'
14
+ autoload :Model, 'deep_store/model'
15
+ autoload :Query, 'deep_store/query'
16
+ autoload :Codecs, 'deep_store/codecs'
17
+ autoload :Operations, 'deep_store/operations'
18
+ autoload :KeyParser, 'deep_store/key_parser'
19
+ autoload :Errors, 'deep_store/errors'
20
+
21
+ def self.adapter
22
+ @adapter ||= AdapterFactory.call(settings)
23
+ end
24
+
25
+ def self.configure(&block)
26
+ block.call(settings)
27
+ end
28
+
29
+ def self.settings
30
+ @settings ||= Settings.new(bucket: ENV['DEEP_DIVE_BUCKET'],
31
+ region: ENV.fetch('AWS_REGION', 'us-east-1'),
32
+ access_key_id: ENV['AWS_ACCESS_KEY_ID'],
33
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'])
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deep_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Wiermann
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mime-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-mocks
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: dotenv
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: AWS S3 ODM
154
+ email:
155
+ - marcelo.wiermann@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".rubocop.yml"
163
+ - ".travis.yml"
164
+ - CHANGELOG.md
165
+ - CODE_OF_CONDUCT.md
166
+ - Gemfile
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - bin/console
171
+ - bin/setup
172
+ - deep_store.gemspec
173
+ - lib/deep_store.rb
174
+ - lib/deep_store/adapter_factory.rb
175
+ - lib/deep_store/codec_factory.rb
176
+ - lib/deep_store/codecs.rb
177
+ - lib/deep_store/codecs/codec.rb
178
+ - lib/deep_store/codecs/gzip_codec.rb
179
+ - lib/deep_store/codecs/null_codec.rb
180
+ - lib/deep_store/dao.rb
181
+ - lib/deep_store/errors.rb
182
+ - lib/deep_store/key_parser.rb
183
+ - lib/deep_store/model.rb
184
+ - lib/deep_store/model/content_interface.rb
185
+ - lib/deep_store/model/dsl.rb
186
+ - lib/deep_store/model/key_factory.rb
187
+ - lib/deep_store/model/persistence.rb
188
+ - lib/deep_store/operations.rb
189
+ - lib/deep_store/operations/destroy_operation.rb
190
+ - lib/deep_store/operations/find_query.rb
191
+ - lib/deep_store/operations/operation.rb
192
+ - lib/deep_store/operations/save_operation.rb
193
+ - lib/deep_store/operations/where_query.rb
194
+ - lib/deep_store/repository.rb
195
+ - lib/deep_store/settings.rb
196
+ - lib/deep_store/version.rb
197
+ homepage: https://github.com/marcelow/deep_store
198
+ licenses:
199
+ - MIT
200
+ metadata: {}
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubyforge_project:
217
+ rubygems_version: 2.5.1
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: AWS S3 ODM
221
+ test_files: []