motion_blender 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/motion_blender/analyzer/evaluator.rb +1 -1
- data/lib/motion_blender/analyzer/parser.rb +8 -30
- data/lib/motion_blender/analyzer/require.rb +47 -0
- data/lib/motion_blender/analyzer.rb +3 -4
- data/lib/motion_blender/version.rb +1 -1
- data/lib/motion_blender.rb +23 -5
- data/motion/ext.rb +8 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12f4f266de541f71f053210f9b089eb7a56fb77b
|
4
|
+
data.tar.gz: f30217e63c3c013a07862c1ea6f4413b749f6b26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bbca25180fa862d2cdf18dc13589a6dfe8260b6972c19c4be497e25a48519571afe21537281111553f24a6114961262fe5c622b9cd344f7c5d1c918ca2db2f1
|
7
|
+
data.tar.gz: dc18bde83fe86c28bdd3e4fbbaf38ea7e8fc0c5a04c92acb3b51ef6ba843918b524d97af251ee98fcb46a8de404d284bfce475fab8cb5bd9d0ce2e703a5aabbe
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ module MotionBlender
|
|
13
13
|
def parse_args
|
14
14
|
extractor = create_extractor
|
15
15
|
extractor.instance_eval(@ast.loc.expression.source, @file)
|
16
|
-
extractor.instance_eval { @args }
|
16
|
+
extractor.instance_eval { @args || [] }
|
17
17
|
rescue
|
18
18
|
if stack.any?
|
19
19
|
Evaluator.new(@file, stack.last, stack[0..-2], @method).parse_args
|
@@ -2,15 +2,15 @@ require 'parser/current'
|
|
2
2
|
require 'pathname'
|
3
3
|
|
4
4
|
require 'motion_blender/analyzer/evaluator'
|
5
|
+
require 'motion_blender/analyzer/require'
|
5
6
|
|
6
7
|
module MotionBlender
|
7
8
|
class Analyzer
|
8
9
|
class Parser
|
9
10
|
REQUIREMENT_TOKENS = %i(motion_require require_relative require)
|
10
11
|
|
11
|
-
Require = Struct.new(:loader, :method, :arg, :file, :trace)
|
12
|
-
|
13
12
|
attr_reader :file, :requires, :last_trace
|
13
|
+
attr_accessor :exclude_files
|
14
14
|
|
15
15
|
def initialize file
|
16
16
|
@file = file.to_s
|
@@ -19,19 +19,21 @@ module MotionBlender
|
|
19
19
|
|
20
20
|
def parse
|
21
21
|
ast = ::Parser::CurrentRuby.parse(File.read(@file))
|
22
|
-
traverse ast
|
22
|
+
traverse ast if ast
|
23
23
|
end
|
24
24
|
|
25
25
|
def traverse ast, stack = []
|
26
|
-
|
26
|
+
@exclude_files ||= Set.new
|
27
|
+
if ast.type == :send && require_command?(ast)
|
27
28
|
@last_trace = trace_for ast
|
28
29
|
Evaluator.new(@file, ast, stack).parse_args.each do |arg|
|
29
30
|
req = Require.new(@file, ast.children[1], arg)
|
30
|
-
|
31
|
+
next if @exclude_files.include? req.arg
|
32
|
+
next if @exclude_files.include? req.file
|
31
33
|
req.trace = @last_trace
|
32
34
|
@requires << req
|
33
35
|
end
|
34
|
-
|
36
|
+
else
|
35
37
|
ast.children
|
36
38
|
.select { |node| node.is_a?(::Parser::AST::Node) }
|
37
39
|
.each { |node| traverse node, [*stack, ast] }
|
@@ -45,30 +47,6 @@ module MotionBlender
|
|
45
47
|
def trace_for ast
|
46
48
|
"#{@file}:#{ast.loc.line}:in `#{ast.children[1]}'"
|
47
49
|
end
|
48
|
-
|
49
|
-
def resolve_path method, arg
|
50
|
-
if %i(motion_require require_relative).include? method
|
51
|
-
arg = Pathname.new(@file).dirname.join(arg).to_s
|
52
|
-
end
|
53
|
-
path = candidates_for(arg, method == :require).find(&:file?)
|
54
|
-
fail LoadError, "not found `#{arg}'" unless path
|
55
|
-
explicit_relative path
|
56
|
-
end
|
57
|
-
|
58
|
-
def candidates_for feature, uses_load_path
|
59
|
-
path = Pathname.new(feature)
|
60
|
-
dirs = (uses_load_path && path.relative?) ? $LOAD_PATH : ['']
|
61
|
-
exts = path.extname.empty? ? ['', '.rb'] : ['']
|
62
|
-
Enumerator.new do |y|
|
63
|
-
dirs.product(exts).each do |dir, ext|
|
64
|
-
y << Pathname.new(dir).join("#{path}#{ext}")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def explicit_relative path
|
70
|
-
path.to_s.sub(%r{^(?![\./])}, './')
|
71
|
-
end
|
72
50
|
end
|
73
51
|
end
|
74
52
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module MotionBlender
|
2
|
+
class Analyzer
|
3
|
+
class Require
|
4
|
+
attr_accessor :loader, :method, :arg, :trace
|
5
|
+
|
6
|
+
def initialize loader, method, arg
|
7
|
+
@loader = loader
|
8
|
+
@method = method
|
9
|
+
@arg = arg
|
10
|
+
end
|
11
|
+
|
12
|
+
def file
|
13
|
+
@file ||= resolve_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def resolve_path
|
17
|
+
path = candidates.find(&:file?)
|
18
|
+
fail LoadError, "not found `#{arg}'" unless path
|
19
|
+
explicit_relative path
|
20
|
+
end
|
21
|
+
|
22
|
+
def candidates
|
23
|
+
path =
|
24
|
+
if %i(motion_require require_relative).include? method
|
25
|
+
Pathname.new(loader).dirname.join(arg)
|
26
|
+
else
|
27
|
+
Pathname.new(arg)
|
28
|
+
end
|
29
|
+
dirs = (uses_load_path? && path.relative?) ? $LOAD_PATH : ['']
|
30
|
+
exts = path.extname.empty? ? ['', '.rb'] : ['']
|
31
|
+
Enumerator.new do |y|
|
32
|
+
dirs.product(exts).each do |dir, ext|
|
33
|
+
y << Pathname.new(dir).join("#{path}#{ext}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def explicit_relative path
|
39
|
+
path.to_s.sub(%r{^(?![\./])}, './')
|
40
|
+
end
|
41
|
+
|
42
|
+
def uses_load_path?
|
43
|
+
method == :require
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -20,19 +20,18 @@ module MotionBlender
|
|
20
20
|
@analyzed_files << file
|
21
21
|
|
22
22
|
parser = Parser.new file
|
23
|
+
parser.exclude_files = @exclude_files
|
23
24
|
begin
|
24
25
|
parser.parse
|
25
26
|
rescue LoadError => err
|
26
27
|
err.set_backtrace [parser.last_trace, *backtrace].compact
|
27
28
|
raise err
|
28
29
|
end
|
29
|
-
requires = parser.requires.reject do |req|
|
30
|
-
@exclude_files.include? req.file
|
31
|
-
end
|
32
30
|
|
31
|
+
requires = parser.requires
|
33
32
|
if requires.any?
|
34
33
|
@dependencies[file] = requires.map(&:file)
|
35
|
-
@files =
|
34
|
+
@files = [*@files, file, *@dependencies[file]].uniq
|
36
35
|
requires.each do |req|
|
37
36
|
analyze req.file, [req.trace, *backtrace]
|
38
37
|
end
|
data/lib/motion_blender.rb
CHANGED
@@ -9,6 +9,7 @@ module MotionBlender
|
|
9
9
|
Motion::Project::App.setup do |app|
|
10
10
|
analyzer = Analyzer.new
|
11
11
|
analyzer.exclude_files += Dir[File.expand_path('../**/*.rb', __FILE__)]
|
12
|
+
analyzer.exclude_files += builtin_features
|
12
13
|
app.files.flatten.each do |file|
|
13
14
|
analyzer.analyze file
|
14
15
|
end
|
@@ -21,15 +22,32 @@ module MotionBlender
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
def add file
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def add file = nil
|
26
|
+
return unless motion?
|
27
|
+
|
28
|
+
file ||= caller.first.split(':', 2).first
|
29
|
+
Motion::Project::App.setup do |app|
|
30
|
+
app.files.unshift file
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
34
|
+
def use_motion_dir dir = nil
|
35
|
+
return unless motion?
|
36
|
+
|
37
|
+
dir ||= File.expand_path('../../motion', caller.first.split(':', 2).first)
|
38
|
+
$LOAD_PATH.delete dir
|
39
|
+
$LOAD_PATH.unshift dir
|
40
|
+
end
|
41
|
+
|
42
|
+
def motion?
|
43
|
+
defined?(Motion::Project::Config)
|
44
|
+
end
|
45
|
+
|
32
46
|
def ext_file
|
33
47
|
File.expand_path('../../motion/ext.rb', __FILE__)
|
34
48
|
end
|
49
|
+
|
50
|
+
def builtin_features
|
51
|
+
%w(bigdecimal date thread)
|
52
|
+
end
|
35
53
|
end
|
data/motion/ext.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion_blender
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kayhide
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -230,6 +230,7 @@ files:
|
|
230
230
|
- lib/motion_blender/analyzer/evaluator.rb
|
231
231
|
- lib/motion_blender/analyzer/hooker.rb
|
232
232
|
- lib/motion_blender/analyzer/parser.rb
|
233
|
+
- lib/motion_blender/analyzer/require.rb
|
233
234
|
- lib/motion_blender/rake_tasks.rb
|
234
235
|
- lib/motion_blender/version.rb
|
235
236
|
- motion/ext.rb
|