rogerdpack-desc_method 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,29 +18,37 @@ module SourceLocationDesc
18
18
  # TODO does this work with class methods?
19
19
  def desc want_just_summary = false, want_the_description_returned = false
20
20
  doc = []
21
-
21
+ #_dbg
22
22
  # to_s is something like "#<Method: String#strip>"
23
23
  # or #<Method: GiftCertsControllerTest(Test::Unit::TestCase)#get>
24
24
  # or "#<Method: A.go>"
25
- # or "#<Method: Order(id: integer, order_number: integer, created_on: datetime, shipped_on: datetime, order_user_id: integer, order_status_code_id: integer, notes: text, referer: string, order_shipping_type_id: integer, product_cost: float, shipping_cost: float, tax: float, auth_transaction_id: string, promotion_id: integer, shipping_address_id: integer, billing_address_id: integer, order_account_id: integer).get_cc_processor>"
25
+ # or "#<Method: Order(id: integer, order_number: integer).get_cc_processor>"
26
+ # or "#<Method: Order(id: integer, order_number: integer)(ActiveRecord::Base).get_cc_processor>"
26
27
 
27
28
  string = to_s
28
29
 
29
- if string.include? ')#'
30
+ # derive class_name
31
+ parenthese_count = string.count '('
32
+
33
+ if parenthese_count== 1
30
34
  # case #<Method: GiftCertsControllerTest(Test::Unit::TestCase)#get>
31
- string =~ /\((.*)\)/ # extract out what is between parentheses for the classname
32
- class_name = $1
33
- elsif string.include?( '(' ) && string.include?( ').' )
34
- # case "Method: Order(id:...).class_method"
35
- string =~ /Method: (.*)\(/
35
+ # case #<Method: Order(id: integer, order_number: integer).get_cc_processor>
36
+ if string.include? "id: " # TODO huh?
37
+ string =~ /Method: (.+)\(/
38
+ else
39
+ string =~ /\(([^\(]+)\)[\.#]/ # extract out what is between last parentheses
40
+ end
36
41
  class_name = $1
37
- elsif string =~ /Method: (.*)\..*>/
42
+ elsif parenthese_count == 0
38
43
  # case "#<Method: A.go>"
44
+ string =~ /Method: ([^#\.]+)/
39
45
  class_name = $1
40
- else
41
- # case "#<Method: String#strip>"
42
- string =~ /Method: (.*)#.*/
46
+ elsif parenthese_count == 2
47
+ # case "#<Method: Order(id: integer, order_number: integer)(ActiveRecord::Base).get_cc_processor>"
48
+ string =~ /\(([^\(]+)\)[\.#]/
43
49
  class_name = $1
50
+ else
51
+ raise 'bad ' + string
44
52
  end
45
53
 
46
54
  # now get method name, type
@@ -48,7 +56,7 @@ module SourceLocationDesc
48
56
  joiner = $1
49
57
  method_name = $2
50
58
  full_name = "#{class_name}#{joiner}#{method_name}"
51
- puts "#{to_s} arity: #{arity}"
59
+ puts "sig: #{to_s} arity: #{arity}"
52
60
  # TODO add to doc, I want it before ri for now though, and only once, so not there yet :)
53
61
 
54
62
  # now run default RI for it
@@ -76,12 +84,14 @@ module SourceLocationDesc
76
84
  out = []
77
85
  args.each{|arg_pair|
78
86
  out << arg_pair.join(' = ')
79
- }
87
+ } if args
80
88
  out = out.join(', ')
81
89
  return out if want_just_summary
82
90
 
83
- doc << "Parameters: #{method_name}(" + out + ")"
91
+ param_string = "Parameters: #{method_name}(" + out + ")"
92
+ doc << param_string unless want_the_description_returned
84
93
  rescue Exception => e
94
+
85
95
  puts "fail to parse tree: #{class_name} #{e} #{e.backtrace}" if $VERBOSE
86
96
  end
87
97
  else
@@ -115,6 +125,7 @@ module SourceLocationDesc
115
125
  else
116
126
  doc << 'appears to be a c method'
117
127
  end
128
+ param_string = to_s
118
129
  if respond_to? :parameters
119
130
  doc << "Original code signature: %s" % sig.to_s.strip if sig
120
131
  doc << "#parameters signature: %s( %p )" % [name, parameters]
@@ -124,9 +135,9 @@ module SourceLocationDesc
124
135
  puts doc # always output it since RI does currently [todo make optional I suppose, and non out-putty]
125
136
 
126
137
  if want_the_description_returned # give them something they can examine
127
- doc
138
+ doc
128
139
  else
129
- self
140
+ param_string
130
141
  end
131
142
  end
132
143
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rogerdpack-desc_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Pack
@@ -89,7 +89,6 @@ files:
89
89
  - lib/method_describer/method_desc.rb
90
90
  has_rdoc: false
91
91
  homepage: http://github.com/rogerdpack/method_describer
92
- licenses:
93
92
  post_install_message:
94
93
  rdoc_options: []
95
94
 
@@ -110,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
109
  requirements: []
111
110
 
112
111
  rubyforge_project:
113
- rubygems_version: 1.3.5
112
+ rubygems_version: 1.2.0
114
113
  signing_key:
115
114
  specification_version: 2
116
115
  summary: ruby method describer to make it possible to inspect methods [rdoc, signature, etc.] at runtime, for example while debugging.