oedipus-dm 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
##
|
4
|
+
# DataMapper Integration for Oedipus.
|
5
|
+
# Copyright © 2012 Chris Corbyn.
|
6
|
+
#
|
7
|
+
# See LICENSE file for details.
|
8
|
+
##
|
9
|
+
|
10
|
+
module Oedipus
|
11
|
+
module DataMapper
|
12
|
+
# Default methods for accessing model data.
|
13
|
+
#
|
14
|
+
# Note these classes are not actually procs, for performance reasons.
|
15
|
+
module DefaultProc
|
16
|
+
class Get
|
17
|
+
def initialize(model, attr)
|
18
|
+
@model = model
|
19
|
+
@attr = attr
|
20
|
+
@property = model.properties[attr]
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(resource)
|
24
|
+
if @property
|
25
|
+
@property.dump(resource[@attr])
|
26
|
+
else
|
27
|
+
resource.send(@attr)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Set
|
33
|
+
def initialize(model, attr)
|
34
|
+
@model = model
|
35
|
+
@attr = attr
|
36
|
+
@property = model.properties[attr]
|
37
|
+
end
|
38
|
+
|
39
|
+
def call(resource, value)
|
40
|
+
if @property
|
41
|
+
value = @property.load(value)
|
42
|
+
end
|
43
|
+
|
44
|
+
resource.send("#{@attr}=", value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -194,9 +194,7 @@ module Oedipus
|
|
194
194
|
raise ArgumentError, "Argument 1 for #multi_search must be a Hash" unless Hash === searches
|
195
195
|
|
196
196
|
raw.multi_search(
|
197
|
-
searches.inject({}) { |o, (k, v)|
|
198
|
-
o.merge!(k => convert_filters(v))
|
199
|
-
}
|
197
|
+
searches.inject({}) { |o, (k, v)| o.merge!(k => convert_filters(v)) }
|
200
198
|
).inject({}) { |o, (k, v)|
|
201
199
|
o.merge!(k => build_collection(v))
|
202
200
|
}
|
@@ -221,16 +219,16 @@ module Oedipus
|
|
221
219
|
# a proc/lambda that accepts a resource and returns the value to set,
|
222
220
|
# for realtime indexes only
|
223
221
|
def map(attr, options = {})
|
224
|
-
@mappings[attr] = normalize_mapping(attr, options.dup)
|
222
|
+
@mappings[attr.to_sym] = normalize_mapping(attr, options.dup)
|
225
223
|
end
|
226
224
|
|
227
225
|
private
|
228
226
|
|
229
227
|
def normalize_mapping(attr, options)
|
230
228
|
options.tap do
|
231
|
-
prop = options.delete(:with) || attr
|
232
|
-
options[:get] ||=
|
233
|
-
options[:set] ||=
|
229
|
+
prop = (options.delete(:with) || attr).to_sym
|
230
|
+
options[:get] ||= DefaultProc::Get.new(model, prop)
|
231
|
+
options[:set] ||= DefaultProc::Set.new(model, prop)
|
234
232
|
end
|
235
233
|
end
|
236
234
|
|
data/lib/oedipus/data_mapper.rb
CHANGED
@@ -13,6 +13,7 @@ require "dm-core"
|
|
13
13
|
require "oedipus/data_mapper/version"
|
14
14
|
require "oedipus/data_mapper/conversions"
|
15
15
|
require "oedipus/data_mapper/pagination"
|
16
|
+
require "oedipus/data_mapper/default_proc"
|
16
17
|
require "oedipus/data_mapper/index"
|
17
18
|
require "oedipus/data_mapper/collection"
|
18
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oedipus-dm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oedipus
|
16
|
-
requirement: &
|
16
|
+
requirement: &18175300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.0.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *18175300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: dm-core
|
27
|
-
requirement: &
|
27
|
+
requirement: &18174720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.2'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *18174720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &18174320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *18174320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &18173760 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *18173760
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: dm-pager
|
60
|
-
requirement: &
|
60
|
+
requirement: &18173280 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *18173280
|
69
69
|
description: ! '== DataMapper Integration for Oedipus
|
70
70
|
|
71
71
|
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/oedipus/data_mapper.rb
|
94
94
|
- lib/oedipus/data_mapper/collection.rb
|
95
95
|
- lib/oedipus/data_mapper/conversions.rb
|
96
|
+
- lib/oedipus/data_mapper/default_proc.rb
|
96
97
|
- lib/oedipus/data_mapper/index.rb
|
97
98
|
- lib/oedipus/data_mapper/pagination.rb
|
98
99
|
- lib/oedipus/data_mapper/version.rb
|
@@ -116,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
117
|
version: '0'
|
117
118
|
segments:
|
118
119
|
- 0
|
119
|
-
hash:
|
120
|
+
hash: 402637751909853895
|
120
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
122
|
none: false
|
122
123
|
requirements:
|
@@ -125,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
126
|
version: '0'
|
126
127
|
segments:
|
127
128
|
- 0
|
128
|
-
hash:
|
129
|
+
hash: 402637751909853895
|
129
130
|
requirements: []
|
130
131
|
rubyforge_project:
|
131
132
|
rubygems_version: 1.8.11
|