take_a_memo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.6.1"
11
+ gem "rcov", ">= 0"
12
+ gem 'ruby_parser'
13
+ gem 'file-tail'
14
+ gem 'sourcify'
15
+ end
16
+
17
+ group :test do
18
+ gem 'rspec'
19
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ file-tail (1.0.5)
6
+ spruz (>= 0.1.0)
7
+ git (1.2.5)
8
+ jeweler (1.6.2)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rake (0.9.2)
13
+ rcov (0.9.9)
14
+ rspec (2.6.0)
15
+ rspec-core (~> 2.6.0)
16
+ rspec-expectations (~> 2.6.0)
17
+ rspec-mocks (~> 2.6.0)
18
+ rspec-core (2.6.3)
19
+ rspec-expectations (2.6.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.6.0)
22
+ ruby2ruby (1.2.5)
23
+ ruby_parser (~> 2.0)
24
+ sexp_processor (~> 3.0)
25
+ ruby_parser (2.0.6)
26
+ sexp_processor (~> 3.0)
27
+ sexp_processor (3.0.5)
28
+ sourcify (0.5.0)
29
+ file-tail (>= 1.0.5)
30
+ ruby2ruby (>= 1.2.5)
31
+ ruby_parser (>= 2.0.5)
32
+ sexp_processor (>= 3.0.5)
33
+ spruz (0.2.7)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.0.0)
40
+ file-tail
41
+ jeweler (~> 1.6.1)
42
+ rcov
43
+ rspec
44
+ ruby_parser
45
+ sourcify
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 vertigoclinic
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.rdoc ADDED
@@ -0,0 +1,52 @@
1
+ = take_a_memo
2
+
3
+ This is a very simple gem that allows you to capture the commands you run in your irb session in mini-scripts that you can replay later.
4
+
5
+ = Installing it
6
+
7
+ $ gem install take_a_memo
8
+
9
+ = Using it
10
+
11
+ Here's a really basic example of how it works.
12
+
13
+ >> take_a_memo "remember this" do
14
+ ?> 1 + 1
15
+ >> end
16
+ memo returned: 2
17
+ => nil
18
+
19
+ >> show_my_memos
20
+ Here's your memos:
21
+ - remember this
22
+ => nil
23
+
24
+ >> play_it_back("remember this")
25
+ memo returned: 2
26
+ => nil
27
+
28
+ >> trash_this_memo("remember this")
29
+ => ["/Users/vertigoclinic/.irb_memos/remember_this.rb"]
30
+
31
+ You can set this up in your .irbrc file like this:
32
+
33
+ require 'take_a_memo'
34
+ include TakeAMemo
35
+
36
+ The storage location for the memos defaults to ~/.irb_memos, but you can change it by setting ENV['IRB_MEMO_DIR']
37
+
38
+ == Contributing to take_a_memo
39
+
40
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
41
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
42
+ * Fork the project
43
+ * Start a feature/bugfix branch
44
+ * Commit and push until you are happy with your contribution
45
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
46
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
47
+
48
+ == Copyright
49
+
50
+ Copyright (c) 2011 vertigoclinic. See LICENSE.txt for
51
+ further details.
52
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "take_a_memo"
18
+ gem.homepage = "http://github.com/vertigoclinic/take_a_memo"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A simple gem to record commands from your irb session}
21
+ gem.description = %Q{A simple gem to record commands from your irb session}
22
+ gem.email = "vertigoclinic@gmail.com"
23
+ gem.authors = ["vertigoclinic"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "take_a_memo #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,57 @@
1
+ require 'sourcify'
2
+
3
+ module TakeAMemo
4
+
5
+ IRB_MEMO_DIR = ENV['IRB_MEMO_DIR'] || "#{ENV['HOME']}/.irb_memos"
6
+
7
+ def take_a_memo(title, &block)
8
+ unless block_given?
9
+ puts "nothing to remember here!"
10
+ return
11
+ end
12
+ file = create_file(title)
13
+ file.write(block.to_raw_source)
14
+ file.close
15
+ execute_commands(file)
16
+ end
17
+
18
+ def play_it_back(memo)
19
+ unless file = File.open("#{IRB_MEMO_DIR}/#{memo.gsub(" ", "_")}.rb")
20
+ puts "couldn't find file for #{memo}"
21
+ return
22
+ end
23
+ execute_commands(file)
24
+ end
25
+
26
+
27
+ def show_my_memos
28
+ unless File.exists?(IRB_MEMO_DIR) and Dir.entries(IRB_MEMO_DIR).size > 0
29
+ puts "you have no saved memos"
30
+ return
31
+ end
32
+ puts %Q|Here's your memos:\n|
33
+ puts Dir.entries(IRB_MEMO_DIR).reject {|m| m =~ /^\./ }.map {|m| "\t - #{m.gsub(".rb", "").gsub("_", " ")}" }.join("\n")
34
+ end
35
+
36
+ def trash_this_memo(memo)
37
+ unless File.exists?("#{IRB_MEMO_DIR}/#{memo.gsub(" ", "_")}.rb")
38
+ puts "couldn't find file to remove for #{memo}"
39
+ end
40
+ FileUtils.rm("#{IRB_MEMO_DIR}/#{memo.gsub(" ", "_")}.rb")
41
+ end
42
+
43
+ private
44
+
45
+
46
+ def create_file(title)
47
+ FileUtils.mkdir_p(IRB_MEMO_DIR) unless File.exists?(IRB_MEMO_DIR)
48
+ File.new("#{IRB_MEMO_DIR}/#{title.gsub(" ", "_")}.rb", "w")
49
+ end
50
+
51
+ def execute_commands(file)
52
+ cmd = IO.read(file.path)
53
+ output = eval cmd
54
+ puts "memo returned: #{output.call}"
55
+ end
56
+
57
+ end
@@ -0,0 +1,18 @@
1
+ ENV['IRB_MEMO_DIR'] = "/var/tmp/.irb_memos"
2
+ require File.join(File.dirname(__FILE__), '..', 'lib/take_a_memo')
3
+ include TakeAMemo
4
+
5
+ require 'stringio'
6
+
7
+ module Kernel
8
+
9
+ def capture_stdout
10
+ out = StringIO.new
11
+ $stdout = out
12
+ yield
13
+ return out
14
+ ensure
15
+ $stdout = STDOUT
16
+ end
17
+
18
+ end
@@ -0,0 +1,99 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec/spec_helper')
2
+ require 'fileutils'
3
+
4
+ describe "TakeAMemo" do
5
+
6
+ before do
7
+
8
+ end
9
+
10
+ it "should print an error if no commands are given" do
11
+ output = capture_stdout do
12
+ take_a_memo "remember something"
13
+ end
14
+ output.string.should match("nothing to remember")
15
+ end
16
+
17
+ it "should create a file for the commands" do
18
+ take_a_memo "remember something" do
19
+ 1 + 1
20
+ puts "#{1 + 1}"
21
+ end
22
+ File.exists?("#{ENV['IRB_MEMO_DIR']}/remember_something.rb").should_not be(false)
23
+ end
24
+
25
+ it "should put the commands in the file" do
26
+ take_a_memo "remember_something" do
27
+ 1 + 1
28
+ puts "#{1 + 1}"
29
+ end
30
+ File.open("#{ENV['IRB_MEMO_DIR']}/remember_something.rb").read.should match("puts")
31
+ end
32
+
33
+ it "should execute a single command" do
34
+ output = capture_stdout do
35
+ take_a_memo "remember_something" do
36
+ puts "hello"
37
+ end
38
+ end
39
+ output.string.should match("hello")
40
+ end
41
+
42
+ it "should execute multiple commands" do
43
+ output = capture_stdout do
44
+ take_a_memo "remember_something" do
45
+ h = Hash.new(:a => 1, :b => 4)
46
+ 1 + 1
47
+ end
48
+ end
49
+ output.string.should match("2")
50
+ end
51
+
52
+ it "should allow you to replay previous commands" do
53
+ take_a_memo "remember_something" do
54
+ h = Hash.new(:a => 1, :b => 4)
55
+ 1 + 1
56
+ end
57
+ output = capture_stdout do
58
+ play_it_back("remember_something")
59
+ end
60
+ output.string.should match("2")
61
+ end
62
+
63
+ it "should display a list of your commands" do
64
+ %w[one two three].each do |num|
65
+ take_a_memo "remember #{num}" do
66
+ 1 + 1
67
+ end
68
+ end
69
+ output = capture_stdout do
70
+ show_my_memos
71
+ end
72
+ output.string.should match("three")
73
+ end
74
+
75
+ it "should show a message if there are no commands to list" do
76
+ output = capture_stdout do
77
+ show_my_memos
78
+ end
79
+ output.string.should match("you have no saved memos")
80
+ end
81
+
82
+ it "should allow you to remove unwanted commands" do
83
+ %w[one two three].each do |num|
84
+ take_a_memo "remember #{num}" do
85
+ 1 + 1
86
+ end
87
+ end
88
+ trash_this_memo("remember three")
89
+ output = capture_stdout do
90
+ show_my_memos
91
+ end
92
+ output.string.should_not match("three")
93
+ end
94
+
95
+ after do
96
+ FileUtils.rm_r("#{ENV['IRB_MEMO_DIR']}") if File.directory?("#{ENV['IRB_MEMO_DIR']}")
97
+ end
98
+
99
+ end
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{take_a_memo}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["vertigoclinic"]
12
+ s.date = %q{2011-06-18}
13
+ s.description = %q{A simple gem to record commands from your irb session}
14
+ s.email = %q{vertigoclinic@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/take_a_memo.rb",
28
+ "spec/spec_helper.rb",
29
+ "spec/take_a_memo_spec.rb",
30
+ "take_a_memo.gemspec",
31
+ "take_a_memo.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/vertigoclinic/take_a_memo}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{A simple gem to record commands from your irb session}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.1"])
46
+ s.add_development_dependency(%q<rcov>, [">= 0"])
47
+ s.add_development_dependency(%q<ruby_parser>, [">= 0"])
48
+ s.add_development_dependency(%q<file-tail>, [">= 0"])
49
+ s.add_development_dependency(%q<sourcify>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
53
+ s.add_dependency(%q<rcov>, [">= 0"])
54
+ s.add_dependency(%q<ruby_parser>, [">= 0"])
55
+ s.add_dependency(%q<file-tail>, [">= 0"])
56
+ s.add_dependency(%q<sourcify>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ s.add_dependency(%q<ruby_parser>, [">= 0"])
63
+ s.add_dependency(%q<file-tail>, [">= 0"])
64
+ s.add_dependency(%q<sourcify>, [">= 0"])
65
+ end
66
+ end
67
+
data/take_a_memo.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'lib/take_a_memo')
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: take_a_memo
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - vertigoclinic
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-06-18 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: jeweler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 6
45
+ - 1
46
+ version: 1.6.1
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rcov
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: ruby_parser
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: file-tail
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
90
+ name: sourcify
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *id006
102
+ description: A simple gem to record commands from your irb session
103
+ email: vertigoclinic@gmail.com
104
+ executables: []
105
+
106
+ extensions: []
107
+
108
+ extra_rdoc_files:
109
+ - LICENSE.txt
110
+ - README.rdoc
111
+ files:
112
+ - .document
113
+ - Gemfile
114
+ - Gemfile.lock
115
+ - LICENSE.txt
116
+ - README.rdoc
117
+ - Rakefile
118
+ - VERSION
119
+ - lib/take_a_memo.rb
120
+ - spec/spec_helper.rb
121
+ - spec/take_a_memo_spec.rb
122
+ - take_a_memo.gemspec
123
+ - take_a_memo.rb
124
+ has_rdoc: true
125
+ homepage: http://github.com/vertigoclinic/take_a_memo
126
+ licenses:
127
+ - MIT
128
+ post_install_message:
129
+ rdoc_options: []
130
+
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 73392461
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ requirements: []
151
+
152
+ rubyforge_project:
153
+ rubygems_version: 1.3.7
154
+ signing_key:
155
+ specification_version: 3
156
+ summary: A simple gem to record commands from your irb session
157
+ test_files: []
158
+