rethinker 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +10 -0
- data/README.md +49 -0
- data/USAGE.rb.md +99 -0
- data/lib/rethinker.rb +38 -0
- data/lib/rethinker/autoload.rb +14 -0
- data/lib/rethinker/connection.rb +49 -0
- data/lib/rethinker/criterion.rb +32 -0
- data/lib/rethinker/database.rb +38 -0
- data/lib/rethinker/document.rb +8 -0
- data/lib/rethinker/document/attributes.rb +117 -0
- data/lib/rethinker/document/core.rb +37 -0
- data/lib/rethinker/document/dynamic_attributes.rb +12 -0
- data/lib/rethinker/document/id.rb +54 -0
- data/lib/rethinker/document/injection_layer.rb +11 -0
- data/lib/rethinker/document/persistence.rb +79 -0
- data/lib/rethinker/document/polymorphic.rb +37 -0
- data/lib/rethinker/document/relation.rb +34 -0
- data/lib/rethinker/document/selection.rb +49 -0
- data/lib/rethinker/document/serialization.rb +41 -0
- data/lib/rethinker/document/timestamps.rb +18 -0
- data/lib/rethinker/document/validation.rb +62 -0
- data/lib/rethinker/error.rb +6 -0
- data/lib/rethinker/query_runner.rb +32 -0
- data/lib/rethinker/query_runner/connection.rb +17 -0
- data/lib/rethinker/query_runner/database_on_demand.rb +16 -0
- data/lib/rethinker/query_runner/driver.rb +10 -0
- data/lib/rethinker/query_runner/selection.rb +8 -0
- data/lib/rethinker/query_runner/table_on_demand.rb +12 -0
- data/lib/rethinker/query_runner/write_error.rb +34 -0
- data/lib/rethinker/railtie.rb +16 -0
- data/lib/rethinker/railtie/database.rake +37 -0
- data/lib/rethinker/relation.rb +6 -0
- data/lib/rethinker/relation/belongs_to.rb +36 -0
- data/lib/rethinker/relation/has_many.rb +30 -0
- data/lib/rethinker/relation/has_many/selection.rb +27 -0
- data/lib/rethinker/selection.rb +6 -0
- data/lib/rethinker/selection/core.rb +39 -0
- data/lib/rethinker/selection/count.rb +13 -0
- data/lib/rethinker/selection/delete.rb +9 -0
- data/lib/rethinker/selection/enumerable.rb +22 -0
- data/lib/rethinker/selection/first.rb +20 -0
- data/lib/rethinker/selection/inc.rb +12 -0
- data/lib/rethinker/selection/limit.rb +15 -0
- data/lib/rethinker/selection/order_by.rb +41 -0
- data/lib/rethinker/selection/scope.rb +11 -0
- data/lib/rethinker/selection/update.rb +6 -0
- data/lib/rethinker/selection/where.rb +23 -0
- data/lib/rethinker/version.rb +3 -0
- metadata +140 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
module Rethinker::Selection::OrderBy
|
2
|
+
|
3
|
+
def order_by(*rules)
|
4
|
+
rules = Hash[*rules.map{|i| i.is_a?(Hash) ? i.to_a.flatten : [i, :asc]}.flatten]
|
5
|
+
criterion = Rethinker::Criterion.new(:order_by, OrderByRules.new(rules))
|
6
|
+
chain criterion
|
7
|
+
end
|
8
|
+
|
9
|
+
def ordered?
|
10
|
+
!criteria.select{|c| c.method == :order_by }.blank?
|
11
|
+
end
|
12
|
+
|
13
|
+
class OrderByRules
|
14
|
+
attr_accessor :rules
|
15
|
+
|
16
|
+
def initialize(rules)
|
17
|
+
@rules = rules
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_rql(context)
|
21
|
+
@rules.map{|k,v| rql_lookup(k,v, context[:order])}
|
22
|
+
end
|
23
|
+
|
24
|
+
def rql_lookup(key, value = :asc, order)
|
25
|
+
case value
|
26
|
+
when asc(order) then RethinkDB::RQL.new.asc(key)
|
27
|
+
when desc(order) then RethinkDB::RQL.new.desc(key)
|
28
|
+
else raise "please pass :asc or :desc, not #{value}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def asc(order)
|
33
|
+
order == :reverse ? :desc : :asc
|
34
|
+
end
|
35
|
+
|
36
|
+
def desc(order)
|
37
|
+
order == :reverse ? :asc : :desc
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rethinker::Selection::Scope
|
2
|
+
def respond_to?(name, include_private = false)
|
3
|
+
super || klass.respond_to?(name)
|
4
|
+
end
|
5
|
+
|
6
|
+
# TODO Make something a bit more efficent
|
7
|
+
def method_missing(name, *args, &block)
|
8
|
+
return super unless klass.respond_to?(name)
|
9
|
+
klass.method(name).call(*args, &block)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rethinker::Selection::Where
|
2
|
+
def where(*args, &block)
|
3
|
+
#options = args.extract_options!.dup
|
4
|
+
#default_option = options.select { |k,v| k == :default }
|
5
|
+
|
6
|
+
# TODO: :default option
|
7
|
+
criterion = Rethinker::Criterion.new(:filter, args, &block)
|
8
|
+
chain criterion
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def extract_regexp!(options)
|
14
|
+
regexp_filters = {}
|
15
|
+
options.each do |k,v|
|
16
|
+
if v.is_a?(Regexp)
|
17
|
+
options.delete(k)
|
18
|
+
regexp_filters[k] = v.inspect[1..-2]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
regexp_filters
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rethinker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toby Marsden
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rethinkdb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.11.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.11.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
- - <
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '5'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 3.2.0
|
44
|
+
- - <
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: middleware
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.1.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.1.0
|
61
|
+
description: ORM for RethinkDB
|
62
|
+
email:
|
63
|
+
- toby@databasify.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- lib/rethinker/autoload.rb
|
69
|
+
- lib/rethinker/connection.rb
|
70
|
+
- lib/rethinker/criterion.rb
|
71
|
+
- lib/rethinker/database.rb
|
72
|
+
- lib/rethinker/document/attributes.rb
|
73
|
+
- lib/rethinker/document/core.rb
|
74
|
+
- lib/rethinker/document/dynamic_attributes.rb
|
75
|
+
- lib/rethinker/document/id.rb
|
76
|
+
- lib/rethinker/document/injection_layer.rb
|
77
|
+
- lib/rethinker/document/persistence.rb
|
78
|
+
- lib/rethinker/document/polymorphic.rb
|
79
|
+
- lib/rethinker/document/relation.rb
|
80
|
+
- lib/rethinker/document/selection.rb
|
81
|
+
- lib/rethinker/document/serialization.rb
|
82
|
+
- lib/rethinker/document/timestamps.rb
|
83
|
+
- lib/rethinker/document/validation.rb
|
84
|
+
- lib/rethinker/document.rb
|
85
|
+
- lib/rethinker/error.rb
|
86
|
+
- lib/rethinker/query_runner/connection.rb
|
87
|
+
- lib/rethinker/query_runner/database_on_demand.rb
|
88
|
+
- lib/rethinker/query_runner/driver.rb
|
89
|
+
- lib/rethinker/query_runner/selection.rb
|
90
|
+
- lib/rethinker/query_runner/table_on_demand.rb
|
91
|
+
- lib/rethinker/query_runner/write_error.rb
|
92
|
+
- lib/rethinker/query_runner.rb
|
93
|
+
- lib/rethinker/railtie/database.rake
|
94
|
+
- lib/rethinker/railtie.rb
|
95
|
+
- lib/rethinker/relation/belongs_to.rb
|
96
|
+
- lib/rethinker/relation/has_many/selection.rb
|
97
|
+
- lib/rethinker/relation/has_many.rb
|
98
|
+
- lib/rethinker/relation.rb
|
99
|
+
- lib/rethinker/selection/core.rb
|
100
|
+
- lib/rethinker/selection/count.rb
|
101
|
+
- lib/rethinker/selection/delete.rb
|
102
|
+
- lib/rethinker/selection/enumerable.rb
|
103
|
+
- lib/rethinker/selection/first.rb
|
104
|
+
- lib/rethinker/selection/inc.rb
|
105
|
+
- lib/rethinker/selection/limit.rb
|
106
|
+
- lib/rethinker/selection/order_by.rb
|
107
|
+
- lib/rethinker/selection/scope.rb
|
108
|
+
- lib/rethinker/selection/update.rb
|
109
|
+
- lib/rethinker/selection/where.rb
|
110
|
+
- lib/rethinker/selection.rb
|
111
|
+
- lib/rethinker/version.rb
|
112
|
+
- lib/rethinker.rb
|
113
|
+
- README.md
|
114
|
+
- USAGE.rb.md
|
115
|
+
- LICENSE.md
|
116
|
+
homepage: http://github.com/databasify/rethinker
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.1.11
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: ORM for RethinkDB
|
140
|
+
test_files: []
|