rb-dayone 0.4.0 → 0.4.1
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/Gemfile +2 -1
- data/History.rdoc +5 -0
- data/lib/rb-dayone.rb +1 -1
- data/lib/rb-dayone/plist_reader.rb +43 -4
- data/spec/dayone_spec.rb +3 -1
- data/spec/plist_reader_spec.rb +3 -5
- data/version.txt +1 -1
- metadata +2 -2
data/Gemfile
CHANGED
data/History.rdoc
CHANGED
data/lib/rb-dayone.rb
CHANGED
@@ -39,7 +39,7 @@ module DayOne
|
|
39
39
|
# the DayOne plist file stored in +~/Library/Preferences+.
|
40
40
|
# @return [String] the DayONe journal location
|
41
41
|
def auto_journal_location
|
42
|
-
@auto_journal_location ||= File.expand_path(plist_reader
|
42
|
+
@auto_journal_location ||= File.expand_path(plist_reader.journal_location)
|
43
43
|
end
|
44
44
|
|
45
45
|
# All DayOne entries, as file names
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'nokogiri'
|
2
2
|
|
3
3
|
# The PListReader is a class that reads PLists.
|
4
4
|
# It is used to read the DayOne preferences PList.
|
@@ -10,18 +10,57 @@ class DayOne::PlistReader
|
|
10
10
|
# Initialize the PList Reader, given a path
|
11
11
|
# @param [String] path the path to the PList; defaults to the standard DayOne preference plist
|
12
12
|
def initialize path=nil
|
13
|
-
|
13
|
+
default_paths = [ # There have been two default paths over the versions...
|
14
|
+
File.join(ENV['HOME'], 'Library', 'Group Containers', '5U8NS4GX82.dayoneapp', 'Data', 'Preferences', 'dayone.plist'), # From 1.7 on
|
15
|
+
File.join(ENV['HOME'], 'Library', 'Preferences', 'com.dayoneapp.dayone.plist') # Pre-1.7
|
16
|
+
]
|
17
|
+
|
18
|
+
|
19
|
+
@path = if path
|
20
|
+
path
|
21
|
+
else
|
22
|
+
first_valid_default_path = default_paths.find{ |p| File.exists?(p) }
|
23
|
+
if first_valid_default_path.nil?
|
24
|
+
raise RuntimeError, "Cannot locate DayOne preference file"
|
25
|
+
else
|
26
|
+
first_valid_default_path
|
27
|
+
end
|
28
|
+
end
|
14
29
|
end
|
15
30
|
|
16
31
|
# Retrieve the body of the plist as an array, parsed through JSON
|
17
32
|
# @return [Hash] the body of the plist as a hash.
|
18
33
|
def body
|
19
34
|
if !@body
|
20
|
-
|
21
|
-
@body = JSON.parse(json_string)
|
35
|
+
@body = Nokogiri::XML `plutil -convert xml1 -o - '#{path}'`
|
22
36
|
end
|
23
37
|
@body
|
24
38
|
end
|
39
|
+
|
40
|
+
# Retrieves an array of Nokogiri XML objects representing the
|
41
|
+
# keys of the plist
|
42
|
+
# @return [Array] the keys in the plist
|
43
|
+
def keys
|
44
|
+
body.xpath('//dict/key')
|
45
|
+
end
|
46
|
+
|
47
|
+
# Retrieves a specific key's value, or nil
|
48
|
+
# @return the value of the key, or nil if it doesn't exist
|
49
|
+
def key key_value
|
50
|
+
key_element = keys.find{ |e| e.content == key_value }
|
51
|
+
if key_element
|
52
|
+
key_element.next_element.content
|
53
|
+
else
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Retrieve the DayOne journal location
|
59
|
+
# @return [String] the path to the current DayOne journal location
|
60
|
+
def journal_location
|
61
|
+
key('JournalPackageURL') || # First, try the 1.7 location...
|
62
|
+
key('NSNavLastRootDirectory')
|
63
|
+
end
|
25
64
|
|
26
65
|
# This allows us to access the body's method as well as the reader's.
|
27
66
|
def method_missing sym, *args
|
data/spec/dayone_spec.rb
CHANGED
@@ -18,7 +18,9 @@ describe DayOne do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return a default value when +location+ is 'auto'" do
|
21
|
-
|
21
|
+
reader = double('ReaderMock')
|
22
|
+
reader.should_receive(:journal_location).and_return('foo')
|
23
|
+
DayOne.plist_reader = reader
|
22
24
|
DayOne::dayone_folder = location('auto')
|
23
25
|
DayOne::journal_location.should == File.expand_path('foo')
|
24
26
|
end
|
data/spec/plist_reader_spec.rb
CHANGED
@@ -8,13 +8,11 @@ describe DayOne::PlistReader do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#body" do
|
11
|
-
it "should give us the location of the DayOne journal file" do
|
12
|
-
subject.should have_key('NSNavLastRootDirectory')
|
13
|
-
end
|
14
|
-
|
15
11
|
it "should correctly parse binary plists" do
|
16
12
|
reader = DayOne::PlistReader.new(File.join(File.dirname(__FILE__),'data', 'sample.plist'))
|
17
|
-
|
13
|
+
|
14
|
+
reader.key('foo').should == 'bar'
|
15
|
+
expect(reader.key('bing')).to be_nil
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-dayone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|