method-args 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.markdown +6 -1
- data/lib/method_args.rb +10 -19
- data/lib/method_args/version.rb +1 -1
- data/test/fixtures/4.rb +4 -0
- data/test/test_autoload.rb +11 -0
- data/test/test_bound_method.rb +7 -0
- metadata +7 -14
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -19,7 +19,12 @@ Pretend you have a file `your_ruby_file.rb`:
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
To look at the arguments to something,
|
22
|
+
To look at the arguments to something and you're in Ruby 1.9 (please see https://twitter.com/igrigorik/status/19461463110320128), just require it normally:
|
23
|
+
|
24
|
+
require 'your_ruby_file'
|
25
|
+
MyClass.instance_method(:something).args
|
26
|
+
|
27
|
+
Otherwise, do the following:
|
23
28
|
|
24
29
|
MethodArgs.load('your_ruby_file') # <-- this also requires the file
|
25
30
|
MyClass.instance_method(:something).args
|
data/lib/method_args.rb
CHANGED
@@ -3,7 +3,13 @@ require 'ruby_parser'
|
|
3
3
|
require 'sexp_processor'
|
4
4
|
|
5
5
|
module MethodMixin
|
6
|
-
|
6
|
+
def args(trying_load = false)
|
7
|
+
if !trying_load && respond_to?(:source_location) && !owner.const_defined?(:ArgList, false)
|
8
|
+
file, line = source_location
|
9
|
+
MethodArgs.load(file, false)
|
10
|
+
end
|
11
|
+
self.args = owner.const_get(:ArgList)[name.to_sym]
|
12
|
+
end
|
7
13
|
|
8
14
|
def args=(a)
|
9
15
|
@args = a.clone
|
@@ -75,9 +81,9 @@ module MethodArgs
|
|
75
81
|
end
|
76
82
|
end
|
77
83
|
|
78
|
-
def self.load(file)
|
84
|
+
def self.load(file, require_file = true)
|
79
85
|
file = File.expand_path(file)
|
80
|
-
require file
|
86
|
+
require file if require_file
|
81
87
|
parser = RubyParser.new
|
82
88
|
sexp = parser.process(File.read(File.exist?(file) ? file : "#{file}.rb"))
|
83
89
|
method_args = Processor.new
|
@@ -166,25 +172,14 @@ module MethodArgs
|
|
166
172
|
end
|
167
173
|
|
168
174
|
def add_methods
|
169
|
-
unless current_class.method(:const_defined?).arity ==
|
175
|
+
unless current_class.method(:const_defined?).arity == -1 ? current_class.const_defined?(:ArgList, false) : current_class.const_defined?(:ArgList)
|
170
176
|
current_class.send(:const_set, :ArgList, @method_maps[current_classname])
|
171
177
|
current_class.module_eval(<<-HERE_DOC, __FILE__, __LINE__)
|
172
178
|
alias_method :__method__, :method
|
173
179
|
|
174
|
-
def method(name)
|
175
|
-
m = __method__(name)
|
176
|
-
m.args = self.class.instance_arg_list(name)
|
177
|
-
m
|
178
|
-
end
|
179
|
-
|
180
180
|
class << self
|
181
181
|
alias_method :__instance_method__, :instance_method unless method_defined?(:__instance_method__)
|
182
182
|
end
|
183
|
-
def self.instance_method(name)
|
184
|
-
m = __instance_method__(name)
|
185
|
-
m.args = instance_arg_list(name)
|
186
|
-
m
|
187
|
-
end
|
188
183
|
|
189
184
|
def self.instance_arg_list(method_name)
|
190
185
|
method = __instance_method__(method_name)
|
@@ -192,10 +187,6 @@ module MethodArgs
|
|
192
187
|
ArgList[method_name] or raise('i don\\'t know this method ' + method_name.inspect)
|
193
188
|
elsif method.owner.respond_to?(:instance_arg_list)
|
194
189
|
method.owner.instance_arg_list(method_name)
|
195
|
-
# elsif method.respond_to?(:source_location)
|
196
|
-
# source, line = method.source_location
|
197
|
-
# MethodArgs.load(source)
|
198
|
-
# method.owner.instance_arg_list(method_name)
|
199
190
|
else
|
200
191
|
raise \"\#{method.owner} has not been loaded with method_args\"
|
201
192
|
end
|
data/lib/method_args/version.rb
CHANGED
data/test/fixtures/4.rb
ADDED
data/test/test_bound_method.rb
CHANGED
@@ -12,4 +12,11 @@ class TestBoundMethod < MiniTest::Unit::TestCase
|
|
12
12
|
assert_equal 'more happy times', two.method(:default_args_with_dependant_value).args.last.default_value
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_binding_method
|
16
|
+
method = One.instance_method(:default_args_with_dependant_value)
|
17
|
+
one = One.new
|
18
|
+
one.two_method = 'happy times'
|
19
|
+
assert_equal 'happy times', method.bind(one).args.last.default_value
|
20
|
+
end
|
21
|
+
|
15
22
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method-args
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Joshua Hull
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-05 00:00:00 -08:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 2
|
32
30
|
- 0
|
@@ -41,7 +39,6 @@ dependencies:
|
|
41
39
|
requirements:
|
42
40
|
- - ~>
|
43
41
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 23
|
45
42
|
segments:
|
46
43
|
- 1
|
47
44
|
- 2
|
@@ -57,7 +54,6 @@ dependencies:
|
|
57
54
|
requirements:
|
58
55
|
- - ~>
|
59
56
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 15
|
61
57
|
segments:
|
62
58
|
- 3
|
63
59
|
- 0
|
@@ -73,7 +69,6 @@ dependencies:
|
|
73
69
|
requirements:
|
74
70
|
- - ~>
|
75
71
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 23
|
77
72
|
segments:
|
78
73
|
- 0
|
79
74
|
- 0
|
@@ -89,7 +84,6 @@ dependencies:
|
|
89
84
|
requirements:
|
90
85
|
- - ~>
|
91
86
|
- !ruby/object:Gem::Version
|
92
|
-
hash: 23
|
93
87
|
segments:
|
94
88
|
- 1
|
95
89
|
- 0
|
@@ -105,7 +99,6 @@ dependencies:
|
|
105
99
|
requirements:
|
106
100
|
- - ">="
|
107
101
|
- !ruby/object:Gem::Version
|
108
|
-
hash: 3
|
109
102
|
segments:
|
110
103
|
- 0
|
111
104
|
version: "0"
|
@@ -119,7 +112,6 @@ dependencies:
|
|
119
112
|
requirements:
|
120
113
|
- - ">="
|
121
114
|
- !ruby/object:Gem::Version
|
122
|
-
hash: 3
|
123
115
|
segments:
|
124
116
|
- 0
|
125
117
|
version: "0"
|
@@ -133,7 +125,6 @@ dependencies:
|
|
133
125
|
requirements:
|
134
126
|
- - ">="
|
135
127
|
- !ruby/object:Gem::Version
|
136
|
-
hash: 3
|
137
128
|
segments:
|
138
129
|
- 0
|
139
130
|
version: "0"
|
@@ -160,7 +151,9 @@ files:
|
|
160
151
|
- test/fixtures/1.rb
|
161
152
|
- test/fixtures/2.rb
|
162
153
|
- test/fixtures/3.rb
|
154
|
+
- test/fixtures/4.rb
|
163
155
|
- test/helper.rb
|
156
|
+
- test/test_autoload.rb
|
164
157
|
- test/test_block.rb
|
165
158
|
- test/test_bound_method.rb
|
166
159
|
- test/test_simple.rb
|
@@ -179,7 +172,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
172
|
requirements:
|
180
173
|
- - ">="
|
181
174
|
- !ruby/object:Gem::Version
|
182
|
-
hash: 3
|
183
175
|
segments:
|
184
176
|
- 0
|
185
177
|
version: "0"
|
@@ -188,7 +180,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
180
|
requirements:
|
189
181
|
- - ">="
|
190
182
|
- !ruby/object:Gem::Version
|
191
|
-
hash: 3
|
192
183
|
segments:
|
193
184
|
- 0
|
194
185
|
version: "0"
|
@@ -203,7 +194,9 @@ test_files:
|
|
203
194
|
- test/fixtures/1.rb
|
204
195
|
- test/fixtures/2.rb
|
205
196
|
- test/fixtures/3.rb
|
197
|
+
- test/fixtures/4.rb
|
206
198
|
- test/helper.rb
|
199
|
+
- test/test_autoload.rb
|
207
200
|
- test/test_block.rb
|
208
201
|
- test/test_bound_method.rb
|
209
202
|
- test/test_simple.rb
|