interpol 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,35 +10,47 @@ module Interpol
10
10
  # everything. This is handy so that consumers of this gem can distinguish
11
11
  # between a fat-fingered field, and a field that is set to nil.
12
12
  module DynamicStruct
13
- DEFAULT_PROC = lambda do |hash, key|
14
- raise NoMethodError, "undefined method `#{key}' for #{hash.inspect}"
15
- end
13
+ SAFE_METHOD_MISSING = ::Hashie::Mash.superclass.instance_method(:method_missing)
16
14
 
17
15
  Mash = Class.new(::Hashie::Mash) do
18
16
  undef sort
19
17
  end
20
18
 
21
- def self.new(source)
22
- hash = Mash.new(source)
23
- recursively_freeze(hash)
24
- hash
19
+ def self.new(*args)
20
+ Mash.new(*args).tap do |mash|
21
+ mash.extend(self)
22
+ end
25
23
  end
26
24
 
27
- def self.recursively_freeze(object)
25
+ def self.extended(mash)
26
+ recursively_extend(mash)
27
+ end
28
+
29
+ def self.recursively_extend(object)
28
30
  case object
29
31
  when Array
30
- object.each { |obj| recursively_freeze(obj) }
31
- when Hash
32
- set_default_proc_on(object)
33
- recursively_freeze(object.values)
32
+ object.each { |v| recursively_extend(v) }
33
+ when Mash
34
+ object.extend(self) unless object.is_a?(self)
35
+ object.each { |_, v| recursively_extend(v) }
36
+ end
37
+ end
38
+
39
+ def method_missing(method_name, *args, &blk)
40
+ if key = method_name.to_s[/\A([^?=]*)[?=]?\z/, 1]
41
+ unless has_key?(key)
42
+ return safe_method_missing(method_name, *args, &blk)
43
+ end
34
44
  end
45
+
46
+ super
35
47
  end
36
48
 
37
- def self.set_default_proc_on(hash)
38
- hash.default_proc = DEFAULT_PROC
49
+ private
50
+
51
+ def safe_method_missing(*args)
52
+ SAFE_METHOD_MISSING.bind(self).call(*args)
39
53
  end
40
54
  end
41
55
  end
42
56
 
43
- require 'interpol/hash_set_default_proc_18' unless {}.respond_to?(:default_proc=)
44
-
@@ -1,3 +1,3 @@
1
1
  module Interpol
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interpol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
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-11 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -194,7 +194,6 @@ files:
194
194
  - lib/interpol/each_with_object.rb
195
195
  - lib/interpol/endpoint.rb
196
196
  - lib/interpol/errors.rb
197
- - lib/interpol/hash_set_default_proc_18.rb
198
197
  - lib/interpol/request_body_validator.rb
199
198
  - lib/interpol/request_params_parser.rb
200
199
  - lib/interpol/response_schema_validator.rb
@@ -1,9 +0,0 @@
1
- module Interpol
2
- module DynamicStruct
3
- # Hash#default_proc= isn't defined on 1.8; this is the best we can do.
4
- def self.set_default_proc_on(hash)
5
- hash.replace(Hash.new(&DEFAULT_PROC).merge(hash))
6
- end
7
- end
8
- end
9
-