ruby_require_inline 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f04dda8ad92f3f9fda20285a152b432417667be
4
+ data.tar.gz: 4186f885ac0dca51d914534a115b0f1ac5e71659
5
+ SHA512:
6
+ metadata.gz: f109df804eb40febef89d694cdd77e7e69005969a1d264070c45a9e9f6374a3ecd969c00bf7df933275156d24ddb8d0a1d76cbcb5ee48ed0dd608999919da417
7
+ data.tar.gz: b6c62e57633af705bd49b031e373025a1a53f573508b61b708fc123b2d6482590fc594d548dfa10cb2a75b2fe51d9cd749fef2ed99700da9f3c6b7463445d746
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ph
data/.rdoc_options ADDED
@@ -0,0 +1,20 @@
1
+ --- !ruby/object:RDoc::Options
2
+ encoding: UTF-8
3
+ static_path: []
4
+ rdoc_include:
5
+ - .
6
+ - /home/alex/lib/software/example/ruby/require_inline
7
+ charset: UTF-8
8
+ exclude:
9
+ hyperlink_all: false
10
+ line_numbers: false
11
+ main_page:
12
+ markup: markdown
13
+ output_decoration: true
14
+ page_dir:
15
+ show_hash: false
16
+ tab_width: 8
17
+ template_stylesheets: []
18
+ title:
19
+ visibility: :protected
20
+ webcvs:
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_require_inline.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # ruby_require_inline
2
+
3
+ Recursively goes through ruby 'require' statements & prints a tree of
4
+ dependencies.
5
+
6
+ It does it by parsing .rb files, so it'll find only 'static'
7
+ declarations. Unfortunately, this won't be picked up:
8
+
9
+ foo = 'bar'
10
+ require foo
11
+
12
+ Only
13
+
14
+ require 'bar'
15
+ require './bar'
16
+ require_relative '../bar'
17
+
18
+ & so on will work.
19
+
20
+ See https://github.com/gromnitsky/minirake as an example where it can be
21
+ useful.
22
+
23
+ ## Installation
24
+
25
+ gem install ruby_require_inline
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ $ ruby_require_deps -h
31
+ Usage: ruby_require_deps [-p path] [-o output] input
32
+ -p DIR Add path for additional deps search
33
+ -o FILE Output file instead of stdout
34
+ --flat Print a simple list instead of a tree
35
+ -V, --version Version info & $:
36
+
37
+ ```
38
+
39
+ Dump a tree:
40
+
41
+ ```
42
+ $ ruby_require_deps ~/.rvm/src/ruby-2.0.0-p247/lib/irb.rb
43
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb.rb
44
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/e2mmap.rb
45
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/init.rb
46
+ irb/error.rb (not local)
47
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/help.rb
48
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/magic-file.rb
49
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/context.rb
50
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/workspace.rb
51
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/tempfile.rb
52
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/delegate.rb
53
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/tmpdir.rb
54
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/fileutils.rb
55
+ etc (not local)
56
+ etc.so (not local)
57
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/thread.rb
58
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/inspector.rb
59
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/pp.rb
60
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/prettyprint.rb
61
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/yaml.rb
62
+ psych (not local)
63
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/extend-command.rb
64
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/ruby-lex.rb
65
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/slex.rb
66
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/notifier.rb
67
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/output-method.rb
68
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/ruby-token.rb
69
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/input-method.rb
70
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/src_encoding.rb
71
+ readline (not local)
72
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/locale.rb
73
+ irb/encoding_aliases.rb (not local)
74
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/version.rb
75
+ ```
76
+
77
+ Use `-p` to add a relative path for additional deps search:
78
+
79
+
80
+ ```
81
+ $ ruby_require_deps $GEM_HOME/gems/ruby_parser-3.6.2/bin/ruby_parse \
82
+ -p $GEM_HOME/gems/ruby_parser-3.6.2/lib
83
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/bin/ruby_parse
84
+ rubygems (not local?)
85
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby_parser.rb
86
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby18_parser.rb
87
+ racc/parser.rb (not local?)
88
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby_lexer.rb
89
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby_lexer.rex.rb
90
+ strscan (not local?)
91
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby_parser_extras.rb
92
+ stringio (not local?)
93
+ racc/parser (not local?)
94
+ sexp (not local?)
95
+ timeout (not local?)
96
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby19_parser.rb
97
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby20_parser.rb
98
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby21_parser.rb
99
+ pp (not local?)
100
+ ```
101
+
102
+ Generate 1 .rb file from all deps:
103
+
104
+ $ ruby_require_deps ~/.rvm/src/ruby-2.0.0-p247/lib/irb.rb | \
105
+ ruby_require_cat -o deps.rb
106
+
107
+ ## License
108
+
109
+ MIT.
data/README.md.m4 ADDED
@@ -0,0 +1,105 @@
1
+ changequote([,])dnl
2
+ # ruby_require_inline
3
+
4
+ Recursively goes through ruby 'require' statements & prints a tree of
5
+ dependencies.
6
+
7
+ It does it by parsing .rb files, so it'll find only 'static'
8
+ declarations. Unfortunately, this won't be picked up:
9
+
10
+ foo = 'bar'
11
+ require foo
12
+
13
+ Only
14
+
15
+ require 'bar'
16
+ require './bar'
17
+ require_relative '../bar'
18
+
19
+ & so on will work.
20
+
21
+ See https://github.com/gromnitsky/minirake as an example where it can be
22
+ useful.
23
+
24
+ ## Installation
25
+
26
+ gem install ruby_require_inline
27
+
28
+ ## Usage
29
+
30
+ ```
31
+ $ ruby_require_deps -h
32
+ syscmd([bin/ruby_require_deps -h])
33
+ ```
34
+
35
+ Dump a tree:
36
+
37
+ ```
38
+ $ ruby_require_deps ~/.rvm/src/ruby-2.0.0-p247/lib/irb.rb
39
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb.rb
40
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/e2mmap.rb
41
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/init.rb
42
+ irb/error.rb (not local)
43
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/help.rb
44
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/magic-file.rb
45
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/context.rb
46
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/workspace.rb
47
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/tempfile.rb
48
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/delegate.rb
49
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/tmpdir.rb
50
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/fileutils.rb
51
+ etc (not local)
52
+ etc.so (not local)
53
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/thread.rb
54
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/inspector.rb
55
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/pp.rb
56
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/prettyprint.rb
57
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/yaml.rb
58
+ psych (not local)
59
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/extend-command.rb
60
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/ruby-lex.rb
61
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/slex.rb
62
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/notifier.rb
63
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/output-method.rb
64
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/ruby-token.rb
65
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/input-method.rb
66
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/src_encoding.rb
67
+ readline (not local)
68
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/locale.rb
69
+ irb/encoding_aliases.rb (not local)
70
+ /home/alex/.rvm/src/ruby-2.0.0-p247/lib/irb/version.rb
71
+ ```
72
+
73
+ Use `-p` to add a relative path for additional deps search:
74
+
75
+
76
+ ```
77
+ $ ruby_require_deps $GEM_HOME/gems/ruby_parser-3.6.2/bin/ruby_parse \
78
+ -p $GEM_HOME/gems/ruby_parser-3.6.2/lib
79
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/bin/ruby_parse
80
+ rubygems (not local?)
81
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby_parser.rb
82
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby18_parser.rb
83
+ racc/parser.rb (not local?)
84
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby_lexer.rb
85
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby_lexer.rex.rb
86
+ strscan (not local?)
87
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby_parser_extras.rb
88
+ stringio (not local?)
89
+ racc/parser (not local?)
90
+ sexp (not local?)
91
+ timeout (not local?)
92
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby19_parser.rb
93
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby20_parser.rb
94
+ /home/alex/.rvm/gems/ruby-2.0.0-p247/gems/ruby_parser-3.6.2/lib/ruby21_parser.rb
95
+ pp (not local?)
96
+ ```
97
+
98
+ Generate 1 .rb file from all deps:
99
+
100
+ $ ruby_require_deps ~/.rvm/src/ruby-2.0.0-p247/lib/irb.rb | \
101
+ ruby_require_cat -o deps.rb
102
+
103
+ ## License
104
+
105
+ MIT.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ docs = FileList['*.md.m4'].sub(/\.md\.m4$/, '.md')
5
+
6
+ task :default => [:compile, :test]
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << "test"
10
+ end
11
+
12
+ task :compile => docs
13
+
14
+ rule '.md' => ['.md.m4'] do |t|
15
+ sh "m4 #{t.source} > #{t.name}"
16
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ require 'ruby_parser'
6
+
7
+ require_relative '../lib/ruby_require_inline/version'
8
+
9
+ $conf = {
10
+ banner: "Usage: #{File.basename $0} [-o output] [input]",
11
+ output: $stdout,
12
+ input: $stdin
13
+ }
14
+
15
+
16
+
17
+ def usage ec = 0
18
+ stream = ec == 0 ? $stdout : $stderr
19
+ stream.puts $conf[:banner]
20
+ exit ec
21
+ end
22
+
23
+ def parse_line line
24
+ return nil unless line
25
+ return nil if line[0] == '/' # skip 1st entry
26
+ line.strip!
27
+ return nil if line.match(/\(not local\?\)$/)
28
+
29
+ line
30
+ end
31
+
32
+
33
+
34
+ opt_parser = OptionParser.new do |opts|
35
+ opts.banner = $conf[:banner]
36
+
37
+ opts.on("-o FILE", "Output file instead of stdout") do |arg|
38
+ $conf[:output] = arg
39
+ end
40
+ opts.on("-V", "--version", "Version info") do
41
+ puts RubyRequireInline::VERSION
42
+ exit 0
43
+ end
44
+ end
45
+
46
+ begin
47
+ opt_parser.parse!
48
+ rescue OptionParser::InvalidOption => e
49
+ $stderr.puts e
50
+ usage 1
51
+ end
52
+
53
+ $conf[:input] = File.open ARGV[0] if ARGV.size > 0
54
+
55
+
56
+
57
+ while line = gets
58
+
59
+ file = parse_line line
60
+ next unless file
61
+
62
+ if $conf[:output] != $stdout && !$conf[:output].is_a?(IO)
63
+ $conf[:output] = File.open $conf[:output], 'w+'
64
+ end
65
+
66
+ code = File.read file
67
+
68
+ $conf[:output].printf "%s\n%s%s%s\n\n", \
69
+ "\# === BEGIN #{file} ===", \
70
+ code,
71
+ code[-1] == "\n" ? "" : "\n",
72
+ "\# === END #{file} ==="
73
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ require_relative '../lib/ruby_require_inline/version'
6
+ require_relative '../lib/ruby_require_inline/depswalk'
7
+
8
+ $conf = {
9
+ banner: "Usage: #{File.basename $0} [-p path] [-o output] input",
10
+ mode: 'tree', # also: flat
11
+ deps_paths: [],
12
+ output: $stdout,
13
+ input: nil
14
+ }
15
+
16
+
17
+
18
+ def usage ec = 0
19
+ stream = ec == 0 ? $stdout : $stderr
20
+ stream.puts $conf[:banner]
21
+ exit ec
22
+ end
23
+
24
+
25
+
26
+ opt_parser = OptionParser.new do |opts|
27
+ opts.banner = $conf[:banner]
28
+
29
+ opts.on("-p DIR", "Add path for additional deps search") do |arg|
30
+ $conf[:deps_paths] << arg
31
+ end
32
+ opts.on("-o FILE", "Output file instead of stdout") do |arg|
33
+ $conf[:output] = arg
34
+ end
35
+ opts.on("--flat", "Print a simple list instead of a tree") do
36
+ $conf[:mode] = 'flat'
37
+ end
38
+ opts.on("-V", "--version", "Version info & $:") do
39
+ puts RubyRequireInline::VERSION
40
+ puts $:
41
+ exit 0
42
+ end
43
+ end
44
+
45
+ begin
46
+ opt_parser.parse!
47
+ rescue OptionParser::InvalidOption => e
48
+ $stderr.puts e
49
+ usage 1
50
+ end
51
+
52
+ usage 1 if ARGV.size == 0
53
+ $conf[:input] = ARGV[0]
54
+
55
+
56
+
57
+ dir_orig = Dir.pwd
58
+ Dir.chdir File.dirname $conf[:input]
59
+ $conf[:input] = File.basename $conf[:input]
60
+
61
+ dw = RubyRequireInline::DepsWalk.new $conf[:deps_paths], $conf[:input]
62
+ dw.start do |file, level, not_found|
63
+ indent = $conf[:mode] == 'tree' ? ' ' * level : ''
64
+
65
+ # open output so late because we don't want to destroy the output file
66
+ # for nothing if there was an error in cl params
67
+ if $conf[:output] != $stdout && !$conf[:output].is_a?(IO)
68
+ $conf[:output] = File.open File.join(dir_orig, $conf[:output]), 'w+'
69
+ end
70
+
71
+ $conf[:output].printf "%s%s%s\n", indent, file, not_found ? " (not local?)" : ""
72
+ $conf[:output].flush if $conf[:output] == $stdout
73
+ end
@@ -0,0 +1,112 @@
1
+ require 'ruby_parser'
2
+
3
+ module RubyRequireInline
4
+
5
+ class DepsWalk
6
+
7
+ def initialize deps_paths, entry_point
8
+ @cache = {}
9
+ @entry_point = entry_point
10
+ @deps_paths = deps_paths
11
+
12
+ @deps_paths.unshift "."
13
+ end
14
+
15
+ def start &block
16
+ walk_deps @entry_point, &block
17
+ end
18
+
19
+ def walk_deps file, level = 0, stop = false, &block
20
+ file = File.realpath file if level == 0
21
+ return if @cache.key?(file)
22
+ @cache[file] = true
23
+
24
+ yield file, level, stop if block_given?
25
+ return if stop
26
+
27
+ sexp = RubyParser.new.parse IO.read(file)
28
+
29
+ walk_sexp(sexp) do |node|
30
+ dep = require_parse node
31
+ if dep
32
+ path = dep_path dep, file
33
+ if path
34
+ walk_deps path, level+1, false, &block # recursion!
35
+ else
36
+ # this will do &block and return
37
+ walk_deps dep.first, level+1, true, &block # recursion!
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def walk_sexp sexp, &block
44
+ return unless sexp.is_a?(Sexp)
45
+
46
+ sexp.sexp_body.each do |node|
47
+ yield node if block_given?
48
+ walk_sexp(node, &block) if node.is_a?(Sexp) # recursion!
49
+ end
50
+ end
51
+
52
+ # Return a full path to a dependency, or nil if file not found. It
53
+ # doesn't look in $LOAD_PATH.
54
+ def dep_path dep, parent
55
+ return nil unless dep
56
+
57
+ @deps_paths.each do |path|
58
+ [".rb", ""].each do |idx|
59
+ file = dep.first + idx
60
+ if dep[1]
61
+ # dep.first is relative to a parent dep
62
+ file = File.join File.dirname(parent), file
63
+ else
64
+ file = File.join path, file
65
+ end
66
+
67
+ return File.realpath file if File.readable?(file) && File.file?(file)
68
+ end
69
+ end
70
+
71
+ # puts "#{dep.first} not found"
72
+ nil
73
+ end
74
+
75
+ # Return a 1st param of 'require' & relative flag or nil.
76
+ #
77
+ # Examples:
78
+ #
79
+ # ['foo', nil']
80
+ # ['../bar, 'true']
81
+ def require_parse sexp
82
+ return nil unless sexp
83
+
84
+ # valid node example: s(:call, nil, :require, s(:str, "getoptlong"))
85
+ is_require_node = -> (node) {
86
+ return nil unless node.is_a? Sexp
87
+ node.sexp_type == :call \
88
+ && sexp.sexp_body[2] && sexp.sexp_body[2].sexp_type == :str \
89
+ && (node.sexp_body[1] == :require || \
90
+ node.sexp_body[1] == :require_relative || \
91
+ node.sexp_body[1] == :load)
92
+ }
93
+
94
+ return nil unless is_require_node.call sexp
95
+
96
+ is_relative_path = -> (node) {
97
+ node.sexp_body[2].sexp_body.first.match(/^(\.{1,2})?\//)
98
+ }
99
+ is_relative = -> (node) {
100
+ node.sexp_body[1] == :require_relative || is_relative_path.call(node)
101
+ }
102
+
103
+ if sexp.sexp_body[2]
104
+ return [sexp.sexp_body[2].sexp_body.first, is_relative.call(sexp)]
105
+ end
106
+
107
+ nil
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,3 @@
1
+ module RubyRequireInline
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_require_inline/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_require_inline"
8
+ spec.version = RubyRequireInline::VERSION
9
+ spec.authors = ["Alexander Gromnitsky"]
10
+ spec.email = ["alexander.gromnitsky@gmail.com"]
11
+ spec.summary = "Analyses all 'require' statements & concatenates dependencies into 1 file."
12
+ spec.description = "See the summary."
13
+ spec.homepage = "https://github.com/gromnitsky/ruby_require_inline"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", "~> 10"
23
+ spec.add_development_dependency "minitest", "~> 5.4.1"
24
+
25
+ spec.add_dependency "ruby_parser", "~> 3.6.2"
26
+ end
@@ -0,0 +1,6 @@
1
+ require '../foo'
2
+ require '../ffffff'
3
+
4
+ require 'qwerty'
5
+
6
+ puts 'bar.rb'
@@ -0,0 +1,3 @@
1
+ require_relative 'bar/bar'
2
+
3
+ puts 'foo.rb'
@@ -0,0 +1,6 @@
1
+ require 'fileutils'
2
+ require 'pp'
3
+
4
+ require './bar/bar.rb'
5
+
6
+ puts 'foo2.rb'
@@ -0,0 +1,16 @@
1
+ # hi
2
+
3
+ require 'pp'
4
+
5
+ require './foo/foo'
6
+ require 'thread'
7
+ require_relative 'foo/foo'
8
+
9
+ def foo
10
+ require './foo/foo2'
11
+ end
12
+
13
+ require 'pp'
14
+ require 'the-end'
15
+
16
+ puts 'main.rb'
@@ -0,0 +1,3 @@
1
+ Dir.chdir __dir__
2
+
3
+ require 'minitest/autorun'
@@ -0,0 +1,28 @@
1
+ require_relative 'minitest_helper'
2
+
3
+ require_relative '../lib/ruby_require_inline/depswalk'
4
+
5
+ class TestDepsWalk < Minitest::Test
6
+ def setup
7
+ @files = []
8
+ dw = RubyRequireInline::DepsWalk.new [], "fixtures/01/main.rb"
9
+ dw.start do |file, level, not_found|
10
+ @files << file
11
+ end
12
+
13
+ @files.map {|idx| idx.sub!(/.*fixtures\/01\//, '') }
14
+ end
15
+
16
+ def test_smoke
17
+ assert_equal ["main.rb",
18
+ "pp",
19
+ "foo/foo.rb",
20
+ "foo/bar/bar.rb",
21
+ "../ffffff",
22
+ "qwerty",
23
+ "thread",
24
+ "foo/foo2.rb",
25
+ "fileutils",
26
+ "the-end"], @files
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_require_inline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Gromnitsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 5.4.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 5.4.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby_parser
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.6.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.6.2
69
+ description: See the summary.
70
+ email:
71
+ - alexander.gromnitsky@gmail.com
72
+ executables:
73
+ - ruby_require_cat
74
+ - ruby_require_deps
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rdoc_options
80
+ - Gemfile
81
+ - README.md
82
+ - README.md.m4
83
+ - Rakefile
84
+ - bin/ruby_require_cat
85
+ - bin/ruby_require_deps
86
+ - lib/ruby_require_inline/depswalk.rb
87
+ - lib/ruby_require_inline/version.rb
88
+ - ruby_require_inline.gemspec
89
+ - test/fixtures/01/foo/bar/bar.rb
90
+ - test/fixtures/01/foo/foo.rb
91
+ - test/fixtures/01/foo/foo2.rb
92
+ - test/fixtures/01/main.rb
93
+ - test/minitest_helper.rb
94
+ - test/test_depswalk.rb
95
+ homepage: https://github.com/gromnitsky/ruby_require_inline
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.0.7
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Analyses all 'require' statements & concatenates dependencies into 1 file.
119
+ test_files:
120
+ - test/fixtures/01/foo/bar/bar.rb
121
+ - test/fixtures/01/foo/foo.rb
122
+ - test/fixtures/01/foo/foo2.rb
123
+ - test/fixtures/01/main.rb
124
+ - test/minitest_helper.rb
125
+ - test/test_depswalk.rb