noter 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c87786d868ea352b1cba38c7cc11531c8a438cc8
4
- data.tar.gz: 27bc6a124918df8f115aac6ec4dd35669191ae13
3
+ metadata.gz: 24a405e2ffe8fc73d6315ce36bec44d2a67b621a
4
+ data.tar.gz: a3603bbc7dbbbf662501c5f69e73f85b3fec538d
5
5
  SHA512:
6
- metadata.gz: e460c85a77f5e210dd9e1b44e85ea61e57dfc00f12955679cfd5de90f15a34d681090afcfd18691996073fa8a02fd4555ae8e0c81fc69c95870e0c79940d31d6
7
- data.tar.gz: fa88760035b1659513e3846802b91eac0c80751f87e4cd42f0d0c2abcb3c8f633657a2402967f34acda8e6191c2b9d6aad28ae1a77bd2609000b836a8e89a15a
6
+ metadata.gz: 4b79b72a1c8a004dcbb7ce8dde204b9402b3a9fc66731d395b750a9d14336a8903c9649f51af7e060cc3a72782abbb033ca9e7a1d1bd065d88efd3b89ba48acf
7
+ data.tar.gz: 3a7f667891072910ee06345eb365ef4c851da02b1b6fc2d12a859986b060a21968471b8c562f94f5e96dcea9b0046742d48794efcc9aaca098c0f3c3aad50a98
data/bin/noter CHANGED
@@ -5,7 +5,7 @@ require "optparse"
5
5
 
6
6
  class NoteRunner
7
7
  def initialize
8
- @paging = true
8
+ @options = {:paging => true}
9
9
  end
10
10
 
11
11
  def run(args)
@@ -15,16 +15,16 @@ class NoteRunner
15
15
 
16
16
  def run_command
17
17
  case @command
18
- when :make_from_file
19
- Noter::FileMaker.new.make_from_file(@filename)
18
+ when :show_file_from_index
19
+ Noter::Viewer.new(@options).show_file_from_index(@index)
20
20
  when :show_first_lines
21
- Noter::Viewer.new(:paging => @paging).show_first_lines(:with_filename => @show_names)
21
+ Noter::Viewer.new(@options).show_first_lines(:with_filename => @show_names)
22
+ when :show_files
23
+ Noter::Viewer.new(@options).show_files
22
24
  when :create_from_string
23
25
  Noter::FileMaker.new(@message).save_file
24
- when :show_last_n_files
25
- Noter::Viewer.new(:paging => @paging).show_last_n_files(@count)
26
- when :show_file_from_index
27
- Noter::Viewer.new(:paging => @paging).show_file_from_index(@index)
26
+ when :make_from_file
27
+ Noter::FileMaker.new.make_from_file(@filename)
28
28
  end
29
29
  end
30
30
 
@@ -35,32 +35,46 @@ class NoteRunner
35
35
  @filename = filename
36
36
  end
37
37
 
38
+ opts.on("-g", "--grep STRING", "Only show files that contain a specific string") do |grep_string|
39
+ @options[:grep_string] = grep_string
40
+ end
41
+
38
42
  opts.on("-l", "--one-line", "Show first line of each note file") do
39
43
  @command = :show_first_lines
40
44
  end
41
45
 
46
+ opts.on("-m", "--message MESSAGE", "Create a note using the given string") do |message|
47
+ @command = :create_from_string
48
+ @message = message
49
+ end
50
+
42
51
  opts.on("-n", "--name", "Include names when showing files") do
43
52
  @command = :show_first_lines
44
53
  @show_names = true
45
54
  end
46
55
 
47
- opts.on("-m", "--message MESSAGE", "Create a note using the given string") do |message|
48
- @command = :create_from_string
49
- @message = message
56
+ opts.on("--no-color", "Don't colorize output") do
57
+ @options[:colorize] = false
58
+ end
59
+
60
+ opts.on("-s", "--search STRING", "Show a file with the given index") do |grep_string|
61
+ @options[:tail_count] = 100 unless @options[:tail_count]
62
+ @options[:grep_string] = grep_string
63
+ @command = :show_files
50
64
  end
51
65
 
52
66
  opts.on("-t", "--tail COUNT", "the last n files") do |count|
53
- @command = :show_last_n_files
54
- @count = count
67
+ @command = :show_files
68
+ @options[:tail_count] = count
55
69
  end
56
70
 
57
- opts.on("-s", "--show INDEX", "Show a file with the given index") do |index|
58
- @command = :show_file_from_index
59
- @index = index
71
+ opts.on("-u", "--unpaged", "Don't page the output") do
72
+ @options[:paging] = false
60
73
  end
61
74
 
62
- opts.on("-u", "--unpaged", "Don't page the output") do |count|
63
- @paging = false
75
+ opts.on("-v", "--view INDEX", "View a file with the given index") do |index|
76
+ @command = :show_file_from_index
77
+ @index = index
64
78
  end
65
79
  end
66
80
  parser.parse!
data/lib/noter/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Noter
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/noter/viewer.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "noter/note_file"
2
2
  require "pager"
