method_source 0.8.pre.2 → 0.8.pre.3

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.
@@ -13,14 +13,19 @@ module MethodSource
13
13
  # expressions that may have been valid inside an eval.
14
14
  # @return [String] The first complete expression
15
15
  # @raise [SyntaxError] If the first complete expression can't be identified
16
- def expression_at(file, line_number, strict=false)
16
+ def expression_at(file, line_number, options={})
17
+ options = {
18
+ :strict => false,
19
+ :consume => 0
20
+ }.merge!(options)
21
+
17
22
  lines = file.is_a?(Array) ? file : file.each_line.to_a
18
23
 
19
24
  relevant_lines = lines[(line_number - 1)..-1] || []
20
25
 
21
- extract_first_expression(relevant_lines)
26
+ extract_first_expression(relevant_lines, options[:consume])
22
27
  rescue SyntaxError => e
23
- raise if strict
28
+ raise if options[:strict]
24
29
 
25
30
  begin
26
31
  extract_first_expression(relevant_lines) do |code|
@@ -78,8 +83,9 @@ module MethodSource
78
83
  # @param [&Block] a clean-up function to run before checking for complete_expression
79
84
  # @return [String] a valid ruby expression
80
85
  # @raise [SyntaxError]
81
- def extract_first_expression(lines, &block)
82
- code = ""
86
+ def extract_first_expression(lines, consume=0, &block)
87
+ code = consume.zero? ? "" : lines.slice!(0..(consume - 1)).join
88
+
83
89
  lines.each do |v|
84
90
  code << v
85
91
  return code if complete_expression?(block ? block.call(code) : code)
@@ -1,3 +1,3 @@
1
1
  module MethodSource
2
- VERSION = "0.8.pre.2"
2
+ VERSION = "0.8.pre.3"
3
3
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "method_source"
5
- s.version = "0.8.pre.2"
5
+ s.version = "0.8.pre.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Mair (banisterfiend)"]
9
- s.date = "2012-06-03"
9
+ s.date = "2012-06-29"
10
10
  s.description = "retrieve the sourcecode for a method"
11
11
  s.email = "jrmair@gmail.com"
12
12
  s.files = [".gemtest", ".travis.yml", ".yardopts", "Gemfile", "LICENSE", "README.markdown", "Rakefile", "lib/method_source.rb", "lib/method_source/code_helpers.rb", "lib/method_source/source_location.rb", "lib/method_source/version.rb", "method_source.gemspec", "test/test.rb", "test/test_helper.rb"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.pre.2
4
+ version: 0.8.pre.3
5
5
  prerelease: 4
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-06-03 00:00:00.000000000 Z
12
+ date: 2012-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon