Skip to content
Browse files

renamed the "write" method to "display" to alleviate confusion.

  • Loading branch information...
1 parent e39fd81 commit 5fc1e3554a45bdc1c9894578bdd383d28488f9f5 @salemine salemine committed May 1, 2012
Showing with 74 additions and 81 deletions.
  1. +13 −14 lib/sheet.rb
  2. +14 −16 lib/sheet/copy.rb
  3. +2 −2 lib/sheet/list.rb
  4. +14 −17 lib/sheet/open.rb
  5. +23 −23 lib/sheet/write.rb
  6. +3 −3 spec/sheet/copy_spec.rb
  7. +1 −2 spec/sheet/list_spec.rb
  8. +2 −2 spec/sheet/open_spec.rb
  9. +2 −2 spec/sheet/write_spec.rb
View
27 lib/sheet.rb
@@ -12,7 +12,7 @@ class Sheet
class << self
# Utility to write to standard output
- def write(message)
+ def display(message)
puts message
end
@@ -111,20 +111,19 @@ def process
end
private
+ def open(name)
+ Sheet::Open.new(name).open
+ end
- def open(name)
- Sheet::Open.new(name).open
- end
-
- def write(name)
- Sheet::Write.new(name).write
- end
+ def write(name)
+ Sheet::Write.new(name).write
+ end
- def list
- Sheet::List.new.list
- end
+ def list
+ Sheet::List.new.list
+ end
- def copy(name)
- Sheet::Copy.new(name).copy
- end
+ def copy(name)
+ Sheet::Copy.new(name).copy
+ end
end
View
30 lib/sheet/copy.rb
@@ -1,6 +1,5 @@
class Sheet
class Copy
-
attr_accessor :name
def initialize(name)
@@ -11,28 +10,27 @@ def copy
if name
check_if_sheet_exists_and_copy_sheet
else
- Sheet.write("Please specify a sheet name!")
+ Sheet.display("Please specify a sheet name!")
end
end
private
-
- def check_if_sheet_exists_and_copy_sheet
- if Sheet.sheet_exists?(name)
- copy_sheet
- else
- Sheet.write("A sheet named #{name} could not be found")
+ def check_if_sheet_exists_and_copy_sheet
+ if Sheet.sheet_exists?(name)
+ copy_sheet
+ else
+ Sheet.display("A sheet named #{name} could not be found")
+ end
end
- end
- def copy_sheet
- copy_cmd = Sheet.copy_command
- if copy_cmd
- Sheet.exec("cat #{Sheet::sheet_path(name)} | #{copy_cmd}", true)
- else
- Sheet.write("Could not copy sheet, no copy command found")
+ def copy_sheet
+ copy_cmd = Sheet.copy_command
+ if copy_cmd
+ Sheet.exec("cat #{Sheet::sheet_path(name)} | #{copy_cmd}", true)
+ else
+ Sheet.display("Could not copy sheet, no copy command found")
+ end
end
- end
end
end
View
4 lib/sheet/list.rb
@@ -1,13 +1,13 @@
-
class Sheet
class List
def list
if Sheet.sheets_directory_exists?
Sheet.exec("ls -1 #{Sheet.sheets_dir}", true)
else
- Sheet.write("No sheet found. Create a new sheet with `sheet new <name>`")
+ Sheet.display("No sheet found. Create a new sheet with `sheet new <name>`")
end
end
+
end
end
View
31 lib/sheet/open.rb
@@ -1,7 +1,5 @@
class Sheet
-
class Open
-
attr_accessor :name
def initialize(name)
@@ -12,29 +10,28 @@ def open
if Sheet.sheet_exists?(name)
process_sheet_content
else
- Sheet.write "A cheat named #{name} doesn't exist.\nYou can create one with sheet new #{name}"
+ Sheet.display "A cheat named #{name} doesn't exist.\nYou can create one with sheet new #{name}"
end
end
private
-
- def process_sheet_content
- if !sheet_urls.empty? && cmd = Sheet.open_command
- sheet_urls.each do |url|
- Sheet.exec "#{cmd} #{url.chomp.sub(/url: /,'')}"
+ def process_sheet_content
+ if !sheet_urls.empty? && cmd = Sheet.open_command
+ sheet_urls.each do |url|
+ Sheet.exec "#{cmd} #{url.chomp.sub(/url: /,'')}"
+ end
+ else
+ Sheet.display sheet_content
end
- else
- Sheet.write sheet_content
end
- end
- def sheet_content
- @sheet_content ||= File.read(Sheet.sheet_path(name))
- end
+ def sheet_content
+ @sheet_content ||= File.read(Sheet.sheet_path(name))
+ end
- def sheet_urls
- @sheet_urls ||= sheet_content.split("\n").reject {|line| line !~ /^url:/ }
- end
+ def sheet_urls
+ @sheet_urls ||= sheet_content.split("\n").reject {|line| line !~ /^url:/ }
+ end
end
end
View
46 lib/sheet/write.rb
@@ -1,31 +1,31 @@
+class Sheet
+ class Write
+ attr_accessor :name
-class Sheet::Write
-
- attr_accessor :name
-
- def initialize(name=nil)
- @name = name
- end
+ def initialize(name=nil)
+ @name = name
+ end
- def write
- return Sheet.write("Please specify a name") unless name
- create_dir_if_doesnt_exist
- if editor_is_set?
- Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}", true)
- else
- Sheet.write "Please set the $EDITOR variable to write files"
+ def write
+ return Sheet.display("Please specify a name") unless name
+ create_dir_if_doesnt_exist
+ if editor_is_set?
+ Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}", true)
+ else
+ Sheet.display "Please set the $EDITOR variable to write files"
+ end
end
- end
- private
+ private
+ def editor_is_set?
+ (editor = Sheet.editor) && editor.length > 0
+ end
- def editor_is_set?
- (editor = Sheet.editor) && editor.length > 0
- end
+ def create_dir_if_doesnt_exist
+ if ! Sheet.sheets_directory_exists?
+ Dir.mkdir(Sheet.sheets_dir)
+ end
+ end
- def create_dir_if_doesnt_exist
- if ! Sheet.sheets_directory_exists?
- Dir.mkdir(Sheet.sheets_dir)
- end
end
end
View
6 spec/sheet/copy_spec.rb
@@ -13,20 +13,20 @@
end
it 'should show an error if name is nil' do
- Sheet.should_receive(:write).with("Please specify a sheet name!")
+ Sheet.should_receive(:display).with("Please specify a sheet name!")
Sheet::Copy.new(nil).copy
end
it 'should show an error if snippet is not found' do
- Sheet.should_receive(:write).with("A sheet named git could not be found")
+ Sheet.should_receive(:display).with("A sheet named git could not be found")
Sheet.stub(:sheet_exists?).with('git') { false }
Sheet::Copy.new('git').copy
end
it 'should show a message if no copy program was found' do
- Sheet.should_receive(:write).with("Could not copy sheet, no copy command found")
+ Sheet.should_receive(:display).with("Could not copy sheet, no copy command found")
Sheet.stub(:copy_command) { nil }
Sheet.stub(:sheet_exists?).with('git') { true }
View
3 spec/sheet/list_spec.rb
@@ -1,4 +1,3 @@
-
require 'spec_helper'
describe Sheet::List do
@@ -22,7 +21,7 @@
end
it 'shows a message' do
- Sheet.should_receive(:write).with("No sheet found. Create a new sheet with `sheet new <name>`")
+ Sheet.should_receive(:display).with("No sheet found. Create a new sheet with `sheet new <name>`")
Sheet::List.new.list
end
View
4 spec/sheet/open_spec.rb
@@ -4,14 +4,14 @@
it "should show a message when the app doesn't exist" do
message = "A cheat named rails doesn't exist.\nYou can create one with sheet new rails"
- Sheet.should_receive(:write).with(message)
+ Sheet.should_receive(:display).with(message)
Sheet::Open.new('rails').open
end
it "should output the sheet content" do
message = "My sheet about git"
- Sheet.should_receive(:write).with(message)
+ Sheet.should_receive(:display).with(message)
s = Sheet::Open.new('git')
Sheet.stub(:sheet_exists?).with('git') { true }
View
4 spec/sheet/write_spec.rb
@@ -9,7 +9,7 @@
end
it 'shows an error message if no argument is passed' do
- Sheet.should_receive(:write).with('Please specify a name')
+ Sheet.should_receive(:display).with('Please specify a name')
Sheet::Write.new.write
end
@@ -24,7 +24,7 @@
it 'returns an error if no editor is found' do
Sheet.stub(:editor) { nil }
- Sheet.should_receive(:write).with { "Please set the $EDITOR variable to write files" }
+ Sheet.should_receive(:display).with { "Please set the $EDITOR variable to write files" }
Sheet::Write.new('tmux').write
end

0 comments on commit 5fc1e35

Please sign in to comment.
Something went wrong with that request. Please try again.