From 67e9295f55ea2a2d7353be10393c7d02c4581cda Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Sat, 20 Aug 2016 05:40:49 -0400 Subject: [PATCH 1/6] Add template to server as a guide for extending Betty --- lib/_template.rb | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/_template.rb diff --git a/lib/_template.rb b/lib/_template.rb new file mode 100644 index 0000000..1e04fa6 --- /dev/null +++ b/lib/_template.rb @@ -0,0 +1,65 @@ +# +# This file is a template that is designed to give you a starting point for extending Betty +# Copy this file to what you want to extend Betty with. Personally I wrote this as a precursor to +# extending Betty to supporting git development so my first step would be +# +# cp lib/_template.rb lib/git.rb +# + +module _Template + # + # If you need unit conversions or other meta methods you'd want to locate them here at the top to be consistent with the code base + # See process.rb for examples or convert.rb + + # + # You need a self.interpret method which grabs the command and deals with it + # + def self.interpret(command) + responses = [] + + # + # The guts generally boil down to one or more regular expression matcher against the user's command + # + # Remember to use \s+ as a token delimiter and use () for grouping + # + if command.match(/^$/) + search_term = $1.gsub(' ', '%20') + + # + # Build a hash of the possible responses to the user (Note :url is a new idea that I'm floating here) + # + # Your typical options are :command, :say, :explanation + # :command represents the command you want to give the user + # :say is something to be said out loud + # :explanation is what we're teaching the user + # :url is an web url where more details are available + # + # Use Command.browser(url) as a way to open a url + # + responses << { + :command => "", + :explanation => "" + } + end + + # + # Return responses + # + responses + end + + # + # The help structure + # + def self.help + commands = [] + commands << { + :category => "", + :description => '', + :usage => [""] + } + commands + end +end + +$executors << Map From 8a1af64dfd543cdd04f298cde830f5fc73b3ca76 Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Sun, 21 Aug 2016 23:04:07 -0400 Subject: [PATCH 2/6] Fix class name to eliminate illegal characters --- lib/_template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/_template.rb b/lib/_template.rb index 1e04fa6..fcef978 100644 --- a/lib/_template.rb +++ b/lib/_template.rb @@ -6,7 +6,7 @@ # cp lib/_template.rb lib/git.rb # -module _Template +module Template # # If you need unit conversions or other meta methods you'd want to locate them here at the top to be consistent with the code base # See process.rb for examples or convert.rb From b225db17cc626b4f43270872a12bd61f37397d17 Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Sun, 21 Aug 2016 23:34:43 -0400 Subject: [PATCH 3/6] Add some simple fun routines to get used to working on Betty --- lib/fun.rb | 13 +++++++++++++ lib/{_template.rb => template.rb} | 0 spec/fun_spec.rb | 8 ++++++++ 3 files changed, 21 insertions(+) rename lib/{_template.rb => template.rb} (100%) diff --git a/lib/fun.rb b/lib/fun.rb index 1744e76..99ddd7d 100755 --- a/lib/fun.rb +++ b/lib/fun.rb @@ -8,6 +8,19 @@ def self.interpret(command) } end + if command.match(/^superman\s+vs\s+batman$/i) + responses << { + say: [true,false].sample ? "Batman" : "Superman" + } + end + + if command.match(/^what\s+if\s+batman\s+does\snot\s+have\s+a?n?y?\s*kryptonite$/i) + responses << { + say: "Batman always has kryptonite" + } + end + + if command.match(/^open\s(the\s)?pod\sbay\sdoor(s)?$/i) responses << { :say => "I'm sorry, Dave. I'm afraid I can't do that." diff --git a/lib/_template.rb b/lib/template.rb similarity index 100% rename from lib/_template.rb rename to lib/template.rb diff --git a/spec/fun_spec.rb b/spec/fun_spec.rb index 4ef29a9..8c24106 100644 --- a/spec/fun_spec.rb +++ b/spec/fun_spec.rb @@ -13,5 +13,13 @@ context 'sudo make me a sandwich' do it { responds_with say: "I think you meant to place sudo at the start of the command." } end + + context "what if batman does not have any kryptonite" do + it { responds_with say: "Batman always has kryptonite" } + end + + context "what if batman does not have kryptonite" do + it { responds_with say: "Batman always has kryptonite" } + end end From 8594d6d7cc96f1357887131f92c0c63bf640e84d Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Sun, 21 Aug 2016 23:38:01 -0400 Subject: [PATCH 4/6] Make changes to template structure where I didn't understand it well --- lib/template.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/template.rb b/lib/template.rb index fcef978..bff84cd 100644 --- a/lib/template.rb +++ b/lib/template.rb @@ -62,4 +62,6 @@ def self.help end end -$executors << Map +# this last line is where the magic actually happens; you need to take the executors and assign it to something that does the work +# here it is commented out since this is, well, a template +#$executors << Some Class Goes Here From 3148b3b78b77b2e41792bee4b154ba6860d714cb Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Sun, 21 Aug 2016 23:58:42 -0400 Subject: [PATCH 5/6] Happy dance - first module written for betty --- lib/git.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 lib/git.rb diff --git a/lib/git.rb b/lib/git.rb new file mode 100755 index 0000000..b9d6581 --- /dev/null +++ b/lib/git.rb @@ -0,0 +1,24 @@ +module Git + def self.interpret(command) + responses = [] + + if command.match(/^undo\s+git\s+add$/i) + responses << { + :say => "To undo a single file use\n\ngit reset filespec\n\n\nTo undo ALL files added (i.e. you want to undo git add .) then use\n\ngit reset" + } + end + + responses + end + + def self.help + commands = [] + commands << { + :category => "Git", + :usage => ["undo git add"] + } + commands + end +end + +$executors << Git \ No newline at end of file From 481469bdcb015aac81ab6d44a9852b3c4aa5ca8f Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Mon, 22 Aug 2016 00:18:13 -0400 Subject: [PATCH 6/6] Test coverage albeit minimal on git --- spec/git_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/git_spec.rb diff --git a/spec/git_spec.rb b/spec/git_spec.rb new file mode 100644 index 0000000..3eeac9e --- /dev/null +++ b/spec/git_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe 'Fun' do + + context 'undo git add' do + it { responds_with say: "To undo a single file use\n\ngit reset filespec\n\n\nTo undo ALL files added (i.e. you want to undo git add .) then use\n\ngit reset" } + end + +end