ppl 1.8.0 → 1.9.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.
- data/lib/ppl/adapter/storage/disk.rb +1 -1
- data/lib/ppl/adapter/storage/git.rb +1 -1
- data/lib/ppl/application/bootstrap.rb +2 -0
- data/lib/ppl/application/configuration.rb +8 -2
- data/lib/ppl/application/router.rb +5 -0
- data/lib/ppl/command/mutt.rb +7 -7
- data/lib/ppl/command/version.rb +19 -0
- data/lib/ppl/entity/address_book.rb +1 -11
- data/lib/ppl/format/address_book/birthdays.rb +1 -1
- data/lib/ppl/format/address_book/email_addresses.rb +1 -1
- data/lib/ppl/format/address_book/mutt_query.rb +1 -1
- data/lib/ppl/format/address_book/names.rb +1 -1
- data/lib/ppl/format/address_book/one_line.rb +1 -1
- data/lib/ppl/format/address_book/organizations.rb +1 -1
- data/lib/ppl/format/address_book/phone_numbers.rb +1 -1
- data/lib/ppl/format/address_book/postal_addresses.rb +1 -1
- data/lib/ppl/format/address_book/urls.rb +1 -1
- data/lib/ppl/format/contact/full.rb +17 -15
- data/lib/ppl/format/contact/urls.rb +1 -5
- data/lib/ppl.rb +2 -1
- data/ppl.gemspec +2 -2
- data/spec/ppl/adapter/storage/disk_spec.rb +1 -1
- data/spec/ppl/adapter/storage/git_spec.rb +2 -2
- data/spec/ppl/application/bootstrap_spec.rb +6 -0
- data/spec/ppl/application/router_spec.rb +5 -0
- data/spec/ppl/command/mutt_spec.rb +3 -3
- data/spec/ppl/command/version_spec.rb +26 -0
- data/spec/ppl/entity/address_book_spec.rb +3 -14
- data/spec/ppl/format/address_book/birthdays_spec.rb +1 -1
- data/spec/ppl/format/address_book/email_addresses_spec.rb +1 -1
- data/spec/ppl/format/address_book/mutt_query_spec.rb +1 -1
- data/spec/ppl/format/address_book/names_spec.rb +1 -1
- data/spec/ppl/format/address_book/one_line_spec.rb +1 -1
- data/spec/ppl/format/address_book/organizations_spec.rb +1 -1
- data/spec/ppl/format/address_book/phone_numbers_spec.rb +1 -1
- data/spec/ppl/format/address_book/postal_addresses_spec.rb +1 -1
- data/spec/ppl/format/address_book/urls_spec.rb +1 -1
- metadata +10 -8
@@ -33,7 +33,7 @@ class Ppl::Adapter::Storage::Disk < Ppl::Adapter::Storage
|
|
33
33
|
filenames.each do |filename|
|
34
34
|
contact_id = File.basename(filename).slice(0..-5)
|
35
35
|
contact = load_contact(contact_id)
|
36
|
-
address_book.
|
36
|
+
address_book.contacts.push(contact)
|
37
37
|
end
|
38
38
|
|
39
39
|
return address_book
|
@@ -19,6 +19,7 @@ class Ppl::Application::Bootstrap
|
|
19
19
|
Ppl::Command::Post.new,
|
20
20
|
Ppl::Command::Shell.new,
|
21
21
|
Ppl::Command::Url.new,
|
22
|
+
Ppl::Command::Version.new,
|
22
23
|
]
|
23
24
|
commands.each do |command|
|
24
25
|
command.storage = storage_adapter
|
@@ -52,6 +53,7 @@ class Ppl::Application::Bootstrap
|
|
52
53
|
|
53
54
|
def router
|
54
55
|
router = Ppl::Application::Router.new(command_suite)
|
56
|
+
router.aliases = configuration.aliases
|
55
57
|
router.default = "help"
|
56
58
|
return router
|
57
59
|
end
|
@@ -19,14 +19,20 @@ class Ppl::Application::Configuration
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def aliases
|
22
|
-
|
23
|
-
|
22
|
+
user_aliases = user_configuration["aliases"]
|
23
|
+
default_aliases = default_configuration["aliases"]
|
24
|
+
if user_aliases.nil?
|
25
|
+
default_aliases
|
26
|
+
else
|
27
|
+
user_aliases
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
private
|
27
32
|
|
28
33
|
def default_configuration
|
29
34
|
{
|
35
|
+
"aliases" => {},
|
30
36
|
"address book" => {
|
31
37
|
"path" => Dir.pwd
|
32
38
|
},
|
@@ -1,14 +1,19 @@
|
|
1
1
|
|
2
2
|
class Ppl::Application::Router
|
3
3
|
|
4
|
+
attr_accessor :aliases
|
4
5
|
attr_accessor :default
|
5
6
|
|
6
7
|
def initialize(command_suite)
|
7
8
|
@command_suite = command_suite
|
9
|
+
@aliases = {}
|
8
10
|
end
|
9
11
|
|
10
12
|
def route(argument)
|
11
13
|
command = @command_suite.find_command(argument)
|
14
|
+
if command.nil? && @aliases.has_key?(argument)
|
15
|
+
command = @command_suite.find_command(@aliases[argument])
|
16
|
+
end
|
12
17
|
if command.nil? && !@default.nil?
|
13
18
|
command = @command_suite.find_command(@default)
|
14
19
|
end
|
data/lib/ppl/command/mutt.rb
CHANGED
@@ -18,7 +18,7 @@ class Ppl::Command::Mutt < Ppl::Application::Command
|
|
18
18
|
query = require_query(input)
|
19
19
|
matches = mutt_search(query)
|
20
20
|
output.line(describe_result(matches))
|
21
|
-
matches.
|
21
|
+
matches.contacts.length > 0
|
22
22
|
end
|
23
23
|
|
24
24
|
|
@@ -35,7 +35,7 @@ class Ppl::Command::Mutt < Ppl::Application::Command
|
|
35
35
|
@address_book = @storage.load_address_book
|
36
36
|
matches = Ppl::Entity::AddressBook.new
|
37
37
|
|
38
|
-
@address_book.each do |contact|
|
38
|
+
@address_book.contacts.each do |contact|
|
39
39
|
next if contact.email_addresses.empty?
|
40
40
|
|
41
41
|
matching_emails = contact.email_addresses.select do |email_address|
|
@@ -43,9 +43,9 @@ class Ppl::Command::Mutt < Ppl::Application::Command
|
|
43
43
|
end
|
44
44
|
|
45
45
|
if matching_emails.length > 0
|
46
|
-
matches.
|
46
|
+
matches.contacts.push(contact)
|
47
47
|
elsif !contact.name.nil? && contact.name.include?(query)
|
48
|
-
matches.
|
48
|
+
matches.contacts.push(contact)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -53,7 +53,7 @@ class Ppl::Command::Mutt < Ppl::Application::Command
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def describe_result(matches)
|
56
|
-
if matches.
|
56
|
+
if matches.contacts.length > 0
|
57
57
|
describe_matches(matches)
|
58
58
|
else
|
59
59
|
"No matches"
|
@@ -63,8 +63,8 @@ class Ppl::Command::Mutt < Ppl::Application::Command
|
|
63
63
|
def describe_matches(matches)
|
64
64
|
summary = sprintf(
|
65
65
|
"Searching address book... %d entries... %d matching:",
|
66
|
-
@address_book.
|
67
|
-
matches.
|
66
|
+
@address_book.contacts.length,
|
67
|
+
matches.contacts.length
|
68
68
|
)
|
69
69
|
results = @format.process(matches)
|
70
70
|
[summary, results].join("\n").strip
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
class Ppl::Command::Version < Ppl::Application::Command
|
3
|
+
|
4
|
+
name "version"
|
5
|
+
description "Display ppl version information"
|
6
|
+
|
7
|
+
attr_writer :format
|
8
|
+
|
9
|
+
def options(parser, options)
|
10
|
+
parser.banner = "usage: ppl version"
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute(input, output)
|
14
|
+
output.line("ppl version #{Ppl::Version}")
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -1,21 +1,11 @@
|
|
1
1
|
|
2
|
-
require "enumerator"
|
3
|
-
|
4
2
|
class Ppl::Entity::AddressBook
|
5
3
|
|
6
|
-
|
4
|
+
attr_accessor :contacts
|
7
5
|
|
8
6
|
def initialize
|
9
7
|
@contacts = []
|
10
8
|
end
|
11
9
|
|
12
|
-
def add_contact(contact)
|
13
|
-
@contacts.push contact
|
14
|
-
end
|
15
|
-
|
16
|
-
def each
|
17
|
-
@contacts.each { |contact| yield contact }
|
18
|
-
end
|
19
|
-
|
20
10
|
end
|
21
11
|
|
@@ -58,34 +58,36 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def format_email_addresses(contact)
|
61
|
-
|
62
|
-
@lines.push("")
|
63
|
-
@lines.push("Email Addresses:")
|
64
|
-
contact.email_addresses.each { |email_address| @lines.push(" " + email_address) }
|
65
|
-
end
|
61
|
+
push_list("Email Addresses", contact.email_addresses)
|
66
62
|
end
|
67
63
|
|
68
64
|
def format_phone_numbers(contact)
|
69
65
|
if !contact.phone_number.nil?
|
70
|
-
|
71
|
-
@lines.push("Phone Numbers:")
|
72
|
-
@lines.push(" #{contact.phone_number}")
|
66
|
+
push_list("Phone Numbers", contact.phone_number)
|
73
67
|
end
|
74
68
|
end
|
75
69
|
|
76
70
|
def format_postal_addresses(contact)
|
77
71
|
if !contact.postal_address.nil?
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
push_list(
|
73
|
+
"Postal Address",
|
74
|
+
@postal_address_format.process(contact.postal_address)
|
75
|
+
)
|
81
76
|
end
|
82
77
|
end
|
83
78
|
|
84
79
|
def format_urls(contact)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
80
|
+
push_list("URLs", contact.urls)
|
81
|
+
end
|
82
|
+
|
83
|
+
def push_list(label, list)
|
84
|
+
return if list.empty?
|
85
|
+
@lines.push("")
|
86
|
+
@lines.push("#{label}:")
|
87
|
+
if list.kind_of?(Array)
|
88
|
+
list.each { |item| @lines.push(" #{item}") }
|
89
|
+
else
|
90
|
+
@lines.push(" #{list}")
|
89
91
|
end
|
90
92
|
end
|
91
93
|
|
data/lib/ppl.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Ppl
|
3
3
|
|
4
|
-
Version = "1.
|
4
|
+
Version = "1.9.0"
|
5
5
|
|
6
6
|
module Adapter
|
7
7
|
end
|
@@ -56,6 +56,7 @@ require "ppl/command/mutt"
|
|
56
56
|
require "ppl/command/post"
|
57
57
|
require "ppl/command/shell"
|
58
58
|
require "ppl/command/url"
|
59
|
+
require "ppl/command/version"
|
59
60
|
|
60
61
|
require "ppl/entity/address_book"
|
61
62
|
require "ppl/entity/contact"
|
data/ppl.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
require "ostruct"
|
3
3
|
|
4
|
-
describe Ppl::Adapter::Storage::Git
|
4
|
+
describe Ppl::Adapter::Storage::Git do
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
FakeFS.activate!
|
@@ -65,7 +65,7 @@ describe Ppl::Adapter::Storage::Git, "#initialize" do
|
|
65
65
|
@head.should_receive(:tree).and_return(@files)
|
66
66
|
|
67
67
|
address_book = @git.load_address_book
|
68
|
-
address_book.each do |contact|
|
68
|
+
address_book.contacts.each do |contact|
|
69
69
|
contact.should be_a(Ppl::Entity::Contact)
|
70
70
|
end
|
71
71
|
end
|
@@ -81,6 +81,9 @@ describe Ppl::Application::Bootstrap do
|
|
81
81
|
it "should contain the 'url' command" do
|
82
82
|
@bootstrap.command_suite.find_command("url").should_not be nil
|
83
83
|
end
|
84
|
+
it "should contain the 'version' command" do
|
85
|
+
@bootstrap.command_suite.find_command("version").should_not be nil
|
86
|
+
end
|
84
87
|
end
|
85
88
|
|
86
89
|
describe "#configuration" do
|
@@ -111,6 +114,9 @@ describe Ppl::Application::Bootstrap do
|
|
111
114
|
it "should set the 'help' command as the default" do
|
112
115
|
@bootstrap.router.default.should eq "help"
|
113
116
|
end
|
117
|
+
it "should inject the user's aliases" do
|
118
|
+
@bootstrap.router.aliases.should be_a(Hash)
|
119
|
+
end
|
114
120
|
end
|
115
121
|
|
116
122
|
describe "#shell" do
|
@@ -37,6 +37,11 @@ describe Ppl::Application::Router do
|
|
37
37
|
@router.route("three").should be @cmd_one
|
38
38
|
end
|
39
39
|
|
40
|
+
it "should apply the aliases if the argument doesn't match a command" do
|
41
|
+
@router.aliases = {"t" => "two"}
|
42
|
+
@router.route("t").should be @cmd_two
|
43
|
+
end
|
44
|
+
|
40
45
|
end
|
41
46
|
|
42
47
|
end
|
@@ -27,7 +27,7 @@ describe Ppl::Command::Mutt do
|
|
27
27
|
|
28
28
|
it "should search the address book for the query" do
|
29
29
|
@input.arguments.push "query"
|
30
|
-
@command.should_receive(:mutt_search).and_return(
|
30
|
+
@command.should_receive(:mutt_search).and_return(Ppl::Entity::AddressBook.new)
|
31
31
|
@output.should_receive(:line).with("No matches")
|
32
32
|
@command.execute(@input, @output).should eq false
|
33
33
|
end
|
@@ -36,7 +36,7 @@ describe Ppl::Command::Mutt do
|
|
36
36
|
|
37
37
|
@contact.name = "Test User"
|
38
38
|
@contact.email_addresses.push "test@example.org"
|
39
|
-
@address_book.
|
39
|
+
@address_book.contacts.push(@contact)
|
40
40
|
|
41
41
|
@input.arguments.push "example"
|
42
42
|
|
@@ -52,7 +52,7 @@ describe Ppl::Command::Mutt do
|
|
52
52
|
|
53
53
|
@contact.name = "Test User"
|
54
54
|
@contact.email_addresses.push "test@example.org"
|
55
|
-
@address_book.
|
55
|
+
@address_book.contacts.push(@contact)
|
56
56
|
|
57
57
|
@input.arguments.push "User"
|
58
58
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Command::Version do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@command = Ppl::Command::Version.new
|
6
|
+
@input = Ppl::Application::Input.new
|
7
|
+
@output = double(Ppl::Application::Output)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#name" do
|
11
|
+
it "should be 'version'" do
|
12
|
+
@command.name.should eq "version"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#execute" do
|
17
|
+
it "should show the version number" do
|
18
|
+
@output.should_receive(:line) do |line|
|
19
|
+
line.should include Ppl::Version
|
20
|
+
end
|
21
|
+
@command.execute(@input, @output).should eq true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
@@ -5,20 +5,9 @@ describe Ppl::Entity::AddressBook do
|
|
5
5
|
@address_book = Ppl::Entity::AddressBook.new
|
6
6
|
end
|
7
7
|
|
8
|
-
describe "#
|
9
|
-
it "should
|
10
|
-
@address_book.
|
11
|
-
@address_book.count.should be 1
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#each" do
|
16
|
-
it "should yield contacts" do
|
17
|
-
contact = double(Ppl::Entity::Contact)
|
18
|
-
@address_book.add_contact(contact)
|
19
|
-
@address_book.each do |c|
|
20
|
-
c.should be contact
|
21
|
-
end
|
8
|
+
describe "#contacts" do
|
9
|
+
it "should be an array" do
|
10
|
+
@address_book.contacts.should be_an(Array)
|
22
11
|
end
|
23
12
|
end
|
24
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: inifile
|
16
|
-
requirement: &
|
16
|
+
requirement: &18641320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.0.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *18641320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rugged
|
27
|
-
requirement: &
|
27
|
+
requirement: &18640600 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.17.0.b6
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *18640600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: vpim
|
38
|
-
requirement: &
|
38
|
+
requirement: &18640020 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0.695'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *18640020
|
47
47
|
description: CLI Address Book
|
48
48
|
email: henry@henrysmith.org
|
49
49
|
executables:
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/ppl/command/shell.rb
|
91
91
|
- lib/ppl/command/show.rb
|
92
92
|
- lib/ppl/command/url.rb
|
93
|
+
- lib/ppl/command/version.rb
|
93
94
|
- lib/ppl/entity/address_book.rb
|
94
95
|
- lib/ppl/entity/contact.rb
|
95
96
|
- lib/ppl/entity/postal_address.rb
|
@@ -148,6 +149,7 @@ files:
|
|
148
149
|
- spec/ppl/command/shell_spec.rb
|
149
150
|
- spec/ppl/command/show_spec.rb
|
150
151
|
- spec/ppl/command/url_spec.rb
|
152
|
+
- spec/ppl/command/version_spec.rb
|
151
153
|
- spec/ppl/entity/address_book_spec.rb
|
152
154
|
- spec/ppl/entity/contact_spec.rb
|
153
155
|
- spec/ppl/entity/postal_address_spec.rb
|