fixjour 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/fixjour/merging_proxy.rb +25 -1
  2. 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
- @klass.new(defaults.merge(@overrides))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixjour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Nakajima