singlettings 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f347cd873ba6481b79dfb39bfae7f20b22561ce7
4
- data.tar.gz: 004d5fd453fd073f0d7179bdf96d2af9fbc96b44
3
+ metadata.gz: 691b5a753bda4746f95ff0fa30254c72ab35f7bf
4
+ data.tar.gz: 555694c87632d93ecd1b4084c8ccfe333a9bdcaf
5
5
  SHA512:
6
- metadata.gz: e92bbe8c92a8ea401384eb9639aec82db313d012d70a4f6905aecf14db0384b55cb9ab33b6ea81b07a6da2e8fa11021308765602659f8476ecfe5209a8839600
7
- data.tar.gz: 2a180ca7aa89665708474c3c55a2e399c483f677ed5068ee27e816e81d54d7f360d91a4352c21be8c4a0948c812d2527dee6b76f0a9f6aaad8701c1d26b40ae0
6
+ metadata.gz: 66d366df9f4ab81ad9a03ad9bf122b9a919d27a1174b2859b9139dc0093c015e8f7f93af96b3221d1a09e7423cf81d30a811636c83a7c5f1eb3e7d1de9c7b1e0
7
+ data.tar.gz: 9831baa0ee9531b02a8728f2c6433d464056f95939a78af57ad5ad7adbc15f1c7a057ba454020893f2825d95a3c04946dae74b06df345e2deb190f4261b60138
data/changes.md ADDED
@@ -0,0 +1,3 @@
1
+ 0.0.5
2
+
3
+ - define method after method missing
@@ -5,6 +5,7 @@ require 'erb'
5
5
  module Singlettings
6
6
  class Base < Hash
7
7
  attr_reader :source, :ns
8
+
8
9
  class << self
9
10
  # Basic Usage of source in class
10
11
  # source "config/setting.yml"
@@ -47,11 +48,14 @@ module Singlettings
47
48
  key = method.to_s
48
49
  if current_branch.keys.include? key
49
50
  value = current_branch[key]
50
- if value.is_a? Hash
51
- self.new value
52
- else
53
- value
51
+
52
+ result = value.is_a?(Hash) ? self.new(value) : value
53
+
54
+ self.instance_eval do
55
+ define_singleton_method(key){ result }
54
56
  end
57
+
58
+ result
55
59
  else
56
60
  raise NoSuchKeyError, "#{key} does not exist"
57
61
  end
@@ -99,11 +103,14 @@ module Singlettings
99
103
  key = method.to_s
100
104
  if current_branch.keys.include? key
101
105
  value = current_branch[key]
102
- if value.is_a? Hash
103
- self.class.new value
104
- else
105
- value
106
+
107
+ result = value.is_a?(Hash) ? self.class.new(value) : value
108
+
109
+ self.class.class_eval do
110
+ define_method(key){ result }
106
111
  end
112
+
113
+ result
107
114
  else
108
115
  raise NoSuchKeyError, "#{key} does not exist"
109
116
  end
@@ -1,3 +1,3 @@
1
1
  module Singlettings
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singlettings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jingkai He
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,6 +64,7 @@ files:
64
64
  - LICENSE.txt
65
65
  - README.md
66
66
  - Rakefile
67
+ - changes.md
67
68
  - lib/singlettings.rb
68
69
  - lib/singlettings/base.rb
69
70
  - lib/singlettings/exceptions.rb