live_ast 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.rdoc CHANGED
@@ -1,6 +1,11 @@
1
1
 
2
2
  = live_ast Changes
3
3
 
4
+ == Version 0.6.2
5
+
6
+ * simplified irb handling; readline no longer required
7
+ * add -e notes to readme
8
+
4
9
  == Version 0.6.1
5
10
 
6
11
  * enable usage inside irb
data/README.rdoc CHANGED
@@ -162,6 +162,9 @@ or blocks in order for its AST to be available.
162
162
  a = lambda { } ; b = lambda { }
163
163
  a.to_ast # => raises LiveAST::MultipleDefinitionsOnSameLineError
164
164
 
165
+ Code given to the <code>-e</code> command-line switch is not
166
+ AST-accessible.
167
+
165
168
  ----
166
169
 
167
170
  == <em>Technical Issues</em>
data/devel/levitate.rb CHANGED
@@ -250,7 +250,7 @@ class Levitate
250
250
  include Util
251
251
 
252
252
  def initialize(gem_name)
253
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
253
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
254
254
 
255
255
  require 'rubygems/package_task'
256
256
 
@@ -402,7 +402,7 @@ class Levitate
402
402
  end
403
403
 
404
404
  attribute :extra_rdoc_files do
405
- File.file?(readme_file) ? [readme_file] : []
405
+ [readme_file, history_file].select { |file| File.file?(file) }
406
406
  end
407
407
 
408
408
  attribute :browser do
@@ -478,9 +478,11 @@ class Levitate
478
478
  begin
479
479
  sections[send("#{section}_section")].
480
480
  gsub("\n", " ").
481
- split(%r!\.\s*!m).
481
+ split(%r!\.\s+!m).
482
482
  first(send("#{section}_sentences")).
483
- join(". ") << "."
483
+ join(". ").
484
+ concat(".").
485
+ sub(%r!\.+\Z!, ".")
484
486
  rescue
485
487
  "FIXME: #{section}"
486
488
  end
@@ -749,7 +751,11 @@ class Levitate
749
751
 
750
752
  def define_changes
751
753
  task :changes do
752
- header = "\n\n== Version ____\n\n"
754
+ if File.read(history_file).index version
755
+ raise "version not updated"
756
+ end
757
+
758
+ header = "\n\n== Version #{version}\n\n"
753
759
 
