gimlet 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +9 -0
- data/fixtures/array/hello.yaml +3 -0
- data/fixtures/deep/hello.yaml +3 -0
- data/fixtures/directories/hello/world.yaml +2 -0
- data/fixtures/empty/.gitkeep +0 -0
- data/fixtures/suffix/yaml.yaml +2 -0
- data/fixtures/suffix/yml.yml +2 -0
- data/fixtures/yaml/hello.yaml +2 -0
- data/gimlet.gemspec +26 -0
- data/lib/gimlet/data_store.rb +37 -0
- data/lib/gimlet/util.rb +22 -0
- data/lib/gimlet/version.rb +3 -0
- data/lib/gimlet.rb +6 -0
- data/spec/gimlet/data_store_spec.rb +74 -0
- data/spec/spec_helper.rb +5 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 733389cf8385bfc6f6ddd4df9ef5a6048faa9e67
|
4
|
+
data.tar.gz: d6ebdf34974ecb99668f68bfb7eb9cc2ab4f2bd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71f88abd67a30819ce810946eca365fae9f199b97c78e446bf9afa2be85e055b24d1fbbeebdf2f40eaf1ddf7c1c7f5d711297ff10269c91428e743a354569285
|
7
|
+
data.tar.gz: d7565013532a8738d3b7115f06ecbdf1ba78feca799dc908246c10987a2fa670ed365afc9aea750a531374496d3a3db8a6113050eb9b0f057e2b514838ac1701
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Yoji SHIDARA
|
2
|
+
|
3
|
+
MIT License
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Gimlet
|
2
|
+
|
3
|
+
Document-oriented, Text-based and Read-only data storage
|
4
|
+
|
5
|
+
Gimlet is strongly inspired by [Local Data](http://middlemanapp.com/advanced/local-data/) of [Middleman](http://middlemanapp.com/). It is so handy, but it is built in middleman.
|
6
|
+
|
7
|
+
Gimlet let us to use this feature for general purposes that do not fit middleman with.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'gimlet'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gimlet
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Put `data/people/homuhomu.yaml`,
|
26
|
+
|
27
|
+
---
|
28
|
+
first_name: Akemi
|
29
|
+
last_name: Homura
|
30
|
+
|
31
|
+
Then you can access the data:
|
32
|
+
|
33
|
+
require 'gimlet'
|
34
|
+
|
35
|
+
DB = Gimlet::DataStore.new('data')
|
36
|
+
|
37
|
+
p data.to_h #=> {"homuhomu"=>{"first_name"=>"Akemi", "last_name"=>"Homura"}}
|
38
|
+
p data.homuhomu #=> {"first_name"=>"Akemi", "last_name"=>"Homura"}
|
39
|
+
p data[:homuhomu].last_name #=> "Homura"
|
40
|
+
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
File without changes
|
data/gimlet.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gimlet/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gimlet"
|
8
|
+
spec.version = Gimlet::VERSION
|
9
|
+
spec.authors = ["Yoji SHIDARA"]
|
10
|
+
spec.email = ["dara@shidara.net"]
|
11
|
+
spec.description = %q{Document-oriented, Text-based and Read-only data storage}
|
12
|
+
spec.summary = %q{Document-oriented, Text-based and Read-only data storage}
|
13
|
+
spec.homepage = "https://github.com/darashi/gimlet"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_dependency "thor"
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'thor'
|
3
|
+
require 'forwardable'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
module Gimlet
|
7
|
+
class DataStore
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def initialize(data_directory)
|
11
|
+
@data_directory = Pathname(data_directory)
|
12
|
+
@local_data = ::Gimlet::Util.recursively_enhance({})
|
13
|
+
load_all!
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_all!
|
17
|
+
Pathname.glob(@data_directory + '**/*.{yaml,yml}').each do |path|
|
18
|
+
extension = path.extname
|
19
|
+
basename = path.basename(extension)
|
20
|
+
|
21
|
+
parts = path.relative_path_from(@data_directory).split.map(&:to_s)[0..-1]
|
22
|
+
parts.delete('.')
|
23
|
+
parts.pop
|
24
|
+
|
25
|
+
current = @local_data
|
26
|
+
parts.each do |part|
|
27
|
+
current[part] ||= ::Gimlet::Util.recursively_enhance({})
|
28
|
+
current = current[part]
|
29
|
+
end
|
30
|
+
|
31
|
+
current[basename.to_s] = ::Gimlet::Util.recursively_enhance(YAML.load_file(path))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def_delegators :@local_data, :[], :method_missing, :to_h
|
36
|
+
end
|
37
|
+
end
|
data/lib/gimlet/util.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Gimlet
|
2
|
+
class Util
|
3
|
+
class << self
|
4
|
+
def recursively_enhance(data)
|
5
|
+
case data
|
6
|
+
when Hash
|
7
|
+
data = ::Thor::CoreExt::HashWithIndifferentAccess.new(data)
|
8
|
+
data.each do |key, value|
|
9
|
+
data[key] = recursively_enhance(value)
|
10
|
+
end
|
11
|
+
data
|
12
|
+
when Array
|
13
|
+
data.map do |value|
|
14
|
+
recursively_enhance(value)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
data
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/gimlet.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Gimlet::DataStore do
|
4
|
+
describe 'empty' do
|
5
|
+
subject { Gimlet::DataStore.new(fixture_path('empty')) }
|
6
|
+
|
7
|
+
it do
|
8
|
+
expect(subject.to_h).to eq({})
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'yaml' do
|
13
|
+
subject { Gimlet::DataStore.new(fixture_path('yaml')) }
|
14
|
+
|
15
|
+
it do
|
16
|
+
expect(subject.to_h).to eq({'hello' => {'message' => 'Hello world'}})
|
17
|
+
end
|
18
|
+
|
19
|
+
it do
|
20
|
+
expect(subject.hello.message).to eq('Hello world')
|
21
|
+
end
|
22
|
+
|
23
|
+
it do
|
24
|
+
expect(subject[:hello][:message]).to eq('Hello world')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'deep' do
|
29
|
+
subject { Gimlet::DataStore.new(fixture_path('deep')) }
|
30
|
+
it do
|
31
|
+
expect(subject.to_h).to eq({'hello' => {'message' => {'en' => 'Hello world'}}})
|
32
|
+
end
|
33
|
+
|
34
|
+
it do
|
35
|
+
expect(subject.hello.message.en).to eq('Hello world')
|
36
|
+
end
|
37
|
+
|
38
|
+
it do
|
39
|
+
expect(subject[:hello][:message][:en]).to eq('Hello world')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'array' do
|
44
|
+
subject { Gimlet::DataStore.new(fixture_path('array')) }
|
45
|
+
|
46
|
+
it do
|
47
|
+
expect(subject.to_h).to eq('hello' => ['Hello world', 'こんにちは世界'])
|
48
|
+
end
|
49
|
+
|
50
|
+
it do
|
51
|
+
expect(subject.hello.first).to eq('Hello world')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'directries' do
|
56
|
+
subject { Gimlet::DataStore.new(fixture_path('directories')) }
|
57
|
+
|
58
|
+
it do
|
59
|
+
expect(subject.to_h).to eq({'hello' => {'world' => {'message' => 'Hello world'}}})
|
60
|
+
end
|
61
|
+
|
62
|
+
it do
|
63
|
+
expect(subject.hello.world.message).to eq('Hello world')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'suffix' do
|
68
|
+
subject { Gimlet::DataStore.new(fixture_path('suffix')) }
|
69
|
+
|
70
|
+
it do
|
71
|
+
expect(subject.to_h).to eq({'yaml' => {'name' => 'yaml'}, 'yml' => {'name' => 'yml'}})
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gimlet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoji SHIDARA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Document-oriented, Text-based and Read-only data storage
|
70
|
+
email:
|
71
|
+
- dara@shidara.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- fixtures/array/hello.yaml
|
83
|
+
- fixtures/deep/hello.yaml
|
84
|
+
- fixtures/directories/hello/world.yaml
|
85
|
+
- fixtures/empty/.gitkeep
|
86
|
+
- fixtures/suffix/yaml.yaml
|
87
|
+
- fixtures/suffix/yml.yml
|
88
|
+
- fixtures/yaml/hello.yaml
|
89
|
+
- gimlet.gemspec
|
90
|
+
- lib/gimlet.rb
|
91
|
+
- lib/gimlet/data_store.rb
|
92
|
+
- lib/gimlet/util.rb
|
93
|
+
- lib/gimlet/version.rb
|
94
|
+
- spec/gimlet/data_store_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
homepage: https://github.com/darashi/gimlet
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.3
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Document-oriented, Text-based and Read-only data storage
|
120
|
+
test_files:
|
121
|
+
- spec/gimlet/data_store_spec.rb
|
122
|
+
- spec/spec_helper.rb
|