Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14 from salemine/change-write-method

renamed the "write" method to "display" to alleviate confusion.
  • Loading branch information...
commit a319017b355ac17cedb7bfaa3641e8b7ad4fb9cb 2 parents e39fd81 + 4b32655
@oscardelben authored
View
3  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,7 +111,6 @@ def process
end
private
-
def open(name)
Sheet::Open.new(name).open
end
View
8 lib/sheet/copy.rb
@@ -1,6 +1,5 @@
class Sheet
class Copy
-
attr_accessor :name
def initialize(name)
@@ -11,17 +10,16 @@ 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")
+ Sheet.display("A sheet named #{name} could not be found")
end
end
@@ -30,7 +28,7 @@ def copy_sheet
if copy_cmd
Sheet.exec("cat #{Sheet::sheet_path(name)} | #{copy_cmd}", true)
else
- Sheet.write("Could not copy sheet, no copy command found")
+ Sheet.display("Could not copy sheet, no copy command found")
end
end
View
4 lib/sheet/list.rb
@@ -1,4 +1,3 @@
-
class Sheet
class List
@@ -6,8 +5,9 @@ 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
7 lib/sheet/open.rb
@@ -1,7 +1,5 @@
class Sheet
-
class Open
-
attr_accessor :name
def initialize(name)
@@ -12,19 +10,18 @@ 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: /,'')}"
end
else
- Sheet.write sheet_content
+ Sheet.display sheet_content
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 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 initialize(name=nil)
+ @name = name
end
- end
- private
+ 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
- def editor_is_set?
- (editor = Sheet.editor) && editor.length > 0
- end
+ private
+ 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)
+ def create_dir_if_doesnt_exist
+ if ! Sheet.sheets_directory_exists?
+ Dir.mkdir(Sheet.sheets_dir)
+ end
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
Please sign in to comment.
Something went wrong with that request. Please try again.