annal 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -1
- data/lib/annal/collection.rb +4 -3
- data/lib/annal/version.rb +1 -1
- data/test/collection_integration_test.rb +7 -6
- metadata +5 -5
data/README.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
# Annal
|
2
2
|
|
3
|
-
|
3
|
+
Annal aims to solve a small problem I run into a bit ... reading and parsing groups of YAML or JSON files.
|
4
|
+
|
5
|
+
Instead of:
|
6
|
+
```ruby
|
7
|
+
Dir.glob('/path/*').each do |file|
|
8
|
+
if file =~ %r(\.ya?ml\Z)
|
9
|
+
YAML.parse(file)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
```
|
13
|
+
|
14
|
+
It would be:
|
15
|
+
```ruby
|
16
|
+
Annal::Collection.new('/path/*').documents
|
17
|
+
```
|
18
|
+
In the future, perhaps this will also get files from S3 or such. Crazier things have happened!
|
4
19
|
|
5
20
|
## Installation
|
6
21
|
|
data/lib/annal/collection.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Annal
|
2
2
|
class Collection
|
3
|
-
attr_accessor :dir
|
3
|
+
attr_accessor :dir, :dir_source
|
4
4
|
def initialize(dir)
|
5
5
|
self.dir = dir
|
6
|
+
self.dir_source = Dir.glob(dir)
|
6
7
|
end
|
7
8
|
|
8
|
-
def file_paths
|
9
|
-
|
9
|
+
def file_paths
|
10
|
+
dir_source.select {|path| File.file?(path) }
|
10
11
|
end
|
11
12
|
|
12
13
|
def documents
|
data/lib/annal/version.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
require_relative 'minitest_helper'
|
2
2
|
|
3
3
|
class TestCollectionIntegration < MiniTest::Unit::TestCase
|
4
|
-
def
|
5
|
-
@collection
|
4
|
+
def collection
|
5
|
+
@collection ||= Annal::Collection.new("#{Annal.project_root}/test/*")
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_file_paths
|
9
|
-
assert_operator
|
9
|
+
assert_operator collection.file_paths.length, :>, 1
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_file_paths
|
13
|
-
refute_includes
|
13
|
+
refute_includes collection.file_paths, "#{Annal.project_root}/test/test-dir"
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_documents
|
17
|
-
assert_operator
|
17
|
+
assert_operator collection.documents.length, :>, 1
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_glob
|
21
|
-
|
21
|
+
glob_collection = Annal::Collection.new("#{Annal.project_root}/test/*.yml")
|
22
|
+
assert_equal ["#{Annal.project_root}/test/test.yml"], glob_collection.file_paths
|
22
23
|
end
|
23
24
|
|
24
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: annal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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: 2013-
|
12
|
+
date: 2013-02-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash:
|
124
|
+
hash: 3452962492666588868
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
none: false
|
127
127
|
requirements:
|
@@ -130,10 +130,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash:
|
133
|
+
hash: 3452962492666588868
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
|
-
rubygems_version: 1.8.
|
136
|
+
rubygems_version: 1.8.25
|
137
137
|
signing_key:
|
138
138
|
specification_version: 3
|
139
139
|
summary: A wrapper for text files.
|