754
760
  bullets = `git log --format=%s #{last_release}..HEAD`.lines.map { |line|
755
761
  "* #{line}"
data/lib/live_ast/base.rb CHANGED
@@ -5,7 +5,7 @@ require 'live_ast/evaler'
5
5
  require 'live_ast/linker'
6
6
  require 'live_ast/loader'
7
7
  require 'live_ast/error'
8
- require 'live_ast/irb_spy' if defined?(IRB) && defined?(Readline::HISTORY)
8
+ require 'live_ast/irb_spy' if defined?(IRB)
9
9
 
10
10
  module LiveAST
11
11
  NATIVE_EVAL = Kernel.method(:eval) #:nodoc:
@@ -1,74 +1,37 @@
1
- #
2
- # Some hacks to get LiveAST working with IRB.
3
- #
4
- # (1) Because Readline::HISTORY is empty at startup, we count the
5
- # lines of the history file in order to determine where the new
6
- # history begins for this IRB session.
7
- #
8
- # (2) IRB::ReadlineInputMethod#gets discards empty input lines,
9
- # causing Readline::HISTORY to be out of sync with the current line
10
- # number, thereby fouling up source_location. We redefine #gets to
11
- # keep empty lines.
12
- #
13
1
 
14
2
  module LiveAST
15
3
  module IRBSpy
16
- class << self
17
- def code_at(line)
18
- history = Readline::HISTORY.to_a
19
- start = @history_start + line - 1
20
- grow = 0
21
- begin
22
- code = history[start..(start + grow)].join("\n")
23
- LiveAST.parser.new.parse(code) or raise "#{LiveAST.parser} error"
24
- rescue
25
- grow += 1
26
- retry if start + grow < history.size
27
- raise
28
- end
29
- code
4
+ def self.code_at(line)
5
+ unless defined?(@history)
6
+ raise NotImplementedError,
7
+ "LiveAST cannot access history for this IRB input method"
30
8
  end
31
-
32
- #
33
- # Find the starting point of history for this IRB session.
34
- #
35
- def find_history_start
36
- if IRB.conf[:HISTORY_FILE]
37
- # cut & paste from irb/ext/save-history.rb
38
- if history_file = IRB.conf[:HISTORY_FILE]
39
- history_file = File.expand_path(history_file)
40
- end
41
- history_file = IRB.rc_file("_history") unless history_file
42
-
43
- if File.exist?(history_file)
44
- File.readlines(history_file).size
45
- else
46
- 0
47
- end
48
- else
49
- 0
50
- end
9
+ grow = 0
10
+ begin
11
+ code = @history[line..(line + grow)].join
12
+ LiveAST.parser.new.parse(code) or raise "#{LiveAST.parser} error"
13
+ rescue
14
+ grow += 1
15
+ retry if line + grow < @history.size
16
+ raise
51
17
  end
18
+ code
52
19
  end
53
-
54
- @history_start = find_history_start
55
20
  end
56
21
  end
57
22
 
58
- #
59
- # From irb/input-method.rb.
60
- #
61
- class IRB::ReadlineInputMethod
62
- alias_method :live_ast_original_gets, :gets
63
- def gets
64
- Readline.input = @stdin
65
- Readline.output = @stdout
66
- if l = readline(@prompt, false)
67
- HISTORY.push(l) #if !l.empty? # <---- only this line modified
68
- @line[@line_no += 1] = l + "\n"
69
- else
70
- @eof = true
71
- l
23
+ [
24
+ IRB::StdioInputMethod,
25
+ defined?(IRB::ReadlineInputMethod) ? IRB::ReadlineInputMethod : nil,
26
+ ].compact.each do |klass|
27
+ klass.module_eval do
28
+ alias_method :live_ast_original_gets, :gets
29
+ def gets
30
+ live_ast_original_gets.tap do
31
+ if defined?(@line)
32
+ LiveAST::IRBSpy.instance_variable_set(:@history, @line)
33
+ end
34
+ end
72
35
  end
73
36
  end
74
37
  end
@@ -83,9 +83,6 @@ module LiveAST
83
83
  if !cache and !file.index(REVISION_TOKEN)
84
84
  _, cache =
85
85
  if defined?(IRB) and file == "(irb)"
86
- unless defined? Readline::HISTORY
87
- raise "LiveAST requires readline enabled in irb."
88
- end
89
86
  new_cache(IRBSpy.code_at(line), file, line, false)
90
87
  else
91
88
  #
@@ -1,3 +1,3 @@
1
1
  module LiveAST
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
data/test/irb_test.rb CHANGED
@@ -10,28 +10,15 @@ class IRBTest < RegularTest
10
10
  end
11
11
  end
12
12
 
13
- def test_readline_not_present
14
- with_module(Object, :IRB) do
15
- error = assert_raises RuntimeError do
16
- LiveAST::Linker.fetch_from_cache("(irb)", 33)
17
- end
18
- assert_match(/readline enabled/, error.message)
19
- end
20
- end
21
-
22
13
  def test_irb
23
14
  with_module(Object, :IRB) do
24
- with_module(Object, :Readline) do
25
- with_module(Readline, :HISTORY) do
26
- with_module(LiveAST, :IRBSpy) do
27
- LiveAST::IRBSpy.class_eval do
28
- def self.code_at(line)
29
- "def f ; end"
30
- end
31
- end
32
- LiveAST::Linker.fetch_from_cache("(irb)", 1)
15
+ with_module(LiveAST, :IRBSpy) do
16
+ LiveAST::IRBSpy.class_eval do
17
+ def self.code_at(line)
18
+ "def f ; end"
33
19
  end
34
20
  end
21
+ LiveAST::Linker.fetch_from_cache("(irb)", 1)
35
22
  end
36
23
  end
37
24
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: live_ast
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.1
5
+ version: 0.6.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - James M. Lawrence
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-01 00:00:00 -05:00
13
+ date: 2011-03-09 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -33,6 +33,7 @@ extensions: []
33
33
 
34
34
  extra_rdoc_files:
35
35
  - README.rdoc
36
+ - CHANGES.rdoc
36
37
  files:
37
38
  - CHANGES.rdoc
38
39
  - README.rdoc