3
+ require "colorize"
3
4
 
4
5
  module Noter
5
6
  class Viewer
@@ -9,10 +10,23 @@ module Noter
9
10
 
10
11
  def initialize(options = {})
11
12
  @do_paging = options[:paging].nil? ? true : options[:paging]
13
+ @do_colors = options[:colorize].nil? ? true : options[:colorize]
14
+ @grep_string = options[:grep_string]
15
+ @tail_count = options[:tail_count].nil? ? false : options[:tail_count].to_i
12
16
  end
13
17
 
14
18
  def existing_files
15
- @existing_files ||= Dir.glob("#{NoteFile.dir}/*")
19
+ return @existing_files if @existing_files
20
+
21
+ if @grep_string
22
+ @existing_files = `grep -l #{@grep_string} #{NoteFile.dir}/*`.split("\n")
23
+ else
24
+ @existing_files = Dir.glob("#{NoteFile.dir}/*")
25
+ end
26
+ if @tail_count
27
+ @existing_files = @existing_files.last(@tail_count)
28
+ end
29
+ @existing_files
16
30
  end
17
31
 
18
32
  def show_first_lines(options = {})
@@ -40,9 +54,13 @@ module Noter
40
54
  puts contents
41
55
  end
42
56
 
43
- def show_last_n_files(num_files)
44
- existing_files.last(num_files.to_i).each do |filename|
45
- puts "\n\n#{filename}"
57
+ def show_files
58
+ existing_files.each do |filename|
59
+ if @do_colors
60
+ puts "\n\n#{filename}".colorize(:red)
61
+ else
62
+ puts "\n\n#{filename}"
63
+ end
46
64
  show_file(filename)
47
65
  end
48
66
  end
data/noter.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "pry", "~> 0.10"
27
27
  spec.add_development_dependency "pry-nav", "~> 0.2"
28
28
  spec.add_dependency "pager", "~> 1.0"
29
+ spec.add_dependency "colorize"
29
30
  end
@@ -21,6 +21,21 @@ module Noter
21
21
  it "returns the names of all the existing files" do
22
22
  expect(viewer.existing_files).to eql(%W{#{NoteFile.dir}/2014_09_21_18_20_22.txt #{NoteFile.dir}/2014_09_21_19_20_22.txt})
23
23
  end
24
+
25
+ describe "when grepping" do
26
+ let(:viewer) { Noter::Viewer.new(:grep_string => "foo") }
27
+ let(:grep_result) { "line 1\nline 2" }
28
+
29
+ it "shells out to grep to get matching filenames" do
30
+ expect(viewer).to receive(:`).with("grep -l foo #{NoteFile.dir}/*").and_return(grep_result)
31
+ viewer.existing_files
32
+ end
33
+
34
+ it "splits the lines returned by grep" do
35
+ allow(viewer).to receive(:`).and_return(grep_result)
36
+ expect(viewer.existing_files).to eql(["line 1", "line 2"])
37
+ end
38
+ end
24
39
  end
25
40
 
26
41
  describe "#show_first_lines" do
@@ -69,18 +84,30 @@ module Noter
69
84
  end
70
85
  end
71
86
 
72
- describe "#show_last_n_files" do
73
- it "puts the last two files" do
74
- expect(viewer).to receive(:puts).with("\n\n#{file_1_name}")
75
- expect(viewer).to receive(:puts).with(file_1_contents)
76
- expect(viewer).to receive(:puts).with("\n\n#{file_2_name}")
77
- expect(viewer).to receive(:puts).with(file_2_contents)
78
- viewer.show_last_n_files(2)
87
+ describe "#show_files" do
88
+ describe "without colors" do
89
+ let(:viewer) { Noter::Viewer.new(:colorize => false, :tail_count => "2") }
90
+
91
+ it "puts the last two files" do
92
+ expect(viewer).to receive(:puts).with("\n\n#{file_1_name}")
93
+ expect(viewer).to receive(:puts).with(file_1_contents)
94
+ expect(viewer).to receive(:puts).with("\n\n#{file_2_name}")
95
+ expect(viewer).to receive(:puts).with(file_2_contents)
96
+ viewer.show_files
97
+ end
98
+ end
99
+
100
+ describe "with colors" do
101
+ it "adds color to the filename" do
102
+ expect(viewer).to receive(:puts).with("\n\n#{file_1_name}".colorize(:red))
103
+ expect(viewer).to receive(:puts).with("\n\n#{file_2_name}".colorize(:red))
104
+ viewer.show_files
105
+ end
79
106
  end
80
107
 
81
108
  it "converts string args to int" do
82
109
  expect {
83
- viewer.show_last_n_files("2")
110
+ viewer.show_files
84
111
  }.to_not raise_error
85
112
  end
86
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Roush
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-04 00:00:00.000000000 Z
11
+ date: 2014-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: colorize
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: 'Inspired (read: stolen) from the ''journal'' and ''jrnl'' python progrsm.
126
140
  At the moment, those are more developed; use them instead of this.'
127
141
  email: