ressbo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ ################################################################################
3
+ #
4
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #
25
+ ################################################################################
26
+ require('rubygems')
27
+ require('ressbo')
28
+ require('ressbo/cli')
29
+
30
+ cli = Ressbo::CLI.parse
31
+ Ressbo::Store.new(cli.db)
32
+
33
+ unless ARGV.size == 1
34
+ $stderr.puts("ERROR: please provide a search term on the command line")
35
+ exit(1)
36
+ end
37
+
38
+ $stdout.puts("Searching...")
39
+ matches = Ressbo::Email.mutt_query(ARGV.first)
40
+ matches.each {|e| $stdout.puts(e.to_mutt)}
41
+ exit(1) if matches.empty?
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ ################################################################################
3
+ #
4
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #
25
+ ################################################################################
26
+ require('rubygems')
27
+ require('ressbo')
28
+ require('ressbo/cli')
29
+
30
+ cli = Ressbo::CLI.parse
31
+ File.unlink(cli.db) if File.exist?(cli.db)
32
+ Ressbo::Store.new(cli.db)
@@ -0,0 +1,74 @@
1
+ #title Ressbo Manual
2
+ #author Peter Jones
3
+
4
+ Ressbo is a command line tool and Ruby API for working with entries
5
+ from the [[http://docs.info.apple.com/article.html?artnum=304758][Apple Address Book]]. The entries are first cached into a
6
+ [[http://www.sqlite.org][SQLite]] database, and then are available through [[http://en.wikipedia.org/wiki/ActiveRecord_%28Rails%29][active record]] models.
7
+
8
+ The primary goal of the project is to provide command line tools that
9
+ allow easy access to the Mac OS X built-in address book.
10
+
11
+ <contents>
12
+
13
+ * Installation
14
+
15
+ Ressbo is distributed as a Ruby [[http://www.rubygems.org/][Gem]]. If you are running Mac OS X
16
+ version 10.5 (Leopard), you only need to run the following command:
17
+
18
+ <example>
19
+ $ sudo gem install ressbo
20
+ </example>
21
+
22
+ If you are running an older version of Mac OS X, you should probably
23
+ install a fresh copy of [[http://www.ruby-lang.org/][Ruby]], install [[http://www.rubygems.org/][Ruby Gems]], and then finally
24
+ install Ressbo using the instructions above.
25
+
26
+ * Usage
27
+
28
+ All Ressbo commands automatically create a SQLite cache of the native
29
+ address book. The following is a listing of provided command line
30
+ utilities:
31
+
32
+ | Command | Description |
33
+ |-------------+----------------------------------------------------------------------------------------------------------------|
34
+ | ressbo-mutt | Search the cache for matching addresses. Designed to work with the [[http://www.mutt.org][Mutt]] MUA [[http://www.mutt.org/doc/manual/manual-4.html#query][external address query]] mechanism. |
35
+ | ressbo-sink | Rebuild the SQLite cache of the address book data. |
36
+
37
+ * Cached Data
38
+
39
+ Ressbo currently only caches names and email addresses. It's possible
40
+ that Ressbo will be extended to support more data from the address
41
+ book in future versions.
42
+
43
+ * Rebuilding the Cache
44
+
45
+ The current version of Ressbo does not yet detect changes to the
46
+ address book. You will therefore need to rebuild the cache after
47
+ making changes to the built-in address book.
48
+
49
+ You can rebuild the cache with the provided =ressbo-sink= command line
50
+ tool.
51
+
52
+ * Development
53
+
54
+ The source code repository for Ressbo can be obtained via:
55
+
56
+ <example>
57
+ $ git clone git://pmade.com/ressbo
58
+ </example>
59
+
60
+ * Frequently Asked Questions
61
+
62
+ Q. Where in the world did the name Ressbo come from?
63
+
64
+ A. addRESS BOok
65
+
66
+ Q. Why did you bother to write this?
67
+
68
+ A. So that I could use my Apple address book entries with tools like
69
+ Mutt and Emacs.
70
+
71
+ Q. Do you promise to maintain Ressbo and add all the features that I
72
+ want?
73
+
74
+ A. No. If you want a new feature, send me a patch.
@@ -0,0 +1,33 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ require('rubygems')
26
+ require('activerecord')
27
+ require('sqlite3')
28
+ require('rbosa')
29
+
30
+ ################################################################################
31
+ require('ressbo/constants')
32
+ require('ressbo/store')
33
+ require('ressbo/sink')
@@ -0,0 +1,59 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ require('optparse')
26
+
27
+ ################################################################################
28
+ module Ressbo
29
+
30
+ ################################################################################
31
+ class CLI
32
+
33
+ ################################################################################
34
+ attr_accessor(:db)
35
+
36
+ ################################################################################
37
+ def self.parse
38
+ cli = new
39
+ cli.parse
40
+ cli
41
+ end
42
+
43
+ ################################################################################
44
+ def initialize
45
+ @db = Ressbo::Constants::DEFAULT_DB_PATH
46
+ end
47
+
48
+ ################################################################################
49
+ def parse (&block)
50
+ OptionParser.new do |parser|
51
+ parser.on('-c', "--cache=PATH", "Where to keep the cache file [#@db]") {|c| @db = c}
52
+ parser.on('--version', "Display the Ressbo version and exit") {puts(Ressbo::Constants::VERSION); exit}
53
+ block.call(parser) if block
54
+ parser.parse!
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,30 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module Ressbo
26
+ module Constants
27
+ VERSION = '1.0.0'
28
+ DEFAULT_DB_PATH = File.expand_path("~/.ressbo.db")
29
+ end
30
+ end
@@ -0,0 +1,56 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module Ressbo
26
+
27
+ ################################################################################
28
+ class Email < ActiveRecord::Base
29
+
30
+ ################################################################################
31
+ belongs_to(:person)
32
+
33
+ ################################################################################
34
+ def self.from_address_book (email)
35
+ record = new(:address => email.value)
36
+ end
37
+
38
+ ################################################################################
39
+ def self.mutt_query (query)
40
+ query = "%#{query.downcase}%"
41
+ conditions = ["LOWER(people.first_name) LIKE ?", query]
42
+ conditions.first << " OR LOWER(people.last_name) LIKE ?"
43
+ conditions << query
44
+ conditions.first << " OR LOWER(emails.address) LIKE ?"
45
+ conditions << query
46
+
47
+ find(:all, :include => :person, :conditions => conditions)
48
+ end
49
+
50
+ ################################################################################
51
+ def to_mutt
52
+ "#{address}\t#{person.name}"
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,59 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module Ressbo
26
+
27
+ ################################################################################
28
+ class Person < ActiveRecord::Base
29
+
30
+ ################################################################################
31
+ has_many(:emails)
32
+
33
+ ################################################################################
34
+ def self.from_address_book (person)
35
+ record = new
36
+
37
+ if person.company?
38
+ record.first_name = person.organization
39
+ record.company = true
40
+ else
41
+ record.first_name = person.first_name
42
+ record.last_name = person.last_name
43
+ end
44
+
45
+ person.emails.each do |email|
46
+ record.emails << Email.from_address_book(email)
47
+ end
48
+
49
+ record.save!
50
+ record
51
+ end
52
+
53
+ ################################################################################
54
+ def name
55
+ [first_name, last_name].compact.join(' ')
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,16 @@
1
+ create table ressbo_info (
2
+ ressbo_version text
3
+ );
4
+
5
+ create table people (
6
+ id integer primary key,
7
+ first_name text,
8
+ last_name text,
9
+ company integer
10
+ );
11
+
12
+ create table emails (
13
+ id integer primary key,
14
+ person_id integer,
15
+ address text
16
+ );
@@ -0,0 +1,42 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module Ressbo
26
+
27
+ ################################################################################
28
+ class Sink
29
+
30
+ ################################################################################
31
+ def initialize
32
+ OSA.utf8_strings = true
33
+ end
34
+
35
+ ################################################################################
36
+ def load_from_address_book
37
+ abook = OSA.app('Address Book')
38
+ abook.people.each {|p| Person.from_address_book(p)}
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,92 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module Ressbo
26
+
27
+ ################################################################################
28
+ class Store
29
+
30
+ ################################################################################
31
+ attr_reader(:fresh)
32
+
33
+ ################################################################################
34
+ # Create a new Ressbo store, creating one if necessary
35
+ def initialize (path=nil)
36
+ @path = File.expand_path(path || Constants::DEFAULT_DB_PATH)
37
+ File.exist?(@path) ? check : create
38
+ connect
39
+ load_models
40
+ Sink.new.load_from_address_book if @fresh
41
+ end
42
+
43
+ ################################################################################
44
+ private
45
+
46
+ ################################################################################
47
+ def create
48
+ schema = File.read(File.dirname(__FILE__) + '/schema.sql')
49
+
50
+ with_sqlite do |db|
51
+ db.execute_batch(schema)
52
+ db.execute("INSERT INTO ressbo_info VALUES(?)", Constants::VERSION)
53
+ end
54
+
55
+ @fresh = true
56
+ end
57
+
58
+ ################################################################################
59
+ def check
60
+ version = with_sqlite do |db|
61
+ db.get_first_value("SELECT ressbo_version FROM ressbo_info LIMIT 1")
62
+ end
63
+
64
+ if version != Constants::VERSION
65
+ File.unlink(@path)
66
+ create
67
+ end
68
+ end
69
+
70
+ ################################################################################
71
+ def connect
72
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => @path)
73
+ end
74
+
75
+ ################################################################################
76
+ def with_sqlite (&block)
77
+ db = SQLite3::Database.new(@path)
78
+ result = block.call(db)
79
+ db.close
80
+ result
81
+ end
82
+
83
+ ################################################################################
84
+ def load_models
85
+ Dir.foreach(File.dirname(__FILE__) + '/models') do |file|
86
+ next unless file.match(/\.rb$/)
87
+ require(File.dirname(__FILE__) + '/models/' + file)
88
+ end
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,32 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2008 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '../lib')
26
+ require('ressbo')
27
+ require('test/unit')
28
+ require('mocha')
29
+
30
+ ################################################################################
31
+ TEST_DB_FILE = File.dirname(__FILE__) + '/test.db'
32
+
@@ -0,0 +1,19 @@
1
+ ################################################################################
2
+ require(File.dirname(__FILE__) + '/setup.rb')
3
+
4
+ ################################################################################
5
+ class TestSink < Test::Unit::TestCase
6
+
7
+ ################################################################################
8
+ def teardown
9
+ File.unlink(TEST_DB_FILE)
10
+ end
11
+
12
+ ################################################################################
13
+ def test_abook_load
14
+ assert(!File.exist?(TEST_DB_FILE))
15
+ store = Ressbo::Store.new(TEST_DB_FILE)
16
+ assert_not_equal(0, Ressbo::Person.count)
17
+ end
18
+
19
+ end
@@ -0,0 +1,44 @@
1
+ ################################################################################
2
+ require(File.dirname(__FILE__) + '/setup.rb')
3
+
4
+ ################################################################################
5
+ class TestStore < Test::Unit::TestCase
6
+
7
+ ################################################################################
8
+ def setup
9
+ Ressbo::Sink.any_instance.expects(:load_from_address_book).at_least(1)
10
+ end
11
+
12
+ ################################################################################
13
+ def teardown
14
+ File.unlink(TEST_DB_FILE)
15
+ end
16
+
17
+ ################################################################################
18
+ def test_schema_creation
19
+ assert(!File.exist?(TEST_DB_FILE))
20
+ store = Ressbo::Store.new(TEST_DB_FILE)
21
+ assert(File.exist?(TEST_DB_FILE))
22
+ assert(store.fresh)
23
+
24
+ live_tables = store.send(:with_sqlite) do |db|
25
+ db.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name").flatten
26
+ end
27
+
28
+ assert(!live_tables.size.zero?)
29
+ schema = File.read(File.dirname(__FILE__) + '/../lib/ressbo/schema.sql')
30
+ schema_tables = schema.scan(/create\s+table\s+(\w+)/).flatten.sort
31
+ assert_equal(schema_tables, live_tables)
32
+ end
33
+
34
+ ################################################################################
35
+ def test_schema_exists
36
+ assert(!File.exist?(TEST_DB_FILE))
37
+ store = Ressbo::Store.new(TEST_DB_FILE)
38
+ assert(File.exist?(TEST_DB_FILE))
39
+ store = Ressbo::Store.new(TEST_DB_FILE)
40
+ assert_nil(store.fresh)
41
+ assert(ActiveRecord::Base.connection)
42
+ end
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ressbo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Jones
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-14 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sqlite3-ruby
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: rubyosa
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.6
41
+ version:
42
+ description:
43
+ email: pjones@pmade.com
44
+ executables:
45
+ - ressbo-sink
46
+ - ressbo-mutt
47
+ extensions: []
48
+
49
+ extra_rdoc_files: []
50
+
51
+ files:
52
+ - lib/ressbo
53
+ - lib/ressbo/cli.rb
54
+ - lib/ressbo/constants.rb
55
+ - lib/ressbo/models
56
+ - lib/ressbo/models/email.rb
57
+ - lib/ressbo/models/person.rb
58
+ - lib/ressbo/schema.sql
59
+ - lib/ressbo/sink.rb
60
+ - lib/ressbo/store.rb
61
+ - lib/ressbo.rb
62
+ - bin/ressbo-mutt
63
+ - bin/ressbo-sink
64
+ - doc/index.muse
65
+ - test/setup.rb
66
+ - test/test_sink.rb
67
+ - test/test_store.rb
68
+ has_rdoc: true
69
+ homepage: http://software.pmade.com/ressbo
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: ressbo
90
+ rubygems_version: 1.1.1
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: Ruby Apple Address Book Interface and Tools
94
+ test_files: []
95
+