options_hash-method_object 0.0.1 → 0.1.0
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 +4 -4
- data/lib/options_hash/method_object.rb +10 -12
- data/spec/options_hash/method_object_spec.rb +0 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdcc77f75cf9408490f84a74b7ef9b158d766b92
|
4
|
+
data.tar.gz: 85c3412094c8c5356c98708a53a6c4f6e58d8ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56f28498cd0c3b525d726c58d3adff333b592cc4c06c77937d440cf81732b18908b124020e94ff70735eb41e46e8685f311e8c233f47ae232554ca3a74da62e6
|
7
|
+
data.tar.gz: 1c321e688429643b47cd5ddd0c27dc13ec1fa758d6e2fe86984b94517b745b443ef2ef863b02c630193b751723e420604c3d820ddceee71f7a8c00926f1cd809
|
@@ -2,7 +2,7 @@ require 'options_hash'
|
|
2
2
|
|
3
3
|
class OptionsHash::MethodObject
|
4
4
|
|
5
|
-
VERSION = '0.0
|
5
|
+
VERSION = '0.1.0'
|
6
6
|
|
7
7
|
def self.inherited(subclass)
|
8
8
|
subclass.send :extend, ClassMethods
|
@@ -31,17 +31,6 @@ class OptionsHash::MethodObject
|
|
31
31
|
def optional *keys, &block
|
32
32
|
options.optional *keys, &block
|
33
33
|
end
|
34
|
-
|
35
|
-
def options_reader *keys
|
36
|
-
keys.each do |key|
|
37
|
-
options.option?(key) or raise KeyError, "#{key} is not an option", caller(2)
|
38
|
-
define_method(key){ self.options[key] }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def option_readers!
|
43
|
-
options_reader *options.keys
|
44
|
-
end
|
45
34
|
end
|
46
35
|
|
47
36
|
module InstanceMethods
|
@@ -49,6 +38,15 @@ class OptionsHash::MethodObject
|
|
49
38
|
@options = self.class.options.parse(options)
|
50
39
|
end
|
51
40
|
attr_reader :options
|
41
|
+
|
42
|
+
def method_missing method, *args, &block
|
43
|
+
return options[method] if options.keys.include?(method)
|
44
|
+
raise NoMethodError, "undefined method `#{method}'", caller(1)
|
45
|
+
end
|
46
|
+
|
47
|
+
def given? key
|
48
|
+
options.given? key
|
49
|
+
end
|
52
50
|
end
|
53
51
|
|
54
52
|
end
|
@@ -5,8 +5,6 @@ class CreatePerson < OptionsHash::MethodObject
|
|
5
5
|
required :name
|
6
6
|
optional :favorite_color, default: ->{ 'blue' }
|
7
7
|
|
8
|
-
options_reader :name, :favorite_color
|
9
|
-
|
10
8
|
def call
|
11
9
|
options
|
12
10
|
end
|
@@ -17,8 +15,6 @@ class CreateRobot < CreatePerson
|
|
17
15
|
|
18
16
|
required :model_number
|
19
17
|
|
20
|
-
option_readers!
|
21
|
-
|
22
18
|
def call
|
23
19
|
[name, favorite_color, model_number]
|
24
20
|
end
|