tyrion 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tyrion/attributes.rb +5 -7
- data/lib/tyrion/components.rb +9 -6
- data/lib/tyrion/document.rb +13 -2
- data/lib/tyrion/persistence.rb +19 -5
- data/lib/tyrion/querying.rb +3 -4
- data/lib/tyrion/storage.rb +4 -9
- data/lib/tyrion/validations.rb +10 -0
- data/lib/tyrion/version.rb +1 -1
- data/lib/tyrion.rb +2 -1
- metadata +24 -39
- data/.gitignore +0 -24
- data/.rspec +0 -1
- data/.travis.yml +0 -11
- data/Gemfile +0 -4
- data/spec/connection_spec.rb +0 -22
- data/spec/document_spec.rb +0 -133
- data/spec/examples/post.rb +0 -7
- data/spec/fixtures/posts.yml +0 -10
- data/spec/test_helper.rb +0 -24
- data/tyrion.gemspec +0 -25
data/lib/tyrion/attributes.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Tyrion
|
2
|
-
module Attributes
|
3
|
-
|
2
|
+
module Attributes
|
3
|
+
def self.included(receiver)
|
4
|
+
receiver.extend ClassMethods
|
5
|
+
receiver.send :include, InstanceMethods
|
6
|
+
end
|
4
7
|
|
5
8
|
module ClassMethods
|
6
9
|
def field(name, type = String)
|
@@ -14,11 +17,6 @@ module Tyrion
|
|
14
17
|
module InstanceMethods
|
15
18
|
attr_reader :attributes
|
16
19
|
|
17
|
-
def initialize
|
18
|
-
super
|
19
|
-
@attributes = {}
|
20
|
-
end
|
21
|
-
|
22
20
|
def method_missing(name, *args)
|
23
21
|
attr = name.to_s
|
24
22
|
return super unless attributes.has_key? attr.gsub("=", "")
|
data/lib/tyrion/components.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module Tyrion
|
2
2
|
module Components
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
def self.included(receiver)
|
4
|
+
receiver.class_eval do
|
5
|
+
include Tyrion::Attributes
|
6
|
+
include Tyrion::Validations
|
7
|
+
include Tyrion::Persistence
|
8
|
+
include Tyrion::Querying
|
9
|
+
include Tyrion::Storage
|
10
|
+
end
|
11
|
+
end
|
9
12
|
end
|
10
13
|
end
|
data/lib/tyrion/document.rb
CHANGED
@@ -2,8 +2,14 @@ module Tyrion
|
|
2
2
|
|
3
3
|
# Base module to persist objects.
|
4
4
|
module Document
|
5
|
-
|
6
|
-
|
5
|
+
def self.included(receiver)
|
6
|
+
receiver.extend ClassMethods
|
7
|
+
|
8
|
+
receiver.class_eval do
|
9
|
+
include Tyrion::Components
|
10
|
+
include InstanceMethods
|
11
|
+
end
|
12
|
+
end
|
7
13
|
|
8
14
|
module ClassMethods
|
9
15
|
protected
|
@@ -24,6 +30,11 @@ module Tyrion
|
|
24
30
|
other.attributes == attributes
|
25
31
|
end
|
26
32
|
|
33
|
+
def initialize(attrs = {})
|
34
|
+
@attributes = attrs.stringify_keys
|
35
|
+
@new_document = true
|
36
|
+
end
|
37
|
+
|
27
38
|
private
|
28
39
|
|
29
40
|
def klass_name
|
data/lib/tyrion/persistence.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module Tyrion
|
2
2
|
module Persistence
|
3
|
-
|
3
|
+
def self.included(receiver)
|
4
|
+
receiver.extend ClassMethods
|
5
|
+
receiver.send :include, InstanceMethods
|
6
|
+
end
|
4
7
|
|
5
8
|
module ClassMethods
|
6
9
|
def create attributes = {}
|
7
|
-
new.tap do |n|
|
10
|
+
new(attributes).tap do |n|
|
8
11
|
attributes.each_pair{ |k, v| n.send(:write_attribute, k.to_s, v) }
|
9
12
|
end
|
10
13
|
end
|
@@ -22,16 +25,27 @@ module Tyrion
|
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
|
-
module InstanceMethods
|
28
|
+
module InstanceMethods
|
26
29
|
def save
|
27
|
-
|
28
|
-
|
30
|
+
if valid?
|
31
|
+
self.class.storage[klass_name] << self
|
32
|
+
self.class.save_storage klass_name
|
33
|
+
@new_document = false
|
34
|
+
|
35
|
+
true
|
36
|
+
else
|
37
|
+
false
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
41
|
def delete
|
32
42
|
self.class.storage[klass_name].delete_if{ |doc| self == doc }
|
33
43
|
self.class.save_storage klass_name
|
34
44
|
end
|
45
|
+
|
46
|
+
def new_document?
|
47
|
+
@new_document
|
48
|
+
end
|
35
49
|
end
|
36
50
|
end
|
37
51
|
end
|
data/lib/tyrion/querying.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Tyrion
|
2
2
|
module Querying
|
3
|
-
|
3
|
+
def self.included(receiver)
|
4
|
+
receiver.extend ClassMethods
|
5
|
+
end
|
4
6
|
|
5
7
|
module ClassMethods
|
6
8
|
def all
|
@@ -44,8 +46,5 @@ module Tyrion
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
47
|
-
|
48
|
-
module InstanceMethods
|
49
|
-
end
|
50
49
|
end
|
51
50
|
end
|
data/lib/tyrion/storage.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Tyrion
|
2
2
|
module Storage
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
reload unless
|
3
|
+
def self.included(receiver)
|
4
|
+
receiver.extend ClassMethods
|
5
|
+
|
6
|
+
receiver.reload unless receiver == Tyrion::Components
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
@@ -29,8 +29,6 @@ module Tyrion
|
|
29
29
|
File.open(path, 'w') do |f|
|
30
30
|
f.puts MultiJson.encode(storage[klass_name].map &:attributes)
|
31
31
|
end
|
32
|
-
|
33
|
-
true
|
34
32
|
end
|
35
33
|
|
36
34
|
protected
|
@@ -39,8 +37,5 @@ module Tyrion
|
|
39
37
|
File.join(Connection.path, klass_name + ".json")
|
40
38
|
end
|
41
39
|
end
|
42
|
-
|
43
|
-
module InstanceMethods
|
44
|
-
end
|
45
40
|
end
|
46
41
|
end
|
data/lib/tyrion/version.rb
CHANGED
data/lib/tyrion.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'multi_json'
|
2
|
-
require '
|
2
|
+
require 'active_model'
|
3
3
|
|
4
4
|
require 'tyrion/version'
|
5
5
|
require 'tyrion/connection'
|
@@ -9,5 +9,6 @@ require 'tyrion/persistence'
|
|
9
9
|
require 'tyrion/querying'
|
10
10
|
require 'tyrion/storage'
|
11
11
|
require 'tyrion/components'
|
12
|
+
require 'tyrion/validations'
|
12
13
|
|
13
14
|
require 'tyrion/document'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tyrion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-12-29 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: multi_json
|
17
|
-
requirement: &
|
16
|
+
requirement: &70281257801860 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *70281257801860
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: json_pure
|
28
|
-
requirement: &
|
27
|
+
requirement: &70281257801040 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,21 +32,21 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *70281257801040
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement: &
|
37
|
+
name: activemodel
|
38
|
+
requirement: &70281257816640 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
|
-
- -
|
41
|
+
- - ~>
|
43
42
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
43
|
+
version: 3.1.0
|
45
44
|
type: :runtime
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *70281257816640
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: rspec
|
50
|
-
requirement: &
|
49
|
+
requirement: &70281257815820 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
52
|
- - ! '>='
|
@@ -55,10 +54,10 @@ dependencies:
|
|
55
54
|
version: '0'
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
57
|
+
version_requirements: *70281257815820
|
59
58
|
- !ruby/object:Gem::Dependency
|
60
59
|
name: simplecov
|
61
|
-
requirement: &
|
60
|
+
requirement: &70281257814980 !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
63
|
- - ! '>='
|
@@ -66,7 +65,7 @@ dependencies:
|
|
66
65
|
version: '0'
|
67
66
|
type: :development
|
68
67
|
prerelease: false
|
69
|
-
version_requirements: *
|
68
|
+
version_requirements: *70281257814980
|
70
69
|
description: Tyrion's goal is to provide a fast (as in _easy to setup_) and dirty
|
71
70
|
unstructured document store.
|
72
71
|
email:
|
@@ -75,14 +74,6 @@ executables: []
|
|
75
74
|
extensions: []
|
76
75
|
extra_rdoc_files: []
|
77
76
|
files:
|
78
|
-
- .gitignore
|
79
|
-
- .rspec
|
80
|
-
- .travis.yml
|
81
|
-
- Gemfile
|
82
|
-
- LICENSE
|
83
|
-
- README.markdown
|
84
|
-
- Rakefile
|
85
|
-
- lib/tyrion.rb
|
86
77
|
- lib/tyrion/attributes.rb
|
87
78
|
- lib/tyrion/components.rb
|
88
79
|
- lib/tyrion/connection.rb
|
@@ -90,15 +81,13 @@ files:
|
|
90
81
|
- lib/tyrion/persistence.rb
|
91
82
|
- lib/tyrion/querying.rb
|
92
83
|
- lib/tyrion/storage.rb
|
84
|
+
- lib/tyrion/validations.rb
|
93
85
|
- lib/tyrion/version.rb
|
94
|
-
-
|
95
|
-
-
|
96
|
-
-
|
97
|
-
-
|
98
|
-
|
99
|
-
- tyrion.gemspec
|
100
|
-
has_rdoc: true
|
101
|
-
homepage: http://github.com/
|
86
|
+
- lib/tyrion.rb
|
87
|
+
- LICENSE
|
88
|
+
- README.markdown
|
89
|
+
- Rakefile
|
90
|
+
homepage: http://github.com/razielgn/tyrion
|
102
91
|
licenses: []
|
103
92
|
post_install_message:
|
104
93
|
rdoc_options: []
|
@@ -118,13 +107,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
107
|
version: '0'
|
119
108
|
requirements: []
|
120
109
|
rubyforge_project:
|
121
|
-
rubygems_version: 1.
|
110
|
+
rubygems_version: 1.8.11
|
122
111
|
signing_key:
|
123
112
|
specification_version: 3
|
124
113
|
summary: Tyrion is a small JSON ODM
|
125
|
-
test_files:
|
126
|
-
|
127
|
-
- spec/document_spec.rb
|
128
|
-
- spec/examples/post.rb
|
129
|
-
- spec/fixtures/posts.yml
|
130
|
-
- spec/test_helper.rb
|
114
|
+
test_files: []
|
115
|
+
has_rdoc:
|
data/.gitignore
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
.DS_Store?
|
2
|
-
.DS_Store
|
3
|
-
ehthumbs.db
|
4
|
-
Icon?
|
5
|
-
Thumbs.db
|
6
|
-
|
7
|
-
# Rails
|
8
|
-
coverage
|
9
|
-
rdoc
|
10
|
-
tmp
|
11
|
-
pkg
|
12
|
-
*.gem
|
13
|
-
*.rbc
|
14
|
-
lib/bundler/man
|
15
|
-
spec/reports
|
16
|
-
.config
|
17
|
-
.bundle
|
18
|
-
|
19
|
-
# YARD artifacts
|
20
|
-
.yardoc
|
21
|
-
_yardoc
|
22
|
-
doc/
|
23
|
-
|
24
|
-
Gemfile.lock
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/spec/connection_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Tyrion::Connection do
|
4
|
-
before{ @original_path = subject.path }
|
5
|
-
after{ subject.path = @original_path }
|
6
|
-
|
7
|
-
describe '.path' do
|
8
|
-
it 'should raise an exception if no path is set' do
|
9
|
-
expect do
|
10
|
-
subject.path = nil
|
11
|
-
subject.path
|
12
|
-
end.to raise_exception
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '.path=' do
|
17
|
-
it 'should set the path correctly' do
|
18
|
-
subject.path = ENV['HOME']
|
19
|
-
subject.path.should == ENV['HOME']
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/document_spec.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'examples/post'
|
3
|
-
|
4
|
-
describe Tyrion::Document do
|
5
|
-
|
6
|
-
let! :yml_posts do
|
7
|
-
YAML.load_file File.join(File.dirname(__FILE__), 'fixtures', 'posts.yml')
|
8
|
-
end
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
Post.reload
|
12
|
-
|
13
|
-
yml_posts.each do |p|
|
14
|
-
Post.create! p
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should survive a reload' do
|
19
|
-
Post.reload
|
20
|
-
Post.all.count.should == yml_posts.count
|
21
|
-
end
|
22
|
-
|
23
|
-
describe ".create" do
|
24
|
-
it 'should create a new instance with given attributes' do
|
25
|
-
post = Post.create :title => "Title", :body => "Body"
|
26
|
-
post.title.should == "Title"
|
27
|
-
post.body.should == "Body"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".all" do
|
32
|
-
it 'should find three posts' do
|
33
|
-
Post.all.count.should == yml_posts.count
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe ".find_by_" do
|
38
|
-
context "when performing the search without a regexp" do
|
39
|
-
it "should return a single value" do
|
40
|
-
search = Post.find_by_title("Hello")
|
41
|
-
search.should_not be_nil
|
42
|
-
search.should_not be_a(Array)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should return the first document found' do
|
46
|
-
search = Post.find_by_rank(2)
|
47
|
-
search.title.should == "Testing"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return nil if nothing is found" do
|
51
|
-
Post.find_by_title(5).should be_nil
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "when performing the search with a regexp" do
|
56
|
-
it "should return a single value" do
|
57
|
-
search = Post.find_by_title(/Hello/).should_not be_nil
|
58
|
-
search.should_not be_nil
|
59
|
-
search.should_not be_a(Array)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return nil if nothing is found" do
|
63
|
-
Post.find_by_title(/^u/).should be_nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should raise an exception if the search is performed without arguments' do
|
68
|
-
expect do
|
69
|
-
Post.find_by_body
|
70
|
-
end.to raise_exception
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should raise an exception if the search is performed on an unknown attribute' do
|
74
|
-
expect do
|
75
|
-
Post.find_by_id
|
76
|
-
end.to raise_exception
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe ".remove_all" do
|
81
|
-
it 'should delete every document' do
|
82
|
-
Post.delete_all
|
83
|
-
Post.all.count.should == 0
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe ".remove" do
|
88
|
-
it "should remove all matching documents" do
|
89
|
-
criteria = { :rank => 2, :body => /!$/ }
|
90
|
-
Post.delete(criteria)
|
91
|
-
Post.where(criteria).should be_empty
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe ".where" do
|
96
|
-
it 'should return an array on matching documents' do
|
97
|
-
search = Post.where(:rank => 2, :body => /!$/)
|
98
|
-
search.should_not be_nil
|
99
|
-
search.should be_a(Array)
|
100
|
-
search.count.should == 2
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'shoudl return an empty array if no documents are matched' do
|
104
|
-
Post.where(:title => /e/, :body => /^A/, :rank => 9000).should be_empty
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "#save" do
|
109
|
-
it 'should save a new document' do
|
110
|
-
post = Post.new
|
111
|
-
post.title = "Title"
|
112
|
-
post.body = "Body"
|
113
|
-
post.save.should be_true
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "#method_missing" do
|
118
|
-
it 'should allow to read and update new attributes' do
|
119
|
-
post = Post.new
|
120
|
-
post.send :write_attribute, :comments, 1
|
121
|
-
post.comments.should == 1
|
122
|
-
post.comments = 2
|
123
|
-
post.comments.should == 2
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "#delete" do
|
128
|
-
it 'should remove the document' do
|
129
|
-
Post.find_by_title("Hello").delete
|
130
|
-
Post.find_by_title("Hello").should be_nil
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
data/spec/examples/post.rb
DELETED
data/spec/fixtures/posts.yml
DELETED
data/spec/test_helper.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
SimpleCov.start
|
3
|
-
|
4
|
-
require 'tmpdir'
|
5
|
-
require 'fileutils'
|
6
|
-
|
7
|
-
require 'tyrion'
|
8
|
-
|
9
|
-
tmpdir = Dir.mktmpdir
|
10
|
-
Tyrion::Connection.path = tmpdir
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
config.before(:each) do
|
14
|
-
Tyrion::Connection.path = Dir.mktmpdir
|
15
|
-
end
|
16
|
-
|
17
|
-
config.after(:each) do
|
18
|
-
FileUtils.rm_rf Tyrion::Connection.path
|
19
|
-
end
|
20
|
-
|
21
|
-
config.after(:suite) do
|
22
|
-
FileUtils.rm_rf tmpdir
|
23
|
-
end
|
24
|
-
end
|
data/tyrion.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "tyrion/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "tyrion"
|
7
|
-
s.version = Tyrion::VERSION
|
8
|
-
s.authors = ["Federico Ravasio"]
|
9
|
-
s.email = ["ravasio.federico@gmail.com"]
|
10
|
-
s.homepage = "http://github.com/"
|
11
|
-
s.summary = %q{Tyrion is a small JSON ODM}
|
12
|
-
s.description = %q{Tyrion's goal is to provide a fast (as in _easy to setup_) and dirty unstructured document store.}
|
13
|
-
|
14
|
-
s.files = `git ls-files`.split("\n")
|
15
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
-
s.require_paths = ["lib"]
|
18
|
-
|
19
|
-
s.add_dependency 'multi_json'
|
20
|
-
s.add_dependency 'json_pure'
|
21
|
-
s.add_dependency 'active_support'
|
22
|
-
|
23
|
-
s.add_development_dependency 'rspec'
|
24
|
-
s.add_development_dependency 'simplecov'
|
25
|
-
end
|