fixjour 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fixjour/merging_proxy.rb +25 -1
- metadata +1 -1
@@ -9,13 +9,37 @@ module Fixjour
|
|
9
9
|
@klass = klass
|
10
10
|
@overrides = overrides
|
11
11
|
end
|
12
|
+
|
13
|
+
def protected(*attrs)
|
14
|
+
attrs = attrs.empty? ?
|
15
|
+
@protected :
|
16
|
+
@protected = attrs
|
17
|
+
Set.new(attrs)
|
18
|
+
end
|
12
19
|
|
13
20
|
def new(defaults={})
|
14
|
-
|
21
|
+
attrs = defaults.merge(@overrides)
|
22
|
+
accessible, inaccessible = partition(attrs)
|
23
|
+
returning @klass.new(accessible) do |instance|
|
24
|
+
inaccessible.each do |key,val|
|
25
|
+
instance.send("#{key}=", val)
|
26
|
+
end
|
27
|
+
end
|
15
28
|
end
|
16
29
|
|
17
30
|
def method_missing(sym, *args, &block)
|
18
31
|
@klass.respond_to?(sym) ? @klass.send(sym, *args, &block) : super
|
19
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def partition(attrs)
|
37
|
+
accessible = attrs.keys.inject({ }) do |m, key|
|
38
|
+
next m if protected.include?(key)
|
39
|
+
m[key] = attrs.delete(key)
|
40
|
+
m
|
41
|
+
end
|
42
|
+
[accessible, attrs]
|
43
|
+
end
|
20
44
|
end
|
21
45
|
end
|