friends 0.9 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd57717cc27c13b6520090e016a6ddf121aaf9b6
4
- data.tar.gz: 2ab6ef28bcbc08fa2144ce1a77c7b5f1ca4c29ad
3
+ metadata.gz: 2611eb26561b8f7b40bdae56b727170223657de4
4
+ data.tar.gz: bc6d0a9247e655d9f42c439c2f576fb6dcb0c022
5
5
  SHA512:
6
- metadata.gz: aa7c94b0e734e6bca501e94eafe6d4e6a40c3b00bf4c5c509b0dc8c0d08db38237cbe0027278203a8521c291513016b7d0716e312a612455478f1cf7982b8337
7
- data.tar.gz: 42bd1f835bf0fe0aafbc6e843209d17e02f620626b94a4a0dc6b5cdab933a74ddac450d7c79eddda9c0f34c68426eb8e58835ea1e9b3f9dd4b342245a0449005
6
+ metadata.gz: d6b161c62dd6b7202e833b0f1a93ddb3b7effe11792b1ba333f905f007180bc9c35ebc8b4105ab873243989eda3256955a984381a0c4e754c681c231b3424b90
7
+ data.tar.gz: 76f47fc43841a2c225ea25122d560e46f46dd103f3907b96c66472e9d62ea8edc2d3a0932de04e67c003b841c0c020f117e17d1759000bdaf63c933061f6fe75
data/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.11](https://github.com/JacobEvelyn/friends/tree/v0.11) (2016-01-13)
4
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.10...v0.11)
5
+
6
+ **Fixed bugs:**
7
+
8
+ - friends update doesn't correctly compare version numbers [\#72](https://github.com/JacobEvelyn/friends/issues/72)
9
+ - Date gets duplicated with each new activity [\#71](https://github.com/JacobEvelyn/friends/issues/71)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Fix bug in comparing gem versions for update [\#74](https://github.com/JacobEvelyn/friends/pull/74) ([JacobEvelyn](https://github.com/JacobEvelyn))
14
+ - Fix bug in how dates are deserialized [\#73](https://github.com/JacobEvelyn/friends/pull/73) ([JacobEvelyn](https://github.com/JacobEvelyn))
15
+
16
+ ## [v0.10](https://github.com/JacobEvelyn/friends/tree/v0.10) (2016-01-12)
17
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.9...v0.10)
18
+
19
+ **Implemented enhancements:**
20
+
21
+ - Add --debug flag for error backtraces [\#62](https://github.com/JacobEvelyn/friends/issues/62)
22
+
23
+ **Fixed bugs:**
24
+
25
+ - The same name is only highlighted once per description [\#35](https://github.com/JacobEvelyn/friends/issues/35)
26
+
27
+ **Closed issues:**
28
+
29
+ - Don't write files in middle of commands [\#60](https://github.com/JacobEvelyn/friends/issues/60)
30
+ - Remove require\_relative from codebase [\#58](https://github.com/JacobEvelyn/friends/issues/58)
31
+ - Cleanly separate Introvert from non-library concerns [\#57](https://github.com/JacobEvelyn/friends/issues/57)
32
+
33
+ **Merged pull requests:**
34
+
35
+ - Highlight multiple occurrences [\#70](https://github.com/JacobEvelyn/friends/pull/70) ([GuruKhalsa](https://github.com/GuruKhalsa))
36
+ - Fix Travis badge \(master only\) [\#67](https://github.com/JacobEvelyn/friends/pull/67) ([JacobEvelyn](https://github.com/JacobEvelyn))
37
+ - Move activity prompt to bin/friends [\#64](https://github.com/JacobEvelyn/friends/pull/64) ([JacobEvelyn](https://github.com/JacobEvelyn))
38
+ - Adds the --debug flag for printing backtraces on error [\#63](https://github.com/JacobEvelyn/friends/pull/63) ([JacobEvelyn](https://github.com/JacobEvelyn))
39
+ - Move file writes to end of command actions [\#61](https://github.com/JacobEvelyn/friends/pull/61) ([JacobEvelyn](https://github.com/JacobEvelyn))
40
+ - Remove require\_relative from codebase [\#59](https://github.com/JacobEvelyn/friends/pull/59) ([JacobEvelyn](https://github.com/JacobEvelyn))
41
+
3
42
  ## [v0.9](https://github.com/JacobEvelyn/friends/tree/v0.9) (2016-01-07)
4
43
  [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.8...v0.9)
5
44
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Gem Version](https://badge.fury.io/rb/friends.svg)](https://badge.fury.io/rb/friends) [![Code Climate](https://codeclimate.com/github/JacobEvelyn/friends/badges/gpa.svg)](https://codeclimate.com/github/JacobEvelyn/friends) [![Test Coverage](https://codeclimate.com/github/JacobEvelyn/friends/badges/coverage.svg)](https://codeclimate.com/github/JacobEvelyn/friends) [![Build Status](https://travis-ci.org/JacobEvelyn/friends.svg)](https://travis-ci.org/JacobEvelyn/friends) [![Inline docs](http://inch-ci.org/github/JacobEvelyn/friends.png)](http://inch-ci.org/github/JacobEvelyn/friends) [![ghit.me](https://ghit.me/badge.svg?repo=JacobEvelyn/friends)](https://ghit.me/repo/JacobEvelyn/friends)
1
+ [![Gem Version](https://badge.fury.io/rb/friends.svg)](https://badge.fury.io/rb/friends) [![Code Climate](https://codeclimate.com/github/JacobEvelyn/friends/badges/gpa.svg)](https://codeclimate.com/github/JacobEvelyn/friends) [![Test Coverage](https://codeclimate.com/github/JacobEvelyn/friends/badges/coverage.svg)](https://codeclimate.com/github/JacobEvelyn/friends) [![Build Status](https://travis-ci.org/JacobEvelyn/friends.svg?branch=master)](https://travis-ci.org/JacobEvelyn/friends) [![Inline docs](http://inch-ci.org/github/JacobEvelyn/friends.png)](http://inch-ci.org/github/JacobEvelyn/friends) [![ghit.me](https://ghit.me/badge.svg?repo=JacobEvelyn/friends)](https://ghit.me/repo/JacobEvelyn/friends)
2
2
 
3
3
  # Friends
4
4
 
data/bin/friends CHANGED
@@ -3,11 +3,12 @@
3
3
  # Todo:
4
4
  # - Split out serialization into separate repository.
5
5
  # - Add auto check for updates.
6
- # - Allow friends to have nicknames.
7
6
  # - Allow easy editing of most recent entry.
8
7
 
9
8
  require "gli"
10
9
  require "paint"
10
+ require "readline"
11
+ require "semverse"
11
12
 
12
13
  require "friends/introvert"
13
14
  require "friends/version"
@@ -31,9 +32,9 @@ flag [:filename],
31
32
  default_value: "./friends.md",
32
33
  desc: "Set the location of the friends file"
33
34
 
34
- switch [:clean],
35
+ switch [:debug],
35
36
  negatable: false,
36
- desc: "Force a clean write of the friends file"
37
+ desc: "Debug error messages with a full backtrace"
37
38
 
38
39
  desc "Updates the `friends` program"
39
40
  command :update do |update|
@@ -41,7 +42,8 @@ command :update do |update|
41
42
  search = `gem search friends`
42
43
  if match = search.match(/^friends\s\(([^\)]+)\)$/)
43
44
  remote_version = match[1]
44
- if remote_version.to_r > Friends::VERSION.to_r
45
+ if Semverse::Version.coerce(remote_version) >
46
+ Semverse::Version.coerce(Friends::VERSION)
45
47
  `gem update friends && gem cleanup friends`
46
48
  if $?.success?
47
49
  puts Paint["Updated to friends #{remote_version}", :bold, :green]
@@ -116,6 +118,7 @@ command :add do |add|
116
118
  add_friend.action do |_, _, args|
117
119
  friend = @introvert.add_friend(name: args.first)
118
120
  @message = "Friend added: \"#{friend.name}\""
121
+ @dirty = true # Mark the file for cleaning.
119
122
  end
120
123
  end
121
124
 
@@ -124,7 +127,15 @@ command :add do |add|
124
127
  add.command :activity do |add_activity|
125
128
  add_activity.action do |_, _, args|
126
129
  activity = @introvert.add_activity(serialization: args.first)
130
+
131
+ # If there's no description, prompt the user for one.
132
+ if !activity.description
133
+ activity.description = Readline.readline(activity.display_text)
134
+ activity.highlight_friends(introvert: @introvert)
135
+ end
136
+
127
137
  @message = "Activity added: \"#{activity.display_text}\""
138
+ @dirty = true # Mark the file for cleaning.
128
139
  end
129
140
  end
130
141
 
@@ -134,6 +145,7 @@ command :add do |add|
134
145
  add_nickname.action do |_, _, args|
135
146
  friend = @introvert.add_nickname(name: args.first, nickname: args[1])
136
147
  @message = "Nickname added: \"#{friend}\""
148
+ @dirty = true # Mark the file for cleaning.
137
149
  end
138
150
  end
139
151
  end
@@ -146,6 +158,7 @@ command :remove do |remove|
146
158
  remove_nickname.action do |_, _, args|
147
159
  friend = @introvert.remove_nickname(name: args.first, nickname: args[1])
148
160
  @message = "Nickname removed: \"#{friend}\""
161
+ @dirty = true # Mark the file for cleaning.
149
162
  end
150
163
  end
151
164
  end
@@ -192,8 +205,8 @@ end
192
205
  desc "Cleans your friends.md file"
193
206
  command :clean do |clean|
194
207
  clean.action do
195
- filename = @introvert.clean
196
- @message = "File cleaned: \"#{filename}\""
208
+ @clean_command = true
209
+ @dirty = true # Mark the file for cleaning.
197
210
  end
198
211
  end
199
212
 
@@ -209,6 +222,8 @@ end
209
222
 
210
223
  # Before each command, clean up all arguments and create the global Introvert.
211
224
  pre do |global_options, _, options|
225
+ @debug_mode = global_options[:debug]
226
+
212
227
  final_options = global_options.merge!(options).select do |key, _|
213
228
  [:filename].include? key
214
229
  end
@@ -218,11 +233,12 @@ pre do |global_options, _, options|
218
233
  end
219
234
 
220
235
  post do |global_options|
221
- # After each command, clean if requested with the --clean flag.
222
- if global_options[:clean]
223
- filename = @introvert.clean
224
- @message = "File cleaned: \"#{filename}\""
225
- end
236
+ # After each command, clean the file if we have modifications to make.
237
+ filename = @introvert.clean if @dirty
238
+
239
+ # This is a special-case piece of code that lets us print a message that
240
+ # includes the filename when `friends clean` is called.
241
+ @message = "File cleaned: \"#{filename}\"" if @clean_command
226
242
 
227
243
  # Print the output message (if there is one) unless --quiet is passed.
228
244
  puts @message unless @message.nil? || global_options[:quiet]
@@ -230,7 +246,11 @@ end
230
246
 
231
247
  # If an error is raised, print the message to STDERR and exit the program.
232
248
  on_error do |error|
233
- abort "Error: #{error}"
249
+ if @debug_mode
250
+ raise error
251
+ else
252
+ abort "Error: #{error}"
253
+ end
234
254
  end
235
255
 
236
256
  # Run the program and return the exit code corresponding to its success.
data/friends.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "gli", "~> 2.12"
25
25
  spec.add_dependency "memoist", "~> 0.11"
26
26
  spec.add_dependency "paint", "~> 1.0"
27
+ spec.add_dependency "semverse", "~> 1.2"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.6"
29
30
  spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
@@ -83,12 +83,10 @@ module Friends
83
83
  # make those substitutions.
84
84
  regex_map.
85
85
  select { |_, arr| arr.size == 1 }.each do |regex, friend_list|
86
- if match = @description.match(regex)
86
+ if @description.match(regex)
87
87
  friend = friend_list.first # There's only one friend in the list.
88
88
  matched_friends << friend
89
- @description = "#{match.pre_match}"\
90
- "**#{friend.name}**"\
91
- "#{match.post_match}"
89
+ @description.gsub!(regex, "**#{friend.name}**")
92
90
  end
93
91
  end
94
92
 
@@ -113,19 +111,17 @@ module Friends
113
111
  # guess.
114
112
  regex_map.
115
113
  reject { |_, arr| arr.size == 1 }.each do |regex, friend_list|
116
- if match = @description.match(regex)
114
+ if @description.match(regex)
117
115
  guessed_friend = friend_list.sort_by do |friend|
118
116
  [-friend.likelihood_score, -friend.n_activities]
119
117
  end.first
120
- @description = "#{match.pre_match}"\
121
- "**#{guessed_friend.name}**"\
122
- "#{match.post_match}"
118
+ @description.gsub!(regex, "**#{guessed_friend.name}**")
123
119
  end
124
120
  end
125
121
 
126
122
  # Lastly, we remove any backslashes, as these are used to escape friends'
127
123
  # names that we don't want to match.
128
- @description.gsub!("\\", "")
124
+ @description.delete!("\\")
129
125
  end
130
126
 
131
127
  # @param friend [Friend] the friend to test
@@ -2,8 +2,6 @@
2
2
  # able to be used directly within another Ruby program, without needing to call
3
3
  # the command-line script explicitly.
4
4
 
5
- require "readline"
6
-
7
5
  require "friends/activity"
8
6
  require "friends/friend"
9
7
  require "friends/friends_error"
@@ -18,7 +16,6 @@ module Friends
18
16
  # @param filename [String] the name of the friends Markdown file
19
17
  def initialize(filename: DEFAULT_FILENAME)
20
18
  @filename = filename
21
- @cleaned_file = false # Switches to true when the file is cleaned.
22
19
 
23
20
  # Read in the input file. It's easier to do this now and optimize later
24
21
  # than try to overly be clever about what we read and write.
@@ -27,10 +24,6 @@ module Friends
27
24
 
28
25
  # Write out the friends file with cleaned/sorted data.
29
26
  def clean
30
- # Short-circuit if we've already cleaned the file so we don't write it
31
- # twice.
32
- return @filename if @cleaned_file
33
-
34
27
  descriptions = @activities.sort.map(&:serialize)
35
28
  names = @friends.sort.map(&:serialize)
36
29
 
@@ -43,8 +36,6 @@ module Friends
43
36
  names.each { |name| file.puts(name) }
44
37
  end
45
38
 
46
- @cleaned_file = true
47
-
48
39
  @filename
49
40
  end
50
41
 
@@ -64,7 +55,6 @@ module Friends
64
55
  end
65
56
 
66
57
  @friends << friend
67
- clean # Write a cleaned file.
68
58
 
69
59
  friend # Return the added friend.
70
60
  end
@@ -79,12 +69,8 @@ module Friends
79
69
  raise FriendsError, e
80
70
  end
81
71
 
82
- # If there's no description, prompt the user for one.
83
- activity.description ||= Readline.readline(activity.display_text)
84
-
85
- activity.highlight_friends(introvert: self)
72
+ activity.highlight_friends(introvert: self) if activity.description
86
73
  @activities.unshift(activity)
87
- clean # Write a cleaned file.
88
74
 
89
75
  activity # Return the added activity.
90
76
  end
@@ -97,9 +83,6 @@ module Friends
97
83
  def add_nickname(name:, nickname:)
98
84
  friend = friend_with_name_in(name)
99
85
  friend.add_nickname(nickname.strip)
100
-
101
- clean # Write a cleaned file.
102
-
103
86
  friend
104
87
  end
105
88
 
@@ -112,9 +95,6 @@ module Friends
112
95
  def remove_nickname(name:, nickname:)
113
96
  friend = friend_with_name_in(name)
114
97
  friend.remove_nickname(nickname.strip)
115
-
116
- clean # Write a cleaned file.
117
-
118
98
  friend
119
99
  end
120
100
 
@@ -1,3 +1,3 @@
1
1
  module Friends
2
- VERSION = "0.9"
2
+ VERSION = "0.11"
3
3
  end
@@ -1,4 +1,4 @@
1
- require_relative "helper"
1
+ require "./test/helper"
2
2
 
3
3
  describe Friends::Activity do
4
4
  let(:date) { Date.today }
@@ -174,6 +174,16 @@ describe Friends::Activity do
174
174
  end
175
175
  end
176
176
 
177
+ describe "when a friend's name is mentioned multiple times" do
178
+ let(:description) { "Dinner with Elizabeth. Elizabeth made us pasta." }
179
+ it "highlights all occurrences of the friend's name" do
180
+ subject
181
+ activity.description.
182
+ must_equal "Dinner with **Elizabeth Cady Stanton**."\
183
+ " **Elizabeth Cady Stanton** made us pasta."
184
+ end
185
+ end
186
+
177
187
  describe "when there are multiple matches" do
178
188
  describe "when there is context from past activities" do
179
189
  let(:description) { "Dinner with Elizabeth and John." }
data/test/friend_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative "helper"
1
+ require "./test/helper"
2
2
 
3
3
  describe Friends::Friend do
4
4
  let(:friend_name) { "Jacob Evelyn" }
@@ -1,4 +1,4 @@
1
- require_relative "helper"
1
+ require "./test/helper"
2
2
 
3
3
  describe Friends::Introvert do
4
4
  # Add readers to make internal state easier to test.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friends
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Evelyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: semverse
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement