gimlet 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +5 -5
- data/lib/gimlet/data_store.rb +25 -5
- data/lib/gimlet/version.rb +1 -1
- data/spec/gimlet/data_store_spec.rb +16 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf39d44503a768fe66812c45cc20df9454d5b214
|
4
|
+
data.tar.gz: 10f512cf0ce4ac85fcb1273a60b2b8740757282e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0c58e6c97ed992514af5640418bd67f4b77a53de3fcb91809deeeff607ed53051f04b18fc29c9711a5b3fab21c882f3aaf2661971aa952772dbd8a01d1e41ec
|
7
|
+
data.tar.gz: ccf512ff0308030fb1753bfdf54136f7c75e0de00c6daf8cb8921b6efe91ab542f15d51b0d0279becbdc56ee1e7d98e01f3496d1026925064dfbc14d09ebf62f
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -25,8 +25,8 @@ Or install it yourself as:
|
|
25
25
|
Put `data/people/homuhomu.yaml`,
|
26
26
|
|
27
27
|
---
|
28
|
-
first_name:
|
29
|
-
last_name:
|
28
|
+
first_name: Homura
|
29
|
+
last_name: Akemi
|
30
30
|
|
31
31
|
Then you can access the data:
|
32
32
|
|
@@ -34,9 +34,9 @@ Then you can access the data:
|
|
34
34
|
|
35
35
|
data = Gimlet::DataStore.new('data')
|
36
36
|
|
37
|
-
p data.to_h #=> {"people"=>{"homuhomu"=>{"first_name"=>"
|
38
|
-
p data.people.homuhomu #=> {"first_name"=>"
|
39
|
-
p data.people[:homuhomu].
|
37
|
+
p data.to_h #=> {"people"=>{"homuhomu"=>{"first_name"=>"Homura", "last_name"=>"Akemi"}}}
|
38
|
+
p data.people.homuhomu #=> {"first_name"=>"Homura", "last_name"=>"Akemi"}
|
39
|
+
p data.people[:homuhomu].first_name #=> "Homura"
|
40
40
|
|
41
41
|
|
42
42
|
## Contributing
|
data/lib/gimlet/data_store.rb
CHANGED
@@ -7,18 +7,30 @@ module Gimlet
|
|
7
7
|
class DataStore
|
8
8
|
extend Forwardable
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
class SourceNotFound < StandardError; end
|
11
|
+
|
12
|
+
def initialize(source_path)
|
13
|
+
@source_path = Pathname(source_path)
|
12
14
|
@local_data = ::Gimlet::Util.recursively_enhance({})
|
13
15
|
load_all!
|
14
16
|
end
|
15
17
|
|
16
18
|
def load_all!
|
17
|
-
|
19
|
+
if @source_path.directory?
|
20
|
+
load_from_directory!
|
21
|
+
elsif @source_path.file?
|
22
|
+
load_from_file!
|
23
|
+
else
|
24
|
+
raise SourceNotFound, 'No such file or directory - %s' % @source_path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_from_directory!
|
29
|
+
Pathname.glob(@source_path + '**/*.{yaml,yml}').each do |path|
|
18
30
|
extension = path.extname
|
19
31
|
basename = path.basename(extension)
|
20
32
|
|
21
|
-
parts = path.relative_path_from(@
|
33
|
+
parts = path.relative_path_from(@source_path).split.map(&:to_s)[0..-1]
|
22
34
|
parts.delete('.')
|
23
35
|
parts.pop
|
24
36
|
|
@@ -28,10 +40,18 @@ module Gimlet
|
|
28
40
|
current = current[part]
|
29
41
|
end
|
30
42
|
|
31
|
-
current[basename.to_s] =
|
43
|
+
current[basename.to_s] = load_from_file(path)
|
32
44
|
end
|
33
45
|
end
|
34
46
|
|
47
|
+
def load_from_file!
|
48
|
+
@local_data = load_from_file(@source_path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_from_file(path)
|
52
|
+
::Gimlet::Util.recursively_enhance(YAML.load_file(path))
|
53
|
+
end
|
54
|
+
|
35
55
|
def_delegators :@local_data, :[], :method_missing, :to_h, :each
|
36
56
|
end
|
37
57
|
end
|
data/lib/gimlet/version.rb
CHANGED
@@ -71,4 +71,20 @@ describe Gimlet::DataStore do
|
|
71
71
|
expect(subject.to_h).to eq({'yaml' => {'name' => 'yaml'}, 'yml' => {'name' => 'yml'}})
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
describe 'filename' do
|
76
|
+
subject { Gimlet::DataStore.new(fixture_path('yaml/hello.yaml')) }
|
77
|
+
|
78
|
+
it do
|
79
|
+
expect(subject.to_h).to eq({'message' => 'Hello world'})
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'not found' do
|
84
|
+
subject { Gimlet::DataStore.new('NOT_FOUND') }
|
85
|
+
|
86
|
+
it do
|
87
|
+
expect(->{ subject }).to raise_error(Gimlet::DataStore::SourceNotFound)
|
88
|
+
end
|
89
|
+
end
|
74
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gimlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoji SHIDARA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
77
|
- .rspec
|
78
|
+
- .travis.yml
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|