Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
150 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,13 @@ | ||
GemTemplate | ||
=========== | ||
Question | ||
======== | ||
|
||
A gem template for new projects. | ||
Ask questions from Auto. | ||
|
||
Requirements | ||
------------ | ||
Install | ||
------- | ||
|
||
<pre> | ||
sudo gem install stencil --source http://gemcutter.org | ||
</pre> | ||
|
||
Setup the template | ||
------------------ | ||
|
||
You only have to do this once. | ||
|
||
<pre> | ||
git clone git@github.com:winton/gem_template.git | ||
cd gem_template | ||
stencil | ||
</pre> | ||
|
||
Setup a new project | ||
------------------- | ||
|
||
Do this for every new project. | ||
This plugin is automatically installed when you install the auto gem. | ||
|
||
<pre> | ||
mkdir my_project | ||
git init | ||
stencil gem_template | ||
rake rename | ||
</pre> | ||
|
||
The last command does a find-replace (gem\_template -> my\_project) on files and filenames. | ||
sudo gem install auto --source http://gemcutter.org | ||
</pre> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
GEM_NAME = 'gem_template' | ||
GEM_NAME = 'auto-question' | ||
GEM_FILES = FileList['**/*'] - FileList['coverage', 'coverage/**/*', 'pkg', 'pkg/**/*'] | ||
GEM_SPEC = Gem::Specification.new do |s| | ||
# == CONFIGURE == | ||
s.author = "Winton Welsh" | ||
s.email = "mail@wintoni.us" | ||
s.homepage = "http://github.com/winton/#{GEM_NAME}" | ||
s.summary = "" | ||
s.summary = "Ask questions from Auto" | ||
# == CONFIGURE == | ||
s.add_dependency('auto', '=0.1.2') | ||
s.executables << GEM_NAME | ||
s.extra_rdoc_files = [ "README.markdown" ] | ||
s.files = GEM_FILES.to_a | ||
s.has_rdoc = false | ||
s.name = GEM_NAME | ||
s.platform = Gem::Platform::RUBY | ||
s.require_path = "lib" | ||
s.version = "0.1.0" | ||
end | ||
s.version = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module Auto | ||
module Question | ||
|
||
def after_question(key=nil, value=nil, &block) | ||
Questions.after_question(key, value, &block) | ||
end | ||
|
||
def before_question(key=nil, value=nil, &block) | ||
Questions.before_question(key, value, &block) | ||
end | ||
|
||
def questions(hash={}, &block) | ||
q = Questions | ||
hash.each do |key, value| | ||
q[key] = value | ||
if before_question(key, value) | ||
yield if block_given? | ||
after_question(key, value) | ||
end | ||
end | ||
q.questions | ||
end | ||
alias :question :questions | ||
alias :q :questions | ||
|
||
class Questions | ||
|
||
cattr_accessor :questions | ||
@@questions = {} | ||
|
||
class <<self | ||
|
||
def []=(key, value) | ||
@@questions[key] = value | ||
end | ||
|
||
def [](key) | ||
@@questions[key] | ||
end | ||
|
||
def after_question(key, value, &block) | ||
@@after_question ||= [] | ||
if block | ||
@@after_question << block | ||
end | ||
if key && !value.nil? | ||
@@after_question.each do |callback| | ||
callback.call(key, value) | ||
end | ||
end | ||
end | ||
|
||
def before_question(key, value, &block) | ||
@@before_question ||= [] | ||
if block | ||
@@before_question << block | ||
end | ||
if key && !value.nil? | ||
result = true | ||
@@before_question.each do |callback| | ||
result = callback.call(key, value) | ||
break unless result | ||
end | ||
return result | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper") | ||
|
||
module Auto | ||
describe Auto::Question do | ||
|
||
def run | ||
@r.run do | ||
q :q1 => "q1", :q2 => "q2" | ||
end | ||
end | ||
|
||
before(:each) do | ||
@r = Runner.new | ||
end | ||
|
||
it 'should store questions' do | ||
run | ||
@r.run do | ||
q.should == { | ||
:q1 => "q1" , | ||
:q2 => "q2" | ||
} | ||
end | ||
end | ||
|
||
it 'should trigger a "before question" callback' do | ||
questions = {} | ||
@r.before_question do |key, value| | ||
questions[key] = value | ||
end | ||
run | ||
questions.should == { :q1 => "q1", :q2 => "q2" } | ||
end | ||
|
||
it 'should trigger an "after question" callback' do | ||
questions = {} | ||
@r.after_question do |key, value| | ||
questions[key] = value | ||
end | ||
run | ||
questions.should == { :q1 => "q1", :q2 => "q2" } | ||
end | ||
|
||
it 'should not trigger "after question" if a "before question" callback returns false' do | ||
@r.before_question { |key, value| false } | ||
@r.after_question do |key, value| | ||
true.should == false # fail test | ||
end | ||
run | ||
end | ||
|
||
it 'should yield to a block if specified' do | ||
@r.run do | ||
q :q1 => "q1", :q2 => "q2" do | ||
q[:q1].should == "q1" | ||
q[:q2].should == "q2" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters