reqwire 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/reqwire +30 -0
  2. data/lib/reqwire.rb +114 -0
  3. metadata +47 -0
data/bin/reqwire ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'parseconfig'
5
+
6
+ def parse_options()
7
+ options = {}
8
+
9
+ optparse = OptionParser.new do |opts|
10
+ opts.on('-p', '--ping', 'ping!!!') do ||
11
+ options[:ping] = true
12
+ end
13
+ end
14
+
15
+ optparse.parse!
16
+
17
+ return options, optparse
18
+ end
19
+
20
+
21
+
22
+
23
+ #config = ParseConfig.new(File.join(Dir.home, '.tricket'))
24
+
25
+
26
+ options, optparse = parse_options()
27
+
28
+ if options[:ping] then
29
+ puts 'ping ping ping!'
30
+ end
data/lib/reqwire.rb ADDED
@@ -0,0 +1,114 @@
1
+ require 'pathname'
2
+ require 'stringio'
3
+
4
+ class Reqwire
5
+
6
+ @fname
7
+ @extname
8
+ @repo
9
+ @path_rel
10
+ @path_abs
11
+
12
+ attr_accessor :children, :path_abs, :path_rel
13
+
14
+ def initialize(params)
15
+ @fname = params[:fname]
16
+ @extname = File.extname(@fname)
17
+ @repo = params[:repo]
18
+ @out = params[:out] || STDOUT
19
+ @children = {}
20
+
21
+ path_dir = Pathname.new projectDir()
22
+ path = Pathname.new File.absolute_path(@fname, path_dir.to_s)
23
+
24
+ @path_rel = path.relative_path_from(path_dir).to_s
25
+ @path_abs = path.to_s
26
+
27
+ end
28
+
29
+ def fetchReq(line)
30
+ if (line =~ /^\s*\/\/\s*req\s*'([^']*)'/) then
31
+ return $1
32
+ else
33
+ return false
34
+ end
35
+ end
36
+
37
+ def testPath(fname, dirs)
38
+ dirs.each.with_index do |dir, count|
39
+ path = File.absolute_path(fname, dir)
40
+ if File.exists?(path) then
41
+ subdirs = Array.new(dirs)[count .. -1]
42
+ return path, subdirs
43
+ end
44
+ end
45
+ return false
46
+ end
47
+
48
+ def projectDir()
49
+ @repo[0]
50
+ end
51
+
52
+
53
+ def revert(&handler)
54
+ resolve()
55
+ yield(@path_abs, @path_rel, @out)
56
+ res = []
57
+ Dir.glob(File.join(projectDir(), '**', '*')) do |path|
58
+ out = StringIO.new("", "w+")
59
+ next if File.directory?(path)
60
+ next if @children[path]
61
+ req = Reqwire.new(
62
+ :fname => path,
63
+ :repo => [projectDir()],
64
+ :out => out
65
+ )
66
+ req.resolve()
67
+ if req.children[@path_abs] then
68
+ yield(req.path_abs, req.path_rel, out)
69
+ end
70
+ out.close
71
+ end
72
+ end
73
+
74
+ def resolve(visited = {}, parent_resolver = nil)
75
+ out = @out
76
+ req = @fname
77
+ if visited[req].nil? then
78
+ #if not started then continue
79
+ #do nothing )
80
+ elsif visited[req] = 1 then
81
+ #if already done then ignore
82
+ puts "ignoring #{req} since it already been added"
83
+ return false
84
+ elsif visited[req] == 0 then
85
+ raise "Cannot resolve circular reference in #{req}"
86
+ end
87
+ #started
88
+ visited[req] = 0
89
+ path, subrepo = testPath(req, @repo)
90
+ if path then
91
+ if not parent_resolver.nil? then
92
+ parent_resolver.children[path] = true
93
+ end
94
+ file = File.new(path, 'r')
95
+ while line = file.gets do
96
+ req = fetchReq(line)
97
+ if req then
98
+ rec = Reqwire.new(
99
+ :fname => req,
100
+ :repo => subrepo,
101
+ :out => out
102
+ )
103
+ rec.resolve(visited, self)
104
+ else
105
+ out.write line
106
+ end
107
+ end
108
+ end
109
+ #visited
110
+ visited[@fname] = 1
111
+ return true
112
+ end
113
+
114
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reqwire
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Shahen Shabunc
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-02 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: a toolbox for resolving includes. This is an early alpha.
15
+ email: shabunc@gmail.com
16
+ executables:
17
+ - reqwire
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/reqwire.rb
22
+ - bin/reqwire
23
+ homepage: http://rubygems.org/gems/tricket
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.24
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: a toolbox for resolving includes. This is an early alpha.
47
+ test_files: []