auto-question 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +18 -0
- data/README.markdown +13 -0
- data/Rakefile +52 -0
- data/gemspec.rb +17 -0
- data/lib/auto/question.rb +70 -0
- data/spec/questions_spec.rb +61 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +20 -0
- metadata +62 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2009 Winton Welsh
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
require 'gemspec'
|
6
|
+
|
7
|
+
desc "Generate gemspec"
|
8
|
+
task :gemspec do
|
9
|
+
File.open("#{Dir.pwd}/#{GEM_NAME}.gemspec", 'w') do |f|
|
10
|
+
f.write(GEM_SPEC.to_ruby)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Install gem"
|
15
|
+
task :install do
|
16
|
+
Rake::Task['gem'].invoke
|
17
|
+
`sudo gem uninstall #{GEM_NAME} -x`
|
18
|
+
`sudo gem install pkg/#{GEM_NAME}*.gem`
|
19
|
+
`rm -Rf pkg`
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Package gem"
|
23
|
+
Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
|
24
|
+
pkg.gem_spec = GEM_SPEC
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Rename project"
|
28
|
+
task :rename do
|
29
|
+
name = ENV['NAME'] || File.basename(Dir.pwd)
|
30
|
+
begin
|
31
|
+
dir = Dir['**/gem_template*']
|
32
|
+
from = dir.pop
|
33
|
+
if from
|
34
|
+
rb = from.include?('.rb')
|
35
|
+
to = File.dirname(from) + "/#{name}#{'.rb' if rb}"
|
36
|
+
FileUtils.mv(from, to)
|
37
|
+
end
|
38
|
+
end while dir.length > 0
|
39
|
+
Dir["**/*"].each do |path|
|
40
|
+
next if path.include?('Rakefile')
|
41
|
+
if File.file?(path)
|
42
|
+
`sed -i "" 's/gem_template/#{name}/g' #{path}`
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Run specs"
|
48
|
+
Spec::Rake::SpecTask.new do |t|
|
49
|
+
t.rcov = true
|
50
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
51
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
52
|
+
end
|
data/gemspec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
GEM_NAME = 'auto-question'
|
2
|
+
GEM_FILES = FileList['**/*'] - FileList['coverage', 'coverage/**/*', 'pkg', 'pkg/**/*']
|
3
|
+
GEM_SPEC = Gem::Specification.new do |s|
|
4
|
+
# == CONFIGURE ==
|
5
|
+
s.author = "Winton Welsh"
|
6
|
+
s.email = "mail@wintoni.us"
|
7
|
+
s.homepage = "http://github.com/winton/#{GEM_NAME}"
|
8
|
+
s.summary = "Ask questions from Auto"
|
9
|
+
# == CONFIGURE ==
|
10
|
+
s.extra_rdoc_files = [ "README.markdown" ]
|
11
|
+
s.files = GEM_FILES.to_a
|
12
|
+
s.has_rdoc = false
|
13
|
+
s.name = GEM_NAME
|
14
|
+
s.platform = Gem::Platform::RUBY
|
15
|
+
s.require_path = "lib"
|
16
|
+
s.version = "0.0.1"
|
17
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Auto
|
2
|
+
module Question
|
3
|
+
|
4
|
+
def after_question(key=nil, value=nil, &block)
|
5
|
+
Questions.after_question(key, value, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def before_question(key=nil, value=nil, &block)
|
9
|
+
Questions.before_question(key, value, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def questions(hash={}, &block)
|
13
|
+
q = Questions
|
14
|
+
hash.each do |key, value|
|
15
|
+
q[key] = value
|
16
|
+
if before_question(key, value)
|
17
|
+
yield if block_given?
|
18
|
+
after_question(key, value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
q.questions
|
22
|
+
end
|
23
|
+
alias :question :questions
|
24
|
+
alias :q :questions
|
25
|
+
|
26
|
+
class Questions
|
27
|
+
|
28
|
+
cattr_accessor :questions
|
29
|
+
@@questions = {}
|
30
|
+
|
31
|
+
class <<self
|
32
|
+
|
33
|
+
def []=(key, value)
|
34
|
+
@@questions[key] = value
|
35
|
+
end
|
36
|
+
|
37
|
+
def [](key)
|
38
|
+
@@questions[key]
|
39
|
+
end
|
40
|
+
|
41
|
+
def after_question(key, value, &block)
|
42
|
+
@@after_question ||= []
|
43
|
+
if block
|
44
|
+
@@after_question << block
|
45
|
+
end
|
46
|
+
if key && !value.nil?
|
47
|
+
@@after_question.each do |callback|
|
48
|
+
callback.call(key, value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def before_question(key, value, &block)
|
54
|
+
@@before_question ||= []
|
55
|
+
if block
|
56
|
+
@@before_question << block
|
57
|
+
end
|
58
|
+
if key && !value.nil?
|
59
|
+
result = true
|
60
|
+
@@before_question.each do |callback|
|
61
|
+
result = callback.call(key, value)
|
62
|
+
break unless result
|
63
|
+
end
|
64
|
+
return result
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2
|
+
|
3
|
+
module Auto
|
4
|
+
describe Auto::Question do
|
5
|
+
|
6
|
+
def run
|
7
|
+
@r.run do
|
8
|
+
q :q1 => "q1", :q2 => "q2"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@r = Runner.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should store questions' do
|
17
|
+
run
|
18
|
+
@r.run do
|
19
|
+
q.should == {
|
20
|
+
:q1 => "q1" ,
|
21
|
+
:q2 => "q2"
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should trigger a "before question" callback' do
|
27
|
+
questions = {}
|
28
|
+
@r.before_question do |key, value|
|
29
|
+
questions[key] = value
|
30
|
+
end
|
31
|
+
run
|
32
|
+
questions.should == { :q1 => "q1", :q2 => "q2" }
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should trigger an "after question" callback' do
|
36
|
+
questions = {}
|
37
|
+
@r.after_question do |key, value|
|
38
|
+
questions[key] = value
|
39
|
+
end
|
40
|
+
run
|
41
|
+
questions.should == { :q1 => "q1", :q2 => "q2" }
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should not trigger "after question" if a "before question" callback returns false' do
|
45
|
+
@r.before_question { |key, value| false }
|
46
|
+
@r.after_question do |key, value|
|
47
|
+
true.should == false # fail test
|
48
|
+
end
|
49
|
+
run
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should yield to a block if specified' do
|
53
|
+
@r.run do
|
54
|
+
q :q1 => "q1", :q2 => "q2" do
|
55
|
+
q[:q1].should == "q1"
|
56
|
+
q[:q2].should == "q2"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$testing = true
|
2
|
+
SPEC = File.dirname(__FILE__)
|
3
|
+
$:.unshift File.expand_path("#{SPEC}/../lib")
|
4
|
+
$:.unshift File.expand_path("#{SPEC}/../../auto/lib")
|
5
|
+
|
6
|
+
require 'auto/require'
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
# Manually add this plugin
|
10
|
+
Auto::Plugins.add File.expand_path("#{SPEC}/../")
|
11
|
+
|
12
|
+
# For use with rspec textmate bundle
|
13
|
+
def debug(object)
|
14
|
+
puts "<pre>"
|
15
|
+
puts object.pretty_inspect.gsub('<', '<').gsub('>', '>')
|
16
|
+
puts "</pre>"
|
17
|
+
end
|
18
|
+
|
19
|
+
Spec::Runner.configure do |config|
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auto-question
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Winton Welsh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-15 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: mail@wintoni.us
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- gemspec.rb
|
26
|
+
- lib/auto/question.rb
|
27
|
+
- MIT-LICENSE
|
28
|
+
- Rakefile
|
29
|
+
- README.markdown
|
30
|
+
- spec/questions_spec.rb
|
31
|
+
- spec/spec.opts
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/winton/auto-question
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Ask questions from Auto
|
61
|
+
test_files: []
|
62
|
+
|