From 2c6db30004866be888ca617c032532945951ee0c Mon Sep 17 00:00:00 2001 From: "Colin T.A. Gray" Date: Tue, 14 Oct 2014 13:15:36 -0600 Subject: [PATCH 1/4] added 'pre' and 'post' setup blocks --- lib/motion/project/app.rb | 11 ++++++++++- lib/motion/project/config.rb | 25 +++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/motion/project/app.rb b/lib/motion/project/app.rb index 69a1a436..1a7b5c0d 100644 --- a/lib/motion/project/app.rb +++ b/lib/motion/project/app.rb @@ -71,7 +71,16 @@ def builder end def setup(&block) - config.setup_blocks << block + config_without_setup.setup_blocks << block + config.setup + end + + def pre_setup(&block) + config_without_setup.setup_blocks << block + end + + def post_setup(&block) + config_without_setup.post_setup_blocks << block end def build(platform, opts={}) diff --git a/lib/motion/project/config.rb b/lib/motion/project/config.rb index 581e314f..73c0fa7b 100644 --- a/lib/motion/project/config.rb +++ b/lib/motion/project/config.rb @@ -76,7 +76,8 @@ def self.make(template, project_dir, build_mode) def initialize(project_dir, build_mode) @project_dir = project_dir - @files = Dir.glob(File.join(project_dir, 'app/**/*.rb')) + @files = [] + @app_dir = 'app' @build_mode = build_mode @name = 'Untitled' @resources_dirs = [File.join(project_dir, 'resources')] @@ -105,12 +106,32 @@ def setup_blocks @setup_blocks ||= [] end + def post_setup_blocks + @post_setup_blocks ||= [] + end + def setup if @setup_blocks @setup_blocks.each { |b| b.call(self) } - @setup_blocks = nil + end + + if @post_setup_blocks + @post_setup_blocks.each { |b| b.call(self) } + end + + # should we include a check here for "already included app/ files"? it's + # not necessary since this operation is idempotent. + Dir.glob(File.join(project_dir, "#{@app_dir}/**/*.rb")).each do |app_file| + @files << app_file unless @files.include?(app_file) + end + + if @setup_blocks || @post_setup_blocks validate end + + @setup_blocks = nil + @post_setup_blocks = nil + self end From ae4579e89de4f8fa754874a97aeb30ade49da766 Mon Sep 17 00:00:00 2001 From: "Colin T.A. Gray" Date: Wed, 15 Oct 2014 07:16:49 -0600 Subject: [PATCH 2/4] oh shoot, I forgot to copy in this refactor --- lib/motion/project/config.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/motion/project/config.rb b/lib/motion/project/config.rb index 73c0fa7b..ec1c0251 100644 --- a/lib/motion/project/config.rb +++ b/lib/motion/project/config.rb @@ -111,27 +111,31 @@ def post_setup_blocks end def setup + should_validate = false if @setup_blocks @setup_blocks.each { |b| b.call(self) } + should_validate = true + @setup_blocks = nil end - if @post_setup_blocks - @post_setup_blocks.each { |b| b.call(self) } + if @app_dir + Dir.glob(File.join(project_dir, "#{@app_dir}/**/*.rb")).each do |app_file| + @files << app_file unless @files.include?(app_file) + end + should_validate = true + @app_dir = nil end - # should we include a check here for "already included app/ files"? it's - # not necessary since this operation is idempotent. - Dir.glob(File.join(project_dir, "#{@app_dir}/**/*.rb")).each do |app_file| - @files << app_file unless @files.include?(app_file) + if @post_setup_blocks + @post_setup_blocks.each { |b| b.call(self) } + should_validate = true + @post_setup_blocks = nil end - if @setup_blocks || @post_setup_blocks + if should_validate validate end - @setup_blocks = nil - @post_setup_blocks = nil - self end From 936b9fec7bd8006c4137b2bb8b7325364e90b432 Mon Sep 17 00:00:00 2001 From: "Colin T.A. Gray" Date: Wed, 15 Oct 2014 07:54:43 -0600 Subject: [PATCH 3/4] using 'pre_setup_blocks' we can set 'app.files' before the Rakefile setup block is called, just like old times --- lib/motion/project/app.rb | 2 +- lib/motion/project/config.rb | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/motion/project/app.rb b/lib/motion/project/app.rb index 1a7b5c0d..c338dd62 100644 --- a/lib/motion/project/app.rb +++ b/lib/motion/project/app.rb @@ -76,7 +76,7 @@ def setup(&block) end def pre_setup(&block) - config_without_setup.setup_blocks << block + config_without_setup.pre_setup_blocks << block end def post_setup(&block) diff --git a/lib/motion/project/config.rb b/lib/motion/project/config.rb index ec1c0251..81c5cdcb 100644 --- a/lib/motion/project/config.rb +++ b/lib/motion/project/config.rb @@ -102,6 +102,10 @@ def variables map end + def pre_setup_blocks + @pre_setup_blocks ||= [] + end + def setup_blocks @setup_blocks ||= [] end @@ -112,10 +116,11 @@ def post_setup_blocks def setup should_validate = false - if @setup_blocks - @setup_blocks.each { |b| b.call(self) } + + if @pre_setup_blocks + @pre_setup_blocks.each { |b| b.call(self) } should_validate = true - @setup_blocks = nil + @pre_setup_blocks = nil end if @app_dir @@ -126,6 +131,12 @@ def setup @app_dir = nil end + if @setup_blocks + @setup_blocks.each { |b| b.call(self) } + should_validate = true + @setup_blocks = nil + end + if @post_setup_blocks @post_setup_blocks.each { |b| b.call(self) } should_validate = true From 176f291895e4ee209d44a4741c58fd4c80e4f0a2 Mon Sep 17 00:00:00 2001 From: "Colin T.A. Gray" Date: Wed, 15 Oct 2014 08:03:17 -0600 Subject: [PATCH 4/4] this was calling 'setup' twice, since 'config' also calls 'setup' --- lib/motion/project/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/motion/project/app.rb b/lib/motion/project/app.rb index c338dd62..d54e1533 100644 --- a/lib/motion/project/app.rb +++ b/lib/motion/project/app.rb @@ -72,7 +72,7 @@ def builder def setup(&block) config_without_setup.setup_blocks << block - config.setup + config end def pre_setup(&block)