Permalink
Browse files

Merge pull request #108 from twinturbo/remove-invoke

Remove rename invoke_clean to invoke & drop invoke
  • Loading branch information...
wycats committed Oct 26, 2012
2 parents 2fd58fa + fe15430 commit 9e8b4fa9c57c0c548f9938cc6a291ff5b73ec7a8
View
@@ -309,34 +309,21 @@ def add_filters(*filters)
end
alias add_filter add_filters
- # Invoke the pipeline, processing the inputs into the output. If
- # the pipeline has already been invoked, reinvoking will not
- # pick up new input files added to the file system.
+ # Invoke the pipeline, processing the inputs into the output.
#
# @return [void]
def invoke
@invoke_mutex.synchronize do
- self.rake_application = Rake::Application.new unless @rake_application
+ @tmp_id = 0
+
+ self.rake_application = Rake::Application.new
setup
- @rake_tasks.each { |task| task.recursively_reenable(rake_application) }
@rake_tasks.each { |task| task.invoke }
end
end
- # Pick up any new files added to the inputs and process them through
- # the filters. Then call #invoke.
- #
- # @return [void]
- def invoke_clean
- @clean_mutex.synchronize do
- @tmp_id = 0
- @rake_tasks = @rake_application = nil
- invoke
- end
- end
-
# Set up the filters and generate rake tasks. In general, this method
# is called by invoke.
#
@@ -435,17 +422,7 @@ def generate_tmpdir
#
# @return [void]
def generate_rake_tasks
- @rake_tasks ||= begin
- tasks = []
-
- @filters.each do |filter|
- # TODO: Don't generate rake tasks if we aren't
- # creating a new Rake::Application
- tasks = filter.generate_rake_tasks
- end
-
- tasks
- end
+ @rake_tasks = filters.collect { |f| f.generate_rake_tasks }.flatten
end
# Assert that an input root and glob were both provided.
@@ -30,7 +30,7 @@ def initialize(app, pipeline)
# @param [Hash] env a Rack environment
# @return [Array(Fixnum, Hash, #each)] A rack response
def call(env)
- project.invoke_clean
+ project.invoke
path = env["PATH_INFO"]
if project.maps.has_key?(path)
@@ -103,23 +103,12 @@ def build(&block)
self
end
- # Invoke all of the project's pipelines.
- #
- # @see Rake::Pipeline#invoke
- def invoke
- @invoke_mutex.synchronize do
- manifest.read_manifest
- pipelines.each(&:invoke)
- manifest.write_manifest
- end
- end
-
# Invoke all of the project's pipelines, detecting any changes
# to the Assetfile and rebuilding the pipelines if necessary.
#
# @return [void]
- # @see Rake::Pipeline#invoke_clean
- def invoke_clean
+ # @see Rake::Pipeline#invoke
+ def invoke
@invoke_mutex.synchronize do
if assetfile_path
source = File.read(assetfile_path)
@@ -129,7 +118,7 @@ def invoke_clean
end
manifest.read_manifest
- pipelines.each(&:invoke_clean)
+ pipelines.each(&:invoke)
manifest.write_manifest
end
end
View
@@ -163,7 +163,7 @@ def setup_roots
pipeline.input_files = [input_file("foo.bar", pipeline.tmpdir)]
expect {
- pipeline.invoke_clean
+ pipeline.invoke
}.to raise_error(Rake::Pipeline::TmpInputError)
end
View
@@ -99,6 +99,12 @@ def assetfile_digest
end
describe "#invoke" do
+ def modify_assetfile
+ File.open(assetfile_path, 'w') do |file|
+ file.write(MODIFIED_ASSETFILE_SOURCE)
+ end
+ end
+
it "creates output files" do
output_files.each { |file| file.should_not exist }
project.invoke
@@ -115,6 +121,17 @@ def assetfile_digest
project.manifest.should_receive(:write_manifest)
project.invoke
end
+
+ it "rebuilds its pipeline when the Assetfile changes" do
+ project.invoke
+ original_pipeline = project.pipelines.last
+ original_assetfile_digest = assetfile_digest
+
+ modify_assetfile
+ project.invoke
+ assetfile_digest.should_not == original_assetfile_digest
+ project.pipelines.last.should_not == original_pipeline
+ end
end
describe "invalid Assetfile" do
@@ -129,30 +146,15 @@ def assetfile_digest
end
end
- describe "#invoke_clean" do
+ describe "#invoke" do
context "if the Assetfile contents have changed" do
- def modify_assetfile
- File.open(assetfile_path, 'w') do |file|
- file.write(MODIFIED_ASSETFILE_SOURCE)
- end
- end
-
- it "rebuilds its pipeline" do
- project.invoke_clean
- original_pipeline = project.pipelines.last
- original_assetfile_digest = assetfile_digest
-
- modify_assetfile
- project.invoke_clean
- assetfile_digest.should_not == original_assetfile_digest
- project.pipelines.last.should_not == original_pipeline
- end
+
end
it "updates the manifest" do
project.manifest.should_receive(:read_manifest)
project.manifest.should_receive(:write_manifest)
- project.invoke_clean
+ project.invoke
end
end
@@ -231,7 +231,7 @@ def copy_files
end
end
- project.invoke_clean
+ project.invoke
expected = <<-HERE.gsub(/^ {10}/, '')
var History = {};
@@ -247,12 +247,12 @@ def copy_files
it "does not generate new files when things haven't changed" do
output_file = File.join(tmp, "public/javascripts/application.js")
- project.invoke_clean
+ project.invoke
previous_mtime = File.mtime(output_file)
sleep 1
- project.invoke_clean
+ project.invoke
File.mtime(output_file).should == previous_mtime
end
end
@@ -518,7 +518,7 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
describe "Dynamic dependencies" do
shared_examples_for "a pipeline with dynamic files" do
it "should handle changes in dynamic imports" do
- project.invoke_clean
+ project.invoke
content = File.read output_file
@@ -532,14 +532,14 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
f.write "true to trance"
end
- project.invoke_clean
+ project.invoke
content = File.read output_file
content.should include("true to trance")
end
it "should handle changes in dynamic source files" do
- project.invoke_clean
+ project.invoke
content = File.read output_file
@@ -553,16 +553,16 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
f.write "true to trance"
end
- project.invoke_clean
+ project.invoke
content = File.read output_file
content.should == "true to trance"
end
it "should not regenerate files when nothing changes" do
- project.invoke_clean
+ project.invoke
previous_mtime = File.mtime output_file
- sleep 1 ; project.invoke_clean
+ sleep 1 ; project.invoke
File.mtime(output_file).should == previous_mtime
end
View
@@ -23,36 +23,31 @@ class Perfs < Thor
class_option :clean, :type => :boolean, :default => true
- desc "bench PROJECT_DIR", "Benchmark building, rebuilding, and cleaning the given project"
+ desc "bench PROJECT_DIR", "Benchmark building and cleaning the given project"
def bench(project_dir)
setup(project_dir)
invoke_time = Benchmark.realtime do
project.invoke
end
- reinvoke_time = Benchmark.realtime do
- project.invoke_clean
- end
-
clean_time = Benchmark.realtime do
project.clean
end
puts "build: #{invoke_time}"
- puts "rebuild: #{reinvoke_time}"
puts "clean: #{clean_time}"
end
- desc "profile PROJECT_DIR", "Profile a clean build of the given project"
+ desc "profile PROJECT_DIR", "Profile a build"
method_option :rebuild, :type => :boolean, :aliases => "-r", :default => false
def profile(project_dir)
setup(project_dir)
if options[:rebuild]
project.invoke
result = RubyProf.profile do
- project.invoke_clean
+ project.invoke
end
else
result = RubyProf.profile do
@@ -96,7 +91,6 @@ class Perfs < Thor
def setup(project_dir)
cd project_dir
project.clean
- project.invoke unless options[:clean]
end
def project

0 comments on commit 9e8b4fa

Please sign in to comment.