curator 0.8.1 → 0.9.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.
@@ -45,6 +45,14 @@ module Curator
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
def find_all(collection_name)
|
49
|
+
bucket = _bucket_name(collection_name)
|
50
|
+
_records(bucket).inject([]) do |results, (key,value)|
|
51
|
+
results << {:key => key, :data => value}
|
52
|
+
results
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
48
56
|
def find_by_key(collection_name, key)
|
49
57
|
bucket = _bucket_name(collection_name)
|
50
58
|
value = _records(bucket).fetch(key, nil)
|
@@ -7,6 +7,8 @@ module Curator
|
|
7
7
|
def client
|
8
8
|
return @client if @client
|
9
9
|
config = YAML.load(File.read(Curator.config.mongo_config_file))[Curator.config.environment]
|
10
|
+
config = config.symbolize_keys
|
11
|
+
|
10
12
|
host = config.delete(:host)
|
11
13
|
port = config.delete(:port)
|
12
14
|
password = config.delete(:password)
|
@@ -41,6 +43,12 @@ module Curator
|
|
41
43
|
collection.remove(:_id => id)
|
42
44
|
end
|
43
45
|
|
46
|
+
def find_all(collection_name)
|
47
|
+
collection = _collection(collection_name)
|
48
|
+
documents = collection.find
|
49
|
+
documents.map {|doc| normalize_document(doc) }
|
50
|
+
end
|
51
|
+
|
44
52
|
def find_by_attribute(collection_name, field, query)
|
45
53
|
return [] if query.nil?
|
46
54
|
|
@@ -53,10 +61,20 @@ module Curator
|
|
53
61
|
|
54
62
|
def find_by_key(collection_name, id)
|
55
63
|
collection = _collection(collection_name)
|
56
|
-
document = collection
|
64
|
+
document = _find_by_key_as_provided(collection, id) || _find_by_key_as_object_id(collection, id)
|
57
65
|
normalize_document(document) unless document.nil?
|
58
66
|
end
|
59
67
|
|
68
|
+
def _find_by_key_as_provided(collection, id)
|
69
|
+
collection.find_one(:_id => id)
|
70
|
+
end
|
71
|
+
|
72
|
+
def _find_by_key_as_object_id(collection, id)
|
73
|
+
if BSON::ObjectId.legal?(id)
|
74
|
+
collection.find_one(:_id => BSON::ObjectId.from_string(id))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
60
78
|
def _collection(name)
|
61
79
|
_db.collection(name)
|
62
80
|
end
|
data/lib/curator/repository.rb
CHANGED
@@ -8,6 +8,12 @@ module Curator
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
+
def all
|
12
|
+
data_store.find_all(collection_name).map do |result|
|
13
|
+
_deserialize(result[:key], result[:data])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
11
17
|
def collection(explicit_collection_name)
|
12
18
|
@collection_name = explicit_collection_name
|
13
19
|
end
|
@@ -90,7 +96,7 @@ module Curator
|
|
90
96
|
end
|
91
97
|
|
92
98
|
def serialize(object)
|
93
|
-
object.instance_values
|
99
|
+
HashWithIndifferentAccess.new(object.instance_values)
|
94
100
|
end
|
95
101
|
|
96
102
|
def _build_finder_methods(attribute)
|
@@ -133,7 +139,7 @@ module Curator
|
|
133
139
|
end
|
134
140
|
|
135
141
|
def _indexes(object)
|
136
|
-
index_values = _indexed_fields.map { |field| [field, object.
|
142
|
+
index_values = _indexed_fields.map { |field| [field, serialize(object)[field.to_sym]] }
|
137
143
|
index_values += [
|
138
144
|
[:created_at, _format_time_for_index(object.send(:created_at))],
|
139
145
|
[:updated_at, _format_time_for_index(object.send(:updated_at))],
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -112,15 +112,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
112
|
- - ! '>='
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: 1871681440090585484
|
115
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
119
|
none: false
|
117
120
|
requirements:
|
118
121
|
- - ! '>='
|
119
122
|
- !ruby/object:Gem::Version
|
120
123
|
version: '0'
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
hash: 1871681440090585484
|
121
127
|
requirements: []
|
122
128
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.8.
|
129
|
+
rubygems_version: 1.8.24
|
124
130
|
signing_key:
|
125
131
|
specification_version: 3
|
126
132
|
summary: Model and repository framework
|