sheet 0.1.2 → 0.1.3
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/README.md +7 -0
 - data/VERSION +1 -1
 - data/lib/sheet.rb +21 -1
 - data/lib/sheet/copy.rb +39 -0
 - data/sheet.gemspec +3 -1
 - data/spec/sheet/copy_spec.rb +39 -0
 - data/spec/sheet/list_spec.rb +1 -1
 - data/spec/sheet/sheet_spec.rb +10 -0
 - metadata +4 -2
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -16,6 +16,7 @@ sheet           # with no arguments it will just list all your sheets 
     | 
|
| 
       16 
16 
     | 
    
         
             
            sheet git       # opens git sheet
         
     | 
| 
       17 
17 
     | 
    
         
             
            sheet new git   # creates git sheet
         
     | 
| 
       18 
18 
     | 
    
         
             
            sheet edit git  # edit git sheet
         
     | 
| 
      
 19 
     | 
    
         
            +
            sheet copy git  # Copies content of the sheet to the clipboard
         
     | 
| 
       19 
20 
     | 
    
         
             
            ```
         
     | 
| 
       20 
21 
     | 
    
         | 
| 
       21 
22 
     | 
    
         
             
            Use `sheet new <term>` to create your first sheet. Useful for jotting
         
     | 
| 
         @@ -40,6 +41,12 @@ automatically open that url for you 
     | 
|
| 
       40 
41 
     | 
    
         
             
            Please note that to open urls, sheet will use the `open` command on mac
         
     | 
| 
       41 
42 
     | 
    
         
             
            os x and `xdg-open` in linux. Patches welcome for other systems.
         
     | 
| 
       42 
43 
     | 
    
         | 
| 
      
 44 
     | 
    
         
            +
            ### Copying sheets
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            sheet will use either `pbcopy` or `xclip` to copy the content of a sheet
         
     | 
| 
      
 47 
     | 
    
         
            +
            to the clipboard, make sure you have one of those installed (or open an
         
     | 
| 
      
 48 
     | 
    
         
            +
            issue indicating another copy program).
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
       43 
50 
     | 
    
         
             
            ### Behind the scenes
         
     | 
| 
       44 
51 
     | 
    
         | 
| 
       45 
52 
     | 
    
         
             
            `sheet` stores your sheets in text files in the
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.1. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.1.3
         
     | 
    
        data/lib/sheet.rb
    CHANGED
    
    | 
         @@ -5,6 +5,7 @@ 
     | 
|
| 
       5 
5 
     | 
    
         
             
            require 'sheet/open'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require 'sheet/write'
         
     | 
| 
       7 
7 
     | 
    
         
             
            require 'sheet/list'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'sheet/copy'
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
            class Sheet
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
         @@ -56,13 +57,25 @@ class Sheet 
     | 
|
| 
       56 
57 
     | 
    
         
             
                def open_command
         
     | 
| 
       57 
58 
     | 
    
         
             
                  if RUBY_PLATFORM =~ /darwin/
         
     | 
| 
       58 
59 
     | 
    
         
             
                    'open'
         
     | 
| 
       59 
     | 
    
         
            -
                  elsif RUBY_PLATFORM =~ /linux/
         
     | 
| 
      
 60 
     | 
    
         
            +
                  elsif RUBY_PLATFORM =~ /linux/ && command_available?('xdg-open')
         
     | 
| 
       60 
61 
     | 
    
         
             
                    'xdg-open'
         
     | 
| 
       61 
62 
     | 
    
         
             
                  else
         
     | 
| 
       62 
63 
     | 
    
         
             
                    nil
         
     | 
| 
       63 
64 
     | 
    
         
             
                  end
         
     | 
| 
       64 
65 
     | 
    
         
             
                end
         
     | 
| 
       65 
66 
     | 
    
         | 
| 
      
 67 
     | 
    
         
            +
                # Returns the copy to clipboard command or nil if no command is
         
     | 
| 
      
 68 
     | 
    
         
            +
                # found
         
     | 
| 
      
 69 
     | 
    
         
            +
                def copy_command
         
     | 
| 
      
 70 
     | 
    
         
            +
                  ['pbcopy', 'xclip'].find { |cmd| command_available?(cmd) }
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                # Utility to check wherever a command is available in the user
         
     | 
| 
      
 74 
     | 
    
         
            +
                # system
         
     | 
| 
      
 75 
     | 
    
         
            +
                def command_available?(cmd)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  %x!type #{cmd}!.chomp.length > 0
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
       66 
79 
     | 
    
         
             
              end
         
     | 
| 
       67 
80 
     | 
    
         | 
| 
       68 
81 
     | 
    
         
             
              # Creates a new instance of Sheet, usually followed by a call to {#process}
         
     | 
| 
         @@ -73,11 +86,14 @@ class Sheet 
     | 
|
| 
       73 
86 
     | 
    
         | 
| 
       74 
87 
     | 
    
         
             
              # Where the dispatching really happens. We check to see what the user
         
     | 
| 
       75 
88 
     | 
    
         
             
              # intended to do and then instantiate the proper class
         
     | 
| 
      
 89 
     | 
    
         
            +
              # TODO: refactor in a switch statement
         
     | 
| 
       76 
90 
     | 
    
         
             
              def process
         
     | 
| 
       77 
91 
     | 
    
         
             
                if ['new', 'edit'].include?(@args[0])
         
     | 
| 
       78 
92 
     | 
    
         
             
                  write(@args[1])
         
     | 
| 
       79 
93 
     | 
    
         
             
                elsif ['ls', 'list'].include?(@args[0]) || @args.empty?
         
     | 
| 
       80 
94 
     | 
    
         
             
                  list
         
     | 
| 
      
 95 
     | 
    
         
            +
                elsif ['cp', 'copy'].include?(@args[0])
         
     | 
| 
      
 96 
     | 
    
         
            +
                  copy(@args[1])
         
     | 
| 
       81 
97 
     | 
    
         
             
                else
         
     | 
| 
       82 
98 
     | 
    
         
             
                  open(@args[0])
         
     | 
| 
       83 
99 
     | 
    
         
             
                end
         
     | 
| 
         @@ -96,4 +112,8 @@ class Sheet 
     | 
|
| 
       96 
112 
     | 
    
         
             
              def list
         
     | 
| 
       97 
113 
     | 
    
         
             
                Sheet::List.new.list
         
     | 
| 
       98 
114 
     | 
    
         
             
              end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
              def copy(name)
         
     | 
| 
      
 117 
     | 
    
         
            +
                Sheet::Copy.new(name).copy
         
     | 
| 
      
 118 
     | 
    
         
            +
              end
         
     | 
| 
       99 
119 
     | 
    
         
             
            end
         
     | 
    
        data/lib/sheet/copy.rb
    ADDED
    
    | 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Sheet
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Copy
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                attr_accessor :name
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                def initialize(name)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @name = name
         
     | 
| 
      
 8 
     | 
    
         
            +
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                def copy
         
     | 
| 
      
 11 
     | 
    
         
            +
                  if name
         
     | 
| 
      
 12 
     | 
    
         
            +
                    check_if_sheet_exists_and_copy_sheet
         
     | 
| 
      
 13 
     | 
    
         
            +
                  else
         
     | 
| 
      
 14 
     | 
    
         
            +
                    Sheet.write("Please specify a sheet name!")
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                private
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def check_if_sheet_exists_and_copy_sheet
         
     | 
| 
      
 21 
     | 
    
         
            +
                  if Sheet.sheet_exists?(name)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    copy_sheet
         
     | 
| 
      
 23 
     | 
    
         
            +
                  else
         
     | 
| 
      
 24 
     | 
    
         
            +
                    Sheet.write("A sheet named #{name} could not be found")
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def copy_sheet
         
     | 
| 
      
 29 
     | 
    
         
            +
                  copy_cmd = Sheet.copy_command
         
     | 
| 
      
 30 
     | 
    
         
            +
                  if copy_cmd
         
     | 
| 
      
 31 
     | 
    
         
            +
                    Sheet.exec("cat #{Sheet::sheet_path(name)} | #{copy_cmd}")
         
     | 
| 
      
 32 
     | 
    
         
            +
                    Sheet.write("Copied!")
         
     | 
| 
      
 33 
     | 
    
         
            +
                  else
         
     | 
| 
      
 34 
     | 
    
         
            +
                    Sheet.write("Could not copy sheet, no copy command found")
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     | 
    
        data/sheet.gemspec
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = "sheet"
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.1. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.1.3"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Oscar Del Ben"]
         
     | 
| 
         @@ -28,10 +28,12 @@ Gem::Specification.new do |s| 
     | 
|
| 
       28 
28 
     | 
    
         
             
                "VERSION",
         
     | 
| 
       29 
29 
     | 
    
         
             
                "bin/sheet",
         
     | 
| 
       30 
30 
     | 
    
         
             
                "lib/sheet.rb",
         
     | 
| 
      
 31 
     | 
    
         
            +
                "lib/sheet/copy.rb",
         
     | 
| 
       31 
32 
     | 
    
         
             
                "lib/sheet/list.rb",
         
     | 
| 
       32 
33 
     | 
    
         
             
                "lib/sheet/open.rb",
         
     | 
| 
       33 
34 
     | 
    
         
             
                "lib/sheet/write.rb",
         
     | 
| 
       34 
35 
     | 
    
         
             
                "sheet.gemspec",
         
     | 
| 
      
 36 
     | 
    
         
            +
                "spec/sheet/copy_spec.rb",
         
     | 
| 
       35 
37 
     | 
    
         
             
                "spec/sheet/list_spec.rb",
         
     | 
| 
       36 
38 
     | 
    
         
             
                "spec/sheet/open_spec.rb",
         
     | 
| 
       37 
39 
     | 
    
         
             
                "spec/sheet/sheet_spec.rb",
         
     | 
| 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Sheet::Copy do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              it 'should copy the snippet' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                cmd = "cat #{Sheet.sheet_path('git')} | pbcopy"
         
     | 
| 
      
 7 
     | 
    
         
            +
                Sheet.should_receive(:exec).with(cmd)
         
     | 
| 
      
 8 
     | 
    
         
            +
                Sheet.should_receive(:write).with("Copied!")
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                Sheet.stub(:copy_command) { 'pbcopy' }
         
     | 
| 
      
 11 
     | 
    
         
            +
                Sheet.stub(:sheet_exists?).with('git') { true }
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                Sheet::Copy.new('git').copy
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              it 'should show an error if name is nil' do
         
     | 
| 
      
 17 
     | 
    
         
            +
                Sheet.should_receive(:write).with("Please specify a sheet name!")
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                Sheet::Copy.new(nil).copy
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              it 'should show an error if snippet is not found' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                Sheet.should_receive(:write).with("A sheet named git could not be found")
         
     | 
| 
      
 24 
     | 
    
         
            +
                Sheet.stub(:sheet_exists?).with('git') { false }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                Sheet::Copy.new('git').copy
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              it 'should show a message if no copy program was found' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                Sheet.should_receive(:write).with("Could not copy sheet, no copy command found")
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                Sheet.stub(:copy_command) { nil }
         
     | 
| 
      
 33 
     | 
    
         
            +
                Sheet.stub(:sheet_exists?).with('git') { true }
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                Sheet::Copy.new('git').copy
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
    
        data/spec/sheet/list_spec.rb
    CHANGED
    
    
    
        data/spec/sheet/sheet_spec.rb
    CHANGED
    
    | 
         @@ -49,4 +49,14 @@ describe Sheet do 
     | 
|
| 
       49 
49 
     | 
    
         
             
                  Sheet.new.process
         
     | 
| 
       50 
50 
     | 
    
         
             
                end
         
     | 
| 
       51 
51 
     | 
    
         
             
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              describe 'copy sheet' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                it 'should instantiate Sheet::Copy' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                  copy = double('Sheet::Copy')
         
     | 
| 
      
 56 
     | 
    
         
            +
                  copy.should_receive(:copy)
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                  Sheet::Copy.stub(:new).with('git') { copy }
         
     | 
| 
      
 59 
     | 
    
         
            +
                  Sheet.new('copy', 'git').process
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
              end
         
     | 
| 
       52 
62 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: sheet
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.3
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -95,10 +95,12 @@ files: 
     | 
|
| 
       95 
95 
     | 
    
         
             
            - VERSION
         
     | 
| 
       96 
96 
     | 
    
         
             
            - bin/sheet
         
     | 
| 
       97 
97 
     | 
    
         
             
            - lib/sheet.rb
         
     | 
| 
      
 98 
     | 
    
         
            +
            - lib/sheet/copy.rb
         
     | 
| 
       98 
99 
     | 
    
         
             
            - lib/sheet/list.rb
         
     | 
| 
       99 
100 
     | 
    
         
             
            - lib/sheet/open.rb
         
     | 
| 
       100 
101 
     | 
    
         
             
            - lib/sheet/write.rb
         
     | 
| 
       101 
102 
     | 
    
         
             
            - sheet.gemspec
         
     | 
| 
      
 103 
     | 
    
         
            +
            - spec/sheet/copy_spec.rb
         
     | 
| 
       102 
104 
     | 
    
         
             
            - spec/sheet/list_spec.rb
         
     | 
| 
       103 
105 
     | 
    
         
             
            - spec/sheet/open_spec.rb
         
     | 
| 
       104 
106 
     | 
    
         
             
            - spec/sheet/sheet_spec.rb
         
     | 
| 
         @@ -119,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       119 
121 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       120 
122 
     | 
    
         
             
                  segments:
         
     | 
| 
       121 
123 
     | 
    
         
             
                  - 0
         
     | 
| 
       122 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 124 
     | 
    
         
            +
                  hash: 1707118375102558031
         
     | 
| 
       123 
125 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       124 
126 
     | 
    
         
             
              none: false
         
     | 
| 
       125 
127 
     | 
    
         
             
              requirements:
         
     |