magicloader 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +12 -5
- data/lib/magic_loader/tasks.rb +30 -0
- data/magicloader.gemspec +2 -2
- metadata +5 -5
data/README.markdown
CHANGED
@@ -71,15 +71,22 @@ what the options do already, but if you can't, here's some help:
|
|
71
71
|
|
72
72
|
* __target__: output file to annotate. See above.
|
73
73
|
|
74
|
-
* __strip__: remove the given leading string from all of the output paths
|
75
|
-
to the target file. Optionally, you can give an arbitrary regular
|
74
|
+
* __strip__: remove the given leading string from all of the output paths
|
75
|
+
written to the target file. Optionally, you can give an arbitrary regular
|
76
76
|
expression, and whatever it matches will be removed from the string.
|
77
77
|
This is good if you have a leading directory prefix you want to remove
|
78
78
|
from the generated output files.
|
79
79
|
|
80
|
-
* __name__: the name of the Rake task to define. It defaults to "magicload" if
|
81
|
-
don't specify it yourself, so specifying it explicitly as "magicload" is
|
82
|
-
bit redundant. Otherwise, you can set it to whatever you want.
|
80
|
+
* __name__: the name of the Rake task to define. It defaults to "magicload" if
|
81
|
+
you don't specify it yourself, so specifying it explicitly as "magicload" is
|
82
|
+
a bit redundant. Otherwise, you can set it to whatever you want.
|
83
|
+
|
84
|
+
* __clean__: true or false boolean. The "clean" option is especially useful if
|
85
|
+
your target file is included in the Rake environment. If this happens, it
|
86
|
+
will distrupt MagicLoader's typical operation. Setting :clean => true will
|
87
|
+
remove previous MagicLoader directives from the target file before
|
88
|
+
attempting to regenerate them, affording you a pristine environment in which
|
89
|
+
to compute your code dependencies.
|
83
90
|
|
84
91
|
The wonderful require_all method
|
85
92
|
--------------------------------
|
data/lib/magic_loader/tasks.rb
CHANGED
@@ -19,10 +19,18 @@ module MagicLoader
|
|
19
19
|
|
20
20
|
# Generates the MagicLoader rake task
|
21
21
|
class Task < Rake::TaskLib
|
22
|
+
# FIXME: Yeah all this functionality really shouldn't be part of the Rake
|
23
|
+
# task. It should be all nicely factored into a reusable class with all
|
24
|
+
# the core functionality exposed, then wrapped in a Rake task. But I'm
|
25
|
+
# lazy and just trying to get this thing out the door, and Rake tasks
|
26
|
+
# are my main use case. Got a problem? Refactor me!
|
27
|
+
|
28
|
+
# Please see the README for how to use this task
|
22
29
|
def initialize(*paths)
|
23
30
|
options = paths.last.is_a?(Hash) ? paths.pop : {}
|
24
31
|
task_name = options[:name] || 'magicload'
|
25
32
|
|
33
|
+
desc "Automagically calculate code dependencies"
|
26
34
|
task task_name do
|
27
35
|
load_order = MagicLoader.require_all(*paths)
|
28
36
|
strip_paths!(load_order, options[:strip]) if options[:strip]
|
@@ -45,6 +53,17 @@ module MagicLoader
|
|
45
53
|
puts magic_block
|
46
54
|
end
|
47
55
|
end
|
56
|
+
|
57
|
+
if options[:clean]
|
58
|
+
namespace task_name do
|
59
|
+
desc "Remove the previous MagicLoader block"
|
60
|
+
task :clean do
|
61
|
+
strip_magic_block options[:target]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
Rake::Task[task_name].prerequisites << "#{task_name}:clean"
|
66
|
+
end
|
48
67
|
end
|
49
68
|
|
50
69
|
#######
|
@@ -71,6 +90,10 @@ module MagicLoader
|
|
71
90
|
# Annotate a MagicLoader Magic Block onto the end of an existing file
|
72
91
|
def annotate_file(path, magic_block)
|
73
92
|
data = File.read path
|
93
|
+
|
94
|
+
# Remove trailing whitespace from the file so it doesn't grow
|
95
|
+
data.sub!(/\w+$/m, '')
|
96
|
+
|
74
97
|
magic_matches = data.match(MAGIC_REGEXP)
|
75
98
|
case magic_matches
|
76
99
|
when MatchData
|
@@ -81,5 +104,12 @@ module MagicLoader
|
|
81
104
|
|
82
105
|
File.open(path, 'w') { |f| f << data }
|
83
106
|
end
|
107
|
+
|
108
|
+
# Remove the MagicLoader block from a particular file
|
109
|
+
def strip_magic_block(file)
|
110
|
+
data = File.read path
|
111
|
+
data.sub(MAGIC_REGEXP, '')
|
112
|
+
File.open(path, 'w') { |f| f << data }
|
113
|
+
end
|
84
114
|
end
|
85
115
|
end
|
data/magicloader.gemspec
CHANGED
@@ -7,7 +7,7 @@ GEMSPEC = Gem::Specification.new do |s|
|
|
7
7
|
Painless code dependency management. Think Bundler, but for managing file load
|
8
8
|
ordering dependencies.
|
9
9
|
EOD
|
10
|
-
s.version = "0.9.
|
10
|
+
s.version = "0.9.1"
|
11
11
|
s.authors = "Tony Arcieri"
|
12
12
|
s.email = "bascule@gmail.com"
|
13
13
|
s.homepage = "http://github.com/tarcieri/MagicLoader"
|
@@ -19,6 +19,6 @@ EOD
|
|
19
19
|
|
20
20
|
# RDoc settings
|
21
21
|
s.has_rdoc = true
|
22
|
-
s.rdoc_options = %w(--title MagicLoader --main README.
|
22
|
+
s.rdoc_options = %w(--title MagicLoader --main README.markdown --line-numbers)
|
23
23
|
s.extra_rdoc_files = ["LICENSE", "README.markdown", "CHANGES"]
|
24
24
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magicloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 57
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 1
|
10
|
+
version: 0.9.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Arcieri
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-03 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -58,7 +58,7 @@ rdoc_options:
|
|
58
58
|
- --title
|
59
59
|
- MagicLoader
|
60
60
|
- --main
|
61
|
-
- README.
|
61
|
+
- README.markdown
|
62
62
|
- --line-numbers
|
63
63
|
require_paths:
|
64
64
|
- lib
|