condo-couchbase 2.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b347cc0c0a2a2d934ddf7d33e4cf3b7d6ccb6b2a
4
+ data.tar.gz: 29f1b0b523bedbeb893c5cb145166b883f0d8a1a
5
+ SHA512:
6
+ metadata.gz: 6687f5520477e5e1fac3ff0dca2c234bb9d096fc36a7b7f827be9307d765af56836fb08a0ae1dd21bb38253774c306d3d87b9af4961366e9e45217de6eebeb93
7
+ data.tar.gz: 84c3bb485fe31f640acf87ca9b5695fb0ef2f4b395440a7d49f8b37f5a3b14c59e01d800afae0767d22fb059be3fa50baeeca80e4c6183bbf498e929c00dca3e
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,4 @@
1
+ h1. Condo Couchbase Backend
2
+
3
+ Include in your gem file: @gem 'condo-couchbase'@
4
+ Assumes you are using "couchbase-model":https://github.com/couchbase/couchbase-ruby-model/
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'CondoActiveRecord'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ require 'condo'
2
+ require 'couchbase-id'
3
+ require 'condo-couchbase/engine'
4
+ require 'condo/backend/couchbase'
5
+
6
+ #::Condo::Application.backend = Condo::Backend::Couchbase
7
+ silence_warnings { ::Condo.const_set(:Store, Condo::Backend::Couchbase) }
@@ -0,0 +1,17 @@
1
+ module CondoCouchbase
2
+ class Engine < ::Rails::Engine
3
+ engine_name :condo_couchbase
4
+
5
+ config.after_initialize do |app|
6
+ model_conf = Couchbase::Model::Configuration
7
+ temp = model_conf.design_documents_paths
8
+
9
+ path = File.expand_path(File.join(File.dirname(__FILE__), '../condo/backend'))
10
+ model_conf.design_documents_paths = [path]
11
+
12
+ ::Condo::Backend::Couchbase.ensure_design_document!
13
+
14
+ model_conf.design_documents_paths = temp
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module CondoCouchbase
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ function(doc) {
2
+ if(doc.type === 'co_upld') {
3
+ emit(doc.user_id, null);
4
+ }
5
+ }
@@ -0,0 +1,133 @@
1
+ require 'digest/sha2'
2
+
3
+ module Condo
4
+ module Backend
5
+
6
+ #
7
+ # The following data needs to be stored in any backend
8
+ # => provider_namespace (for handling multiple upload controllers, defaults to global)
9
+ # => provider_name (amazon, rackspace, google, azure etc)
10
+ # => provider_location (US West (Oregon) Region, Asia Pacific (Singapore) Region etc)
11
+ # => user_id (the identifier for the current user as a string)
12
+ # => file_name (the original upload file name)
13
+ # => file_size (the file size as indicated by the client)
14
+ # => file_id (some sort of identifying hash provided by the client)
15
+ # => bucket_name (the name of the users bucket)
16
+ # => object_key (the path to the object in the bucket)
17
+ # => object_options (custom options that were applied to this object - public/private etc)
18
+ # => resumable_id (the id of the chunked upload)
19
+ # => resumable (true if a resumable upload - must be set)
20
+ # => date_created (the date the upload was started)
21
+ #
22
+ # => Each backend should have an ID that uniquely identifies an entry - id or upload_id
23
+ #
24
+ #
25
+ #
26
+ # Backends should inherit this class, set themselves as the backend and define the following:
27
+ #
28
+ # Class Methods:
29
+ # => check_exists ({user_id, upload_id}) returns nil or an entry where all fields match
30
+ # check_exists ({user_id, file_name, file_size, file_id}) so same logic for this
31
+ # => add_entry ({user_id, file_name, file_size, file_id, provider_name, provider_location, bucket_name, object_key})
32
+ #
33
+ #
34
+ #
35
+ # Instance Methods:
36
+ # => update_entry ({upload_id, resumable_id})
37
+ # => remove_entry (upload_id)
38
+ #
39
+ class Couchbase < ::Couchbase::Model
40
+ design_document :co_upld
41
+ before_create :generate_id
42
+
43
+
44
+ attribute :created_at, default: lambda { Time.now.to_i }
45
+ attribute :user_id, :file_name, :file_size, :file_id,
46
+ :provider_namespace, :provider_name, :provider_location, :bucket_name,
47
+ :object_key, :object_options, :resumable_id, :resumable, :file_path,
48
+ :part_list, :part_data
49
+
50
+
51
+ # Checks for an exact match in the database given a set of parameters
52
+ def self.check_exists(params)
53
+ params[:upload_id] ||= "upld-#{params[:user_id]}-#{Digest::SHA256.hexdigest("#{params[:file_id]}-#{params[:file_name]}-#{params[:file_size]}")}"
54
+ self.find_by_id(params[:upload_id])
55
+ end
56
+
57
+ # Adds a new upload entry into the database
58
+ def self.add_entry(params)
59
+ model = self.new(params)
60
+ model.object_options = params[:object_options]
61
+ model.create!
62
+ model
63
+ end
64
+
65
+ # Return a list of Uploads that were last updated before a particular time
66
+ view :by_user_id
67
+ def self.find_by_user_id(user_id)
68
+ self.by_user_id key: user_id, stale: false
69
+ end
70
+
71
+ def self.older_than(time)
72
+ old_upload = time.to_i
73
+ uploads = []
74
+ self.all_uploads.each do |upload|
75
+ uploads << upload if upload.created_at < old_upload
76
+ end
77
+ uploads
78
+ end
79
+
80
+ def self.all_uploads
81
+ self.by_user_id(stale: false)
82
+ end
83
+
84
+
85
+ # Updates self with the passed in parameters
86
+ def update_entry(params)
87
+ self.update_attributes(params)
88
+ result = self.save
89
+ raise ActiveResource::ResourceInvalid if result == false
90
+ self
91
+ end
92
+
93
+ # Deletes references to the upload
94
+ def remove_entry
95
+ self.delete
96
+ end
97
+
98
+ # Attribute accessors to comply with the backend spec
99
+ def upload_id
100
+ self.id
101
+ end
102
+
103
+ def date_created
104
+ @date_created ||= Time.at(self.created_at)
105
+ end
106
+
107
+ # Provide a clean up function that uses the condo strata to delete itself
108
+ # NOTE:: this won't work with completely dynamic providers so is really just here
109
+ # as a helper if you have pre-defined storage providers
110
+ def cleanup
111
+ options = {}
112
+ options[:namespace] = self.provider_namespace if self.provider_namespace
113
+ options[:location] = self.provider_location if self.provider_location
114
+ residence = ::Condo::Configuration.get_residence(self.provider_name, options)
115
+
116
+ if residence
117
+ residence.destroy(self)
118
+ self.remove_entry
119
+ else
120
+ raise NotImplementedError, 'unable to find static residence'
121
+ end
122
+ end
123
+
124
+
125
+ protected
126
+
127
+
128
+ def generate_id
129
+ self.id = "upld-#{self.user_id}-#{Digest::SHA256.hexdigest("#{self.file_id}-#{self.file_name}-#{self.file_size}")}"
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :condo_active_record do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: condo-couchbase
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Stephen von Takach
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: condo
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: couchbase-id
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
+ description: Provides database storage utilising Couchbase.
56
+ email:
57
+ - steve@cotag.me
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LGPL3-LICENSE
63
+ - README.textile
64
+ - Rakefile
65
+ - lib/condo-couchbase.rb
66
+ - lib/condo-couchbase/engine.rb
67
+ - lib/condo-couchbase/version.rb
68
+ - lib/condo/backend/co_upld/by_user_id/map.js
69
+ - lib/condo/backend/couchbase.rb
70
+ - lib/tasks/condo_couchbase_tasks.rake
71
+ homepage: http://cotag.me/
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.6
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Couchbase backend for the Condo project.
94
+ test_files: []
95
+ has_rdoc: