yard_ast_editable 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -24,6 +24,20 @@ module YardAstEditable
24
24
  @arguments.pop if @arguments.last == false
25
25
  @arguments
26
26
  end
27
+
28
+ def block_content_source
29
+ return nil unless block
30
+ result = block.source
31
+ case block.type
32
+ when :do_block then
33
+ result.sub!(/^do\s*(\|.*?\|)?\n?/, '')
34
+ result.sub!(/end$/, '')
35
+ when :brace_block then
36
+ result.sub!(/^\{\s*(\|.*?\|)?\n?/, '')
37
+ result.sub!(/\}$/, '')
38
+ end
39
+ result
40
+ end
27
41
  end
28
42
 
29
43
 
@@ -47,6 +61,16 @@ module YardAstEditable
47
61
  nil
48
62
  end
49
63
 
64
+ # def children_source
65
+ # ranges = children.map{|c| [c.comments_range, c.source_range] }.flatten.compact
66
+ # min_range = ranges.min_by(&:first)
67
+ # max_range = ranges.max_by(&:last)
68
+ # puts "min_range: #{min_range.inspect}"
69
+ # puts "max_range: #{max_range.inspect}"
70
+ # full_source[min_range.first..max_range.last]
71
+ # end
72
+
73
+
50
74
  def replace_source(node, new_source)
51
75
  result = full_source.dup
52
76
  result[node.source_range] = new_source
@@ -63,6 +63,34 @@ describe "YardAstEditable" do
63
63
  end
64
64
  end
65
65
 
66
+ describe :children_source do
67
+
68
+ it "do...endブロックの中身を取得" do
69
+ node = @ast.fcall_by_ident(:foo1){|fcall|
70
+ fcall.arguments.length == 2 && (n = fcall.arguments.first; n.source == ":name2")
71
+ }
72
+ fcall = YardAstEditable::Fcall.new(node)
73
+ fcall.block_content_source.should == %q{ # bar1 #3 S
74
+ bar1{ puts "name2 bar1" }
75
+ # bar1 #3 E
76
+ }
77
+ end
78
+
79
+ it "{}ブロックの中身を取得" do
80
+ node = @ast.fcall_by_ident(:bar1){|fcall|
81
+ fcall.arguments.length == 1 && (n = fcall.arguments.first; n.source == '"name2"')
82
+ }
83
+ fcall = YardAstEditable::Fcall.new(node)
84
+ fcall.block_content_source.should == %q{ # b2 S
85
+ puts b2.inspect
86
+ # b2 E
87
+ }
88
+ end
89
+
90
+ end
91
+
92
+
93
+
66
94
  describe :replace_source do
67
95
  it "全体に対して一部を置換" do
68
96
  node = @ast.fcall_by_ident(:foo1){|fcall|
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{yard_ast_editable}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["akimatter"]
12
- s.date = %q{2010-12-04}
12
+ s.date = %q{2010-12-06}
13
13
  s.description = %q{yard extension to modify source code by using AST Node}
14
14
  s.email = %q{akm2000@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - akimatter
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-04 00:00:00 +09:00
17
+ date: 2010-12-06 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
- hash: -3093227647333841452
129
+ hash: 3450069555588162524
130
130
  segments:
131
131
  - 0
132
132
  version: "0"