dokument 1.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/dokument.gemspec +20 -0
- data/lib/dokument/association.rb +13 -0
- data/lib/dokument/attachment.rb +42 -0
- data/lib/dokument/model.rb +38 -0
- data/lib/dokument/version.rb +3 -0
- data/lib/dokument.rb +14 -0
- data/spec/dokument/association_spec.rb +46 -0
- data/spec/dokument/attachment_spec.rb +67 -0
- data/spec/dokument/model_spec.rb +29 -0
- data/spec/dokument_spec.rb +11 -0
- data/spec/spec_helper.rb +19 -0
- metadata +90 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create default@dokument
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Adam Hunter
|
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,54 @@
|
|
1
|
+
# Dokument
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dokument'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dokument
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
### Notes
|
24
|
+
|
25
|
+
MapReduce query for extracting entities with secondary index search
|
26
|
+
{
|
27
|
+
"inputs":{
|
28
|
+
"bucket":"mybucket",
|
29
|
+
"index":"field1_bin",
|
30
|
+
"start":"val3",
|
31
|
+
"end":"val4"
|
32
|
+
},
|
33
|
+
"query":[
|
34
|
+
{
|
35
|
+
"map":{
|
36
|
+
"language":"javascript",
|
37
|
+
"source":"
|
38
|
+
function(value, keydata, arg){
|
39
|
+
return [value];
|
40
|
+
}
|
41
|
+
",
|
42
|
+
"keep":true
|
43
|
+
}
|
44
|
+
}
|
45
|
+
]
|
46
|
+
}
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/dokument.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dokument/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Adam Hunter"]
|
6
|
+
gem.email = ["adamhunter@me.com"]
|
7
|
+
gem.description = %q{Provides a ripple document to give models 1 or n file attachments.}
|
8
|
+
gem.summary = %q{Riak backed model attachments}
|
9
|
+
# gem.homepage = ""
|
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 = "dokument"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Dokument::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "riak-client", "~> 1.0.3"
|
19
|
+
gem.add_development_dependency "rspec", "~> 2.10.0"
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Dokument
|
4
|
+
class Attachment
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
delegate %w[data data= content_type content_type=] => :robject
|
8
|
+
|
9
|
+
attr_reader :model, :association
|
10
|
+
|
11
|
+
def initialize(model, association)
|
12
|
+
@model = model
|
13
|
+
@association = association
|
14
|
+
end
|
15
|
+
|
16
|
+
def robject
|
17
|
+
@robject ||= bucket.get_or_new(model.send(association.key).to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
def save
|
21
|
+
raise IncompleteError.new("Attachment is missing content_type or data (#{inspect})") unless complete?
|
22
|
+
robject.store
|
23
|
+
end
|
24
|
+
|
25
|
+
def incomplete?
|
26
|
+
content_type.nil? || data.nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
def complete?
|
30
|
+
!incomplete?
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def bucket
|
36
|
+
Dokument.client[association.bucket]
|
37
|
+
end
|
38
|
+
|
39
|
+
class IncompleteError < StandardError ; end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Dokument
|
2
|
+
module Model
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def dokuments
|
10
|
+
@dokuments ||= Hash.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def dokument(name, options={})
|
14
|
+
dokuments[name] = Association.new(name)
|
15
|
+
add_association_reader(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def add_association_reader(name)
|
21
|
+
define_method(name) do
|
22
|
+
get_attachment(name) || set_attachment(name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def get_attachment(name)
|
30
|
+
instance_variable_get(:"@_#{name}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_attachment(name)
|
34
|
+
instance_variable_set(:"@_#{name}", Dokument::Attachment.new(self, self.class.dokuments[name]))
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/dokument.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dokument::Association do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@association = Dokument::Association.new(:file)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "take a name upon initialization" do
|
10
|
+
@association.name.should eq(:file)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "attributes" do
|
14
|
+
%w[name bucket key].each do |attribute|
|
15
|
+
it "has a #{attribute}" do
|
16
|
+
@association.should respond_to(attribute)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "defaults" do
|
22
|
+
it "defaults the model key to :id" do
|
23
|
+
@association.key.should eq(:id)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "defaults the bucket to the string version of the name" do
|
27
|
+
@association.bucket.should eq('file')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "initialization options" do
|
32
|
+
before :each do
|
33
|
+
@association = Dokument::Association.new(:file, :bucket => 'files_bucket', :key => 'some_id')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can set the bucket name" do
|
37
|
+
@association.bucket.should eq('files_bucket')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can set the model key" do
|
41
|
+
@association.key.should eq('some_id')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dokument::Attachment do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@model = ExampleModel.new
|
7
|
+
@content_type = 'text/plain'
|
8
|
+
@data = 'This is an attachment.'
|
9
|
+
@attachment = @model.file
|
10
|
+
@association = @model.file.association
|
11
|
+
@attachment.content_type = @content_type
|
12
|
+
@attachment.data = @data
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has a content_type" do
|
16
|
+
@attachment.content_type.should eq(@content_type)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a data" do
|
20
|
+
@attachment.data.should eq(@data)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "delegates saving to it's robject" do
|
24
|
+
@attachment.robject.should_receive(:store)
|
25
|
+
@attachment.save
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "completeness" do
|
29
|
+
it "is true if the data and content_type are set" do
|
30
|
+
@attachment.should be_complete
|
31
|
+
end
|
32
|
+
|
33
|
+
it "is false if the data is nil" do
|
34
|
+
@attachment.data = nil
|
35
|
+
@attachment.should_not be_complete
|
36
|
+
end
|
37
|
+
|
38
|
+
it "is false if the content_type is nil" do
|
39
|
+
@attachment.content_type = nil
|
40
|
+
@attachment.should_not be_complete
|
41
|
+
end
|
42
|
+
|
43
|
+
it "will raise an exception if you try to save and it is not complete" do
|
44
|
+
@attachment.data = nil
|
45
|
+
expect { @attachment.save }.to raise_error(Dokument::Attachment::IncompleteError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "robject" do
|
50
|
+
it "uses the attachments data" do
|
51
|
+
@attachment.robject.data.should eq(@data)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "uses the attachments content_type" do
|
55
|
+
@attachment.robject.content_type.should eq(@content_type)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "uses the associated model's key method for the key" do
|
59
|
+
@attachment.robject.key.should eq(@model.id.to_s)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "uses the associations bucket for the bucket name" do
|
63
|
+
@attachment.robject.bucket.name.should eq(@association.bucket)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dokument::Model do
|
4
|
+
describe "provided class methods" do
|
5
|
+
it "adds an accessor to list all defined dokuments" do
|
6
|
+
ExampleModel.dokuments.should be_a(Hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "will add a single dokument using the `dokument` class method" do
|
10
|
+
ExampleModel.dokument :file
|
11
|
+
ExampleModel.dokuments[:file].should be_a(Dokument::Association)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "provided instance methods" do
|
16
|
+
before :each do
|
17
|
+
@model = ExampleModel.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it "adds an reader for the given dokument" do
|
21
|
+
@model.should respond_to(:file)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "will return the Dokument::Attachment for the given reader" do
|
25
|
+
@model.file.should be_a(Dokument::Attachment)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift('../lib')
|
2
|
+
require 'dokument'
|
3
|
+
|
4
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.filter_run :focus
|
9
|
+
end
|
10
|
+
|
11
|
+
class ExampleModel
|
12
|
+
include Dokument::Model
|
13
|
+
|
14
|
+
dokument :file
|
15
|
+
|
16
|
+
def id
|
17
|
+
125
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dokument
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.alpha
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Hunter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: riak-client
|
16
|
+
requirement: &70364752141440 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70364752141440
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70364752140940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.10.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70364752140940
|
36
|
+
description: Provides a ripple document to give models 1 or n file attachments.
|
37
|
+
email:
|
38
|
+
- adamhunter@me.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- .rvmrc
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- dokument.gemspec
|
51
|
+
- lib/dokument.rb
|
52
|
+
- lib/dokument/association.rb
|
53
|
+
- lib/dokument/attachment.rb
|
54
|
+
- lib/dokument/model.rb
|
55
|
+
- lib/dokument/version.rb
|
56
|
+
- spec/dokument/association_spec.rb
|
57
|
+
- spec/dokument/attachment_spec.rb
|
58
|
+
- spec/dokument/model_spec.rb
|
59
|
+
- spec/dokument_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
homepage:
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>'
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.3.1
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.16
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Riak backed model attachments
|
85
|
+
test_files:
|
86
|
+
- spec/dokument/association_spec.rb
|
87
|
+
- spec/dokument/attachment_spec.rb
|
88
|
+
- spec/dokument/model_spec.rb
|
89
|
+
- spec/dokument_spec.rb
|
90
|
+
- spec/spec_helper.rb
|