blirb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.DS_Store ADDED
Binary file
data/.autotest ADDED
@@ -0,0 +1,13 @@
1
+ require 'autotest/growl'
2
+ require 'autotest/fsevent'
3
+
4
+ Autotest.add_hook :initialize do |autotest|
5
+ %w{.git .DS_Store vendor}.each do |exception|
6
+ autotest.add_exception(exception)
7
+ end
8
+ false
9
+ end
10
+
11
+ Autotest.add_hook :green do
12
+ Kernel.system('find . -name "*.rb" | xargs grep -n "# DEBT"')
13
+ end
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lorem.gemspec
4
+ gemspec
5
+
6
+
7
+
8
+
9
+
10
+ source "http://rubygems.org"
11
+ # Add dependencies required to use your gem here.
12
+ # Example:
13
+ # gem "activesupport", ">= 2.3.5"
14
+
15
+ # Add dependencies to develop your gem here.
16
+ # Include everything needed to run rake, tests, features, etc.
17
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 ian asaff
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # Blirb
2
+
3
+ Blirb is a ruby teaching and practice tool that sits on top of IRB, also known
4
+ as the "Interactive Ruby Shell". It can be used in two different ways:
5
+
6
+ ## Using Blirb to learn
7
+
8
+ As a student, Blirb can be used in tutorial mode by running `./bin/blirb`.
9
+ The student selects a task to complete that involves various ruby concepts.
10
+ He is then dropped into a special IRB session where several additional global
11
+ commands have been added.
12
+
13
+
14
+ The following commands are available during the tutorial (irb) session:
15
+
16
+ task - print the current task's description
17
+ done - test to see if you've completed the current task
18
+ help! - view this menu
19
+
20
+ To exit from the tutorial menu, type 'q' or 'exit'.
21
+
22
+
23
+ Below the command list appears a list of selectable tasks:
24
+
25
+ Please choose a task by entering a task number:
26
+
27
+ 0 - set a variable 'dude' with a value, any value
28
+ 1 - set an instance variable 'dude' with a value... any value
29
+
30
+ >
31
+
32
+
33
+ The student types the number of the task and hits enter to choose which task to
34
+ complete. Once in the IRB shell, the student simply completes the task and uses
35
+ the `done` command:
36
+
37
+ Please choose a task by entering task number:
38
+
39
+ 0 - set a variable 'dude' with a value, any value
40
+ 1 - set an instance variable 'dude' with a value... any value
41
+
42
+ > 0
43
+ Ok. set a variable 'dude' with a value, any value. Let's get started.
44
+ ruby-1.9.2-p180 :001 > dude = :hi_mom
45
+ => :hi_mom
46
+ ruby-1.9.2-p180 :002 > done
47
+ nice. that worked.
48
+ =========================
49
+
50
+
51
+ After completing a task, the student arrives back at the initial task menu.
52
+ Blirb remembers completed tasks and only lists those that haven't been
53
+ completed in the current session. In the case below, only task 1 is shown
54
+ because task 0 has already been completed.
55
+
56
+
57
+ To exit from the tutorial menu, type 'q' or 'exit'.
58
+
59
+ Please choose a task by entering task number:
60
+
61
+ 1 - set an instance variable 'dude' with a value... any value
62
+
63
+ >
64
+
65
+
66
+ ## Using Blirb to teach
67
+
68
+ Blirb has a tiny DSL used to define tasks in `blirb_tasks/tasks.rb`. A custom
69
+ tasks file can also be passed in on the command line. Tasks can be defined as
70
+ follows:
71
+
72
+ task "description of task (this is what the student reads)", %{
73
+ code that will be eval'd to test if the task has been passed
74
+ }
75
+
76
+
77
+ When Blirb is started up, it will read either the default task file located in
78
+ `blirb_tasks/tasks.rb` or the one passed in on the command line.
79
+
80
+ ## Final Thought
81
+
82
+ I'm not Jerry Springer, so you're out of luck. But, if you think this project
83
+ is useful and would like to contribute, please fork it! I'd love for this to
84
+ become a standard tool in a new rubyist's toolbox.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.pattern = FileList['spec/**/*_spec.rb']
6
+ end
7
+
8
+ # RSpec::Core::RakeTask.new(:rcov) do |spec|
9
+ # spec.pattern = 'spec/**/*_spec.rb'
10
+ # spec.rcov = true
11
+ # end
12
+
13
+ task :default => :spec
data/bin/blirb ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/blirb'
4
+
5
+ # # if a tasks file is passed in, parse the yml-based tasks and feed them to blirb
6
+
7
+ if ARGV[0]
8
+ blirb = Blirb::Coordinator.new ARGV.shift
9
+ else
10
+ blirb = Blirb::Coordinator.new
11
+ end
12
+
13
+ blirb.go
data/blirb.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "blirb/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "blirb"
7
+ s.version = Blirb::VERSION
8
+ s.authors = ["ian asaff"]
9
+ s.email = ["ian.asaff@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{command line ruby tutorial adventure}
12
+ s.description = %q{ruby adventure awaits! also, you will learn stuff.}
13
+
14
+ s.rubyforge_project = "blirb"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ # s.add_development_dependency "rcov"
24
+ # s.add_runtime_dependency "rest-client"
25
+ end
@@ -0,0 +1,71 @@
1
+ # Example tasks file
2
+ #
3
+ # the format of a task is as follows:
4
+ #
5
+ # task "description of task", %{
6
+ # test code -- code to test that task was completed
7
+ # }, %{
8
+ # verification code -- code that performs the task to that the test will pass
9
+ # }
10
+
11
+ task "Set a variable 'dude' with a value, any value", %{
12
+ defined?(dude)
13
+ }, %{
14
+ dude = :dude
15
+ }
16
+
17
+ task "Set an instance variable 'dude' with a value... any value", %{
18
+ defined?(@dude)
19
+ }, %{
20
+ @dude = :dude
21
+ }
22
+
23
+ task "Create a class 'Bro' that has an instance method 'fist_bump'. The method should return a symbol ':yeah_bro'", %{
24
+ Bro.new.fist_bump == :yeah_bro
25
+ }, %{
26
+ class Bro
27
+ def fist_bump
28
+ :yeah_bro
29
+ end
30
+ end
31
+ }
32
+
33
+ task "Give 'Bro' a class method called 'protein_shake' that returns the string 'getting hyooge!'", %{
34
+ Bro.protein_shake == 'getting hyooge!'
35
+ }, %{
36
+ class Bro
37
+ def self.protein_shake
38
+ "getting hyooge!"
39
+ end
40
+ end
41
+ }
42
+
43
+ task "Define 'Bro' so that he has a private method 'drink_natty_ice'. The method should return :yah_dude", %{
44
+ bro = Bro.new
45
+ bro.private_methods.include?(:drink_natty_ice) && bro.send(:drink_natty_ice) == :yah_dude
46
+ }, %{
47
+ class Bro
48
+ private
49
+ def drink_natty_ice
50
+ :yah_dude
51
+ end
52
+ end
53
+ }
54
+
55
+ task "Create a 'Bro' object in the variable 'brah'. Give brah (and only brah) the ability to chug_chug_chug, which will return :full", %{
56
+ broo = Bro.new
57
+ (brah.chug_chug_chug == :full) && (brah.methods - broo.methods == [:chug_chug_chug]) && (brah.private_methods - broo.private_methods).empty?
58
+ }, %{
59
+ brah = Bro.new
60
+ def brah.chug_chug_chug
61
+ :full
62
+ end
63
+ }
64
+
65
+ task "Create a new 'LittleBro' object that inherits from 'Bro'", %{
66
+ LittleBro.ancestors[1] == Bro
67
+ }, %{
68
+ class Bro; end
69
+ class LittleBro < Bro; end
70
+ }
71
+
data/lib/blirb.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'irb'
2
+ require_relative 'blirb/commands'
3
+ require_relative 'blirb/task'
4
+ require_relative 'blirb/behaviors'
5
+ require_relative 'blirb/core_extensions'
6
+ require_relative 'blirb/coordinator'
@@ -0,0 +1,42 @@
1
+ # adds blirb functionality
2
+ module Blirb
3
+ module Behaviors
4
+ module ClassMethods
5
+ end
6
+
7
+ module InstanceMethods
8
+
9
+ def help!
10
+ puts
11
+ Blirb::COMMANDS.each do |command|
12
+ puts %{\t\t#{command}}
13
+ end
14
+ puts
15
+ end
16
+
17
+ def task
18
+ Object.class_eval do
19
+ puts @blirb.current_task.description if @blirb.current_task
20
+ end
21
+ end
22
+
23
+ def done
24
+ b = context.workspace.binding
25
+ Object.class_eval do
26
+ if @blirb.current_task.test!(b)
27
+ puts "Nice. That worked."
28
+ puts "========================="
29
+ @blirb.menu
30
+ else
31
+ puts "Test failed. Try again."
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def self.included(receiver)
38
+ receiver.extend ClassMethods
39
+ receiver.send :include, InstanceMethods
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ module Blirb
2
+ COMMANDS = [
3
+ "task - print the current task's description",
4
+ "done - test to see if you've completed the current task",
5
+ "help! - view this menu"
6
+ ]
7
+ end
@@ -0,0 +1,82 @@
1
+ module Blirb
2
+ class Coordinator
3
+ attr_reader :current_task, :tasks
4
+ DEFAULT_TASKS = 'blirb_tasks/tasks.rb'
5
+
6
+ def initialize file_path = nil
7
+ @tasks = []
8
+ load_tasks file_path || DEFAULT_TASKS
9
+ @current_task = nil
10
+ blirb = self
11
+ Object.class_eval do
12
+ @blirb = blirb
13
+ end
14
+ end
15
+
16
+ def go
17
+ menu
18
+ IRB.start
19
+ end
20
+
21
+ # displays menu, sets the current task
22
+ def menu
23
+ end_tutorial if remaining_tasks.empty?
24
+ list_commands
25
+ puts "\nPlease choose a task by entering task number (completed tasks will not appear):\n\n"
26
+ list_tasks
27
+
28
+ while true
29
+ print "\n> "
30
+ if integer?( (selection = gets.chomp) ) && @tasks[(selection = selection.to_i)]
31
+ select_task selection
32
+ break
33
+ elsif selection == 'q' || selection == 'exit' # variety is the spice of life
34
+ exit
35
+ end
36
+ puts "Sorry, I'm not sure what you're trying to do. Please do something different."
37
+ end
38
+ end
39
+
40
+ private
41
+ def list_commands
42
+ puts "\nThe following commands are available during the tutorial (irb) session:\n\n"
43
+ Blirb::COMMANDS.each do |command|
44
+ puts "\t#{command}\n"
45
+ end
46
+ puts "\nTo exit from the tutorial menu, type 'q' or 'exit'.\n"
47
+ end
48
+
49
+ def select_task selection
50
+ @current_task = @tasks[selection]
51
+ puts "Ok. #{@current_task.description}. Let's get started."
52
+ end
53
+
54
+ def list_tasks
55
+ @tasks.each_with_index do |task, index|
56
+ puts "#{index} - #{task.description}" unless task.passed?
57
+ end
58
+ end
59
+
60
+ def end_tutorial
61
+ puts "Thanks for completing the tutorial. FORK ME ON GITHUB!"
62
+ exit
63
+ end
64
+
65
+ def load_tasks file_path
66
+ eval File.read(file_path)
67
+ end
68
+
69
+ # used for task definitions in blirb_tasks/tasks.rb
70
+ def task description, test_code, validation_code
71
+ @tasks << Task.new(description, test_code, validation_code)
72
+ end
73
+
74
+ def remaining_tasks
75
+ @tasks.select {|task| !task.passed?}
76
+ end
77
+
78
+ def integer? n
79
+ n =~ /^\d+\Z/
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ class Object
2
+ include Blirb::Behaviors
3
+ end
data/lib/blirb/task.rb ADDED
@@ -0,0 +1,30 @@
1
+ # Represents a task that a user must complete
2
+ module Blirb
3
+ class Task
4
+ attr_reader :test,:description
5
+
6
+ def initialize(description, test, verification_code)
7
+ @description = description
8
+ @passed = false
9
+ @test = test
10
+ @verification_code = verification_code
11
+ end
12
+
13
+ def test!(b)
14
+ @passed = !!eval(@test,b)
15
+ end
16
+
17
+ def passed?
18
+ @passed
19
+ end
20
+
21
+ def verify!(b)
22
+ begin
23
+ eval(@verification_code, b)
24
+ test!(b)
25
+ rescue
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Blirb
2
+ VERSION = "0.0.1"
3
+ end
Binary file
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Blirb" do
4
+ it "fails" do
5
+ # fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'blirb'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
13
+
14
+ class TaskTester
15
+ TASKS_TO_VERIFY = 'blirb_tasks/tasks.rb'
16
+
17
+ attr_reader :tasks
18
+ def initialize(file_path=nil)
19
+ file_path ||= TASKS_TO_VERIFY
20
+ @tasks = []
21
+ eval File.read(file_path)
22
+ end
23
+
24
+ # used for task definitions in blirb_tasks/tasks.rb
25
+ def task description, test_code, validation_code
26
+ @tasks << ::Blirb::Task.new(description, test_code, validation_code)
27
+ end
28
+ end
data/spec/task_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "each task" do
4
+ it "has verification code that allows it to pass" do
5
+ TaskTester.new.tasks.each do |task|
6
+ task.verify!(binding).should be_true
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blirb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ian asaff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70314144342360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70314144342360
25
+ description: ruby adventure awaits! also, you will learn stuff.
26
+ email:
27
+ - ian.asaff@gmail.com
28
+ executables:
29
+ - blirb
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .DS_Store
34
+ - .autotest
35
+ - .document
36
+ - .gitignore
37
+ - .rspec
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/blirb
43
+ - blirb.gemspec
44
+ - blirb_tasks/tasks.rb
45
+ - lib/blirb.rb
46
+ - lib/blirb/behaviors.rb
47
+ - lib/blirb/commands.rb
48
+ - lib/blirb/coordinator.rb
49
+ - lib/blirb/core_extensions.rb
50
+ - lib/blirb/task.rb
51
+ - lib/blirb/version.rb
52
+ - pkg/blirb-0.0.1.gem
53
+ - spec/blirb_spec.rb
54
+ - spec/spec_helper.rb
55
+ - spec/task_spec.rb
56
+ homepage: ''
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: blirb
76
+ rubygems_version: 1.8.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: command line ruby tutorial adventure
80
+ test_files:
81
+ - spec/blirb_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/task_spec.rb