drg 0.14.0 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/bin/console +1 -28
- data/lib/drg/ruby/condition.rb +16 -7
- data/lib/drg/ruby/const.rb +2 -2
- data/lib/drg/ruby.rb +1 -1
- data/lib/drg/version.rb +1 -1
- metadata +1 -6
- data/lib/drg/file_context.rb +0 -205
- data/lib/drg/file_reader.rb +0 -44
- data/lib/drg/judge.rb +0 -19
- data/lib/drg/let.rb +0 -4
- data/lib/drg/scanner.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8088ff21bcf344deaf9426041abe5010e50323b1
|
4
|
+
data.tar.gz: a1b79e42fcd4f995d4b50c7ae5cbe37e2082579f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b70bb0f245de6a2f573ab681277a3059406c41361d3913b54c09416546b88d1c2f0ff111d9533b30c7211c7922647adfc8ebaf432160aacf36db76e5c6102f7f
|
7
|
+
data.tar.gz: 3fd5f8dd60e0557065bcec396d66633ca53ae3f1f57c652d57b3908f3165855603d2a21fb6be43f9fec278d88f33377e759e308041a0ce814c8514a08c5559f3
|
data/README.md
CHANGED
@@ -77,11 +77,11 @@ describe Ability do
|
|
77
77
|
subject { described_class.new user }
|
78
78
|
|
79
79
|
describe "#initialize" do
|
80
|
-
context "when user.
|
80
|
+
context "when user.admin?" do
|
81
81
|
before {}
|
82
82
|
end
|
83
83
|
|
84
|
-
context "unless user.
|
84
|
+
context "unless user.admin?" do
|
85
85
|
before {}
|
86
86
|
end
|
87
87
|
end
|
data/bin/console
CHANGED
@@ -2,36 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'pp'
|
5
|
-
|
6
|
-
# require 'ruby2ruby'
|
7
|
-
# require 'ruby_parser'
|
8
|
-
|
9
5
|
require 'rspec'
|
6
|
+
require 'irb'
|
10
7
|
require 'object_tracker'
|
11
8
|
require_relative '../spec/spec_helper'
|
12
9
|
|
13
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
14
|
-
# with your gem easier. You can also use a different console, if you like.
|
15
|
-
|
16
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
17
|
-
# require 'pry'
|
18
|
-
# Pry.start
|
19
|
-
require 'irb'
|
20
|
-
|
21
|
-
def sexp
|
22
|
-
ruby = File.readlines(FIXTURE_ROOT.join 'report.rb').join
|
23
|
-
parser = RubyParser.new
|
24
|
-
ruby2ruby = Ruby2Ruby.new
|
25
|
-
parser.process(ruby)
|
26
|
-
# ruby2ruby.process(sexp)
|
27
|
-
end
|
28
|
-
|
29
|
-
def sexp_spec
|
30
|
-
ruby = File.readlines(FIXTURE_ROOT.join 'report_spec.rb').join
|
31
|
-
parser = RubyParser.new
|
32
|
-
ruby2ruby = Ruby2Ruby.new
|
33
|
-
parser.process(ruby)
|
34
|
-
# ruby2ruby.process(sexp)
|
35
|
-
end
|
36
|
-
|
37
10
|
IRB.start
|
data/lib/drg/ruby/condition.rb
CHANGED
@@ -7,13 +7,7 @@ class DRG::Ruby::Condition
|
|
7
7
|
def initialize(sexp)
|
8
8
|
@sexp = sexp
|
9
9
|
@statement = Ruby2Ruby.new.process(sexp.deep_clone)
|
10
|
-
@nested_conditions =
|
11
|
-
sexp.drop(1).flatten.include?(:if) && sexp.drop(1).deep_each do |exp|
|
12
|
-
DRG::Decorators::SexpDecorator.new(exp).each_sexp_condition do |node|
|
13
|
-
@nested_conditions << self.class.new(node)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
@nested_conditions = @nested_conditions.to_a
|
10
|
+
@nested_conditions = create_nested_conditions
|
17
11
|
end
|
18
12
|
|
19
13
|
def short_statement
|
@@ -49,4 +43,19 @@ class DRG::Ruby::Condition
|
|
49
43
|
def hash
|
50
44
|
sexp.object_id
|
51
45
|
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Private
|
49
|
+
#
|
50
|
+
|
51
|
+
def create_nested_conditions
|
52
|
+
nc = Set.new
|
53
|
+
s = sexp.drop(1)
|
54
|
+
s.flatten.include?(:if) && s.deep_each do |exp|
|
55
|
+
DRG::Decorators::SexpDecorator.new(exp).each_sexp_condition do |node|
|
56
|
+
nc << self.class.new(node)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
nc.to_a
|
60
|
+
end
|
52
61
|
end
|
data/lib/drg/ruby/const.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'ruby_parser'
|
2
2
|
|
3
3
|
class DRG::Ruby::Const
|
4
|
-
CONSTANT_DEFS = { :
|
4
|
+
CONSTANT_DEFS = { class: :class, module: :module, cdecl: :class }
|
5
5
|
|
6
6
|
attr_reader :sexp
|
7
7
|
|
8
8
|
# @param [Sexp] sexp
|
9
9
|
def initialize(sexp)
|
10
|
-
sexp = sexp
|
10
|
+
sexp = sexp[2] if sexp[0] == :block
|
11
11
|
@sexp = sexp
|
12
12
|
end
|
13
13
|
|
data/lib/drg/ruby.rb
CHANGED
data/lib/drg/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
@@ -147,17 +147,12 @@ files:
|
|
147
147
|
- lib/drg.rb
|
148
148
|
- lib/drg/decorators.rb
|
149
149
|
- lib/drg/decorators/sexp_decorator.rb
|
150
|
-
- lib/drg/file_context.rb
|
151
|
-
- lib/drg/file_reader.rb
|
152
|
-
- lib/drg/judge.rb
|
153
|
-
- lib/drg/let.rb
|
154
150
|
- lib/drg/ruby.rb
|
155
151
|
- lib/drg/ruby/class_func.rb
|
156
152
|
- lib/drg/ruby/condition.rb
|
157
153
|
- lib/drg/ruby/const.rb
|
158
154
|
- lib/drg/ruby/func.rb
|
159
155
|
- lib/drg/ruby/instance_func.rb
|
160
|
-
- lib/drg/scanner.rb
|
161
156
|
- lib/drg/spec.rb
|
162
157
|
- lib/drg/tasks.rb
|
163
158
|
- lib/drg/tasks/active_pinner.rb
|
data/lib/drg/file_context.rb
DELETED
@@ -1,205 +0,0 @@
|
|
1
|
-
module DRG
|
2
|
-
class FileContext
|
3
|
-
# = Class
|
4
|
-
# First attempt at reading ruby files. It was a pipe dream. See DRG::Ruby for the real stuff ;)
|
5
|
-
#
|
6
|
-
|
7
|
-
attr_writer :lines
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@lines = Set.new
|
11
|
-
@is_private = false
|
12
|
-
end
|
13
|
-
|
14
|
-
def add(raw_line, index = 0)
|
15
|
-
line_number = index + 1
|
16
|
-
line = parse_line(raw_line, line_number)
|
17
|
-
@lines << line
|
18
|
-
line
|
19
|
-
end
|
20
|
-
|
21
|
-
def inspect
|
22
|
-
%Q(#<DRG::FileContext:#{object_id} @lines=#{@lines.count}>, @is_private=false, @is_protected=false>)
|
23
|
-
end
|
24
|
-
|
25
|
-
def lines
|
26
|
-
@lines.to_a
|
27
|
-
end
|
28
|
-
|
29
|
-
=begin
|
30
|
-
|
31
|
-
def set_name *args
|
32
|
-
def get_name
|
33
|
-
def [](other)
|
34
|
-
def +
|
35
|
-
def -
|
36
|
-
def <=>
|
37
|
-
def /
|
38
|
-
def eql?
|
39
|
-
|
40
|
-
=end
|
41
|
-
def parse_line(line, line_number)
|
42
|
-
case line.to_s.chomp.strip
|
43
|
-
when /\A(=begin|=end)/
|
44
|
-
nil
|
45
|
-
when /class\s+([A-Z]+\w*)/
|
46
|
-
return ClassDef.new($1, line_number)
|
47
|
-
when /module\s+([A-Z]+\w*)/
|
48
|
-
return ModuleDef.new($1, line_number)
|
49
|
-
when /def self\.([a-z0-9\[\]_+-<=>?]+)\s*\(?/
|
50
|
-
# @todo check if within class << self
|
51
|
-
return ClassMethodDef.new($1, line_number, current_class_or_module, @is_private)
|
52
|
-
when /def ([a-z0-9\[\]_+-<=>?]+)\s*\(?/
|
53
|
-
return InstanceMethodDef.new($1, line_number, current_class_or_module, @is_private)
|
54
|
-
when /(.+)\s*(do|\{)(.*)(\}|end)/
|
55
|
-
return BlockDef.new($1, $2, $3, line_number, $4)
|
56
|
-
when /(.+)\s*(do|\{)(.*)/
|
57
|
-
return BlockDef.new($1, $2, $3, line_number)
|
58
|
-
when /#*\s*(private|protected)\b/i
|
59
|
-
@is_private = true
|
60
|
-
when /#*\s*public[\s\n]+/i
|
61
|
-
@is_private = false
|
62
|
-
when /\A(end|\})\b/i
|
63
|
-
close_current_definition unless current_definition.method?
|
64
|
-
else
|
65
|
-
nil
|
66
|
-
end
|
67
|
-
NullLine.new(line)
|
68
|
-
end
|
69
|
-
|
70
|
-
def current_definition
|
71
|
-
lines.reverse.detect { |line| line.open? } || Definition.new
|
72
|
-
end
|
73
|
-
|
74
|
-
def close_current_definition
|
75
|
-
current_definition.close
|
76
|
-
end
|
77
|
-
|
78
|
-
def current_class_or_module
|
79
|
-
current_definition = lines.reverse.detect { |line| line.open? && (line.class? || line.mod?) }
|
80
|
-
current_definition && current_definition.name
|
81
|
-
end
|
82
|
-
|
83
|
-
def classes
|
84
|
-
lines.select { |line| line.class? }
|
85
|
-
end
|
86
|
-
|
87
|
-
def modules
|
88
|
-
lines.select { |line| line.mod? }
|
89
|
-
end
|
90
|
-
|
91
|
-
def blocks
|
92
|
-
lines.select { |line| line.block? }
|
93
|
-
end
|
94
|
-
|
95
|
-
def methods
|
96
|
-
lines.select { |line| line.method? }
|
97
|
-
end
|
98
|
-
|
99
|
-
def last_method
|
100
|
-
lines.reverse.detect { |line| line.method? }
|
101
|
-
end
|
102
|
-
|
103
|
-
def last_class
|
104
|
-
lines.reverse.detect { |line| line.class? }
|
105
|
-
end
|
106
|
-
|
107
|
-
module NullDefinition
|
108
|
-
def class?
|
109
|
-
false
|
110
|
-
end
|
111
|
-
|
112
|
-
def mod?
|
113
|
-
false
|
114
|
-
end
|
115
|
-
|
116
|
-
def method?
|
117
|
-
false
|
118
|
-
end
|
119
|
-
|
120
|
-
def block?
|
121
|
-
false
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
class NullLine < DelegateClass(String)
|
126
|
-
include NullDefinition
|
127
|
-
|
128
|
-
def eql?(*)
|
129
|
-
false
|
130
|
-
end
|
131
|
-
|
132
|
-
def open?
|
133
|
-
false
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
class Definition < Object
|
138
|
-
include NullDefinition
|
139
|
-
attr_accessor :open, :name, :line_number
|
140
|
-
|
141
|
-
def initialize(name = nil, line_number = nil, open = true)
|
142
|
-
@name, @line_number, @open = name, line_number.to_i, open
|
143
|
-
end
|
144
|
-
|
145
|
-
def inspect
|
146
|
-
%Q(#<#{self.class.name} #{instance_variables.map { |i| %Q(#{i}="#{instance_variable_get(i)}") }.join(', ')}>)
|
147
|
-
end
|
148
|
-
|
149
|
-
alias to_s inspect
|
150
|
-
|
151
|
-
def eql?(other)
|
152
|
-
@name == other.name && @line_number == other.line_number
|
153
|
-
end
|
154
|
-
|
155
|
-
def close
|
156
|
-
@open = false
|
157
|
-
end
|
158
|
-
|
159
|
-
alias open? open
|
160
|
-
alias hash line_number
|
161
|
-
end
|
162
|
-
|
163
|
-
class MethodDefinition < Definition
|
164
|
-
attr_accessor :class_name, :is_private
|
165
|
-
|
166
|
-
def initialize(name, line_number, class_name, is_private)
|
167
|
-
super(name, line_number, false)
|
168
|
-
@class_name, @is_private = class_name, is_private
|
169
|
-
end
|
170
|
-
|
171
|
-
def method?
|
172
|
-
true
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
class ClassDef < Definition
|
177
|
-
def class?
|
178
|
-
true
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
class ModuleDef < Definition
|
183
|
-
def mod?
|
184
|
-
true
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
class ClassMethodDef < MethodDefinition
|
189
|
-
end
|
190
|
-
|
191
|
-
class InstanceMethodDef < MethodDefinition
|
192
|
-
end
|
193
|
-
|
194
|
-
class BlockDef < Definition
|
195
|
-
def initialize(name, body, opener, line_number, closer = nil)
|
196
|
-
super(name, line_number, !!closer) # not open if closer present (single line block)
|
197
|
-
@body, @opener, @closer, = body, opener, closer
|
198
|
-
end
|
199
|
-
|
200
|
-
def block?
|
201
|
-
true
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
data/lib/drg/file_reader.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module DRG
|
2
|
-
class FileReader
|
3
|
-
# = Class
|
4
|
-
# Needs to keep track of the context of the file as we scan each line (e.g. what class the
|
5
|
-
# current method is defined). As well as an efficient way to loop through the lines
|
6
|
-
# @todo add SpecReader
|
7
|
-
#
|
8
|
-
|
9
|
-
include Enumerable
|
10
|
-
|
11
|
-
def initialize(file_path)
|
12
|
-
@file_path = file_path
|
13
|
-
end
|
14
|
-
|
15
|
-
def each
|
16
|
-
return to_enum unless block_given?
|
17
|
-
File.open(@file_path) do |f|
|
18
|
-
while line = f.gets
|
19
|
-
yield line
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def each_with_context
|
25
|
-
return enum_for __method__ unless block_given?
|
26
|
-
@context = nil
|
27
|
-
each_with_index do |line, i|
|
28
|
-
current_line = context.add(line, i)
|
29
|
-
yield current_line, context
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def read
|
34
|
-
@context = nil
|
35
|
-
each_with_index do |line, i|
|
36
|
-
context.add(line, i)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def context
|
41
|
-
@context ||= FileContext.new
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/drg/judge.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module DRG
|
2
|
-
class Judge
|
3
|
-
attr_reader :spec, :file
|
4
|
-
|
5
|
-
def initialize(file, spec)
|
6
|
-
@file, @spec = file, spec
|
7
|
-
end
|
8
|
-
|
9
|
-
def missing_methods
|
10
|
-
describes = DRG::Scanner.new(spec).describes
|
11
|
-
DRG::Scanner.new(file).methods.select { |method_name|
|
12
|
-
describes.detect { |describe_name|
|
13
|
-
# turn Report.name or Report#name into .name and #name
|
14
|
-
describe_name[/#{Regexp.escape(method_name.sub(/^\w+(\.|#)/, '\1'))}/i]
|
15
|
-
}.nil?
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/drg/let.rb
DELETED
data/lib/drg/scanner.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module DRG
|
2
|
-
autoload :Let, 'drg/let'
|
3
|
-
|
4
|
-
class Scanner
|
5
|
-
attr_reader :file
|
6
|
-
|
7
|
-
def initialize(file)
|
8
|
-
@file = file
|
9
|
-
end
|
10
|
-
|
11
|
-
def lets
|
12
|
-
_lets = []
|
13
|
-
continuation = false
|
14
|
-
File.readlines(file).each do |line|
|
15
|
-
if continuation && continuation = line.strip != 'end'
|
16
|
-
_lets[-1].value << line
|
17
|
-
elsif line =~ /\A\s+let\(?:(\w+)\)?\s*do\s*\n/
|
18
|
-
continuation = true
|
19
|
-
_lets << Let.new($1.strip, '')
|
20
|
-
elsif line =~ /\A\s+let\(?:(\w+)\)?\s*\{(.+)\}/m
|
21
|
-
_lets << Let.new($1.strip, $2.strip)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
_lets
|
25
|
-
end
|
26
|
-
|
27
|
-
def indentation
|
28
|
-
line = nil
|
29
|
-
File.open(file) do |f|
|
30
|
-
previous_line = nil
|
31
|
-
until indent_size(previous_line) != indent_size(line = f.gets)
|
32
|
-
previous_line = line
|
33
|
-
end
|
34
|
-
end
|
35
|
-
indent_size(line)
|
36
|
-
end
|
37
|
-
|
38
|
-
def methods
|
39
|
-
items = []
|
40
|
-
klasses = Set.new
|
41
|
-
File.readlines(file).each do |line|
|
42
|
-
if line =~ /class (\w+)/
|
43
|
-
klasses << $1
|
44
|
-
end
|
45
|
-
case line.to_s.chomp.strip
|
46
|
-
when /#?\s*private/i
|
47
|
-
break
|
48
|
-
when /def (self)?(\.?[a-z0-9_]+)/
|
49
|
-
method_name = $2
|
50
|
-
if method_name !~ /\A\./
|
51
|
-
method_name = "##{method_name}"
|
52
|
-
end
|
53
|
-
items << "#{klasses.to_a.join('::')}#{method_name}"
|
54
|
-
else
|
55
|
-
nil
|
56
|
-
end
|
57
|
-
end
|
58
|
-
items
|
59
|
-
end
|
60
|
-
|
61
|
-
def describes
|
62
|
-
File.readlines(file).map { |line| $2 if line =~ /(describe|context)\s*['"%](.+)\s*['"%]/ }.compact
|
63
|
-
end
|
64
|
-
|
65
|
-
def indent_size(line)
|
66
|
-
line.to_s.chomp.rstrip[/\s{0,}/].size.to_i
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|