Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Nov 16, 2009
1 parent 761f9ef commit a6ee65c
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 43 deletions.
39 changes: 8 additions & 31 deletions README.markdown
@@ -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>
4 changes: 0 additions & 4 deletions bin/gem_template

This file was deleted.

9 changes: 5 additions & 4 deletions gemspec.rb
@@ -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
70 changes: 70 additions & 0 deletions lib/auto/question.rb
@@ -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
1 change: 0 additions & 1 deletion lib/gem_template.rb

This file was deleted.

Empty file removed lib/gem_template/gem_template.rb
Empty file.
61 changes: 61 additions & 0 deletions spec/questions_spec.rb
@@ -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
9 changes: 6 additions & 3 deletions spec/spec_helper.rb
Expand Up @@ -2,15 +2,18 @@
SPEC = File.dirname(__FILE__)
$:.unshift File.expand_path("#{SPEC}/../lib")

require 'gem_template'
require 'auto/require'
require 'pp'

Spec::Runner.configure do |config|
end
# Manually add this plugin
Auto::Plugins.add File.expand_path("#{SPEC}/../")

# For use with rspec textmate bundle
def debug(object)
puts "<pre>"
puts object.pretty_inspect.gsub('<', '&lt;').gsub('>', '&gt;')
puts "</pre>"
end

Spec::Runner.configure do |config|
end

0 comments on commit a6ee65c

Please sign in to comment.