sequoia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +20 -0
- data/lib/sequoia/builder.rb +92 -0
- data/lib/sequoia/configurable.rb +47 -0
- data/lib/sequoia/configurator.rb +7 -0
- data/lib/sequoia/entity.rb +65 -0
- data/lib/sequoia/store.rb +34 -0
- data/lib/sequoia/version.rb +3 -0
- data/lib/sequoia.rb +9 -0
- data/sequoia.gemspec +26 -0
- data/spec/integration/configurator_spec.rb +61 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/unit/builder_spec.rb +71 -0
- data/spec/unit/entity_spec.rb +46 -0
- data/spec/unit/store_spec.rb +26 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3e551c4ff8d48406a2b15d204b91d02f785213d6
|
4
|
+
data.tar.gz: 5d37ac750c81303c32ec9acaea660a33beb34631
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4f214533793f0399bdd852ad6373ba333274b5e6eab74ac4d5948189771a799efaddf7dc5e0d271bbdf4b357f9bfe03697d1b92df0be36862499cab646eede4
|
7
|
+
data.tar.gz: 3c9d2510b2fbe0c52d886d0e1830fe47f4346f1f44fd60653e1c081358e5c41802b7a2a6b6d5ed870237b0d6ee74f62f1b9ed9d88bae3df36ca31f87bf3538d7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrey Savchenko
|
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,58 @@
|
|
1
|
+
# Sequoia
|
2
|
+
|
3
|
+
Sequoia is a gem for building environment-aware structures like configs, translations etc.
|
4
|
+
|
5
|
+
- [![Build Status](https://travis-ci.org/Ptico/sequoia.png)](https://travis-ci.org/Ptico/sequoia)
|
6
|
+
- [![Code Climate](https://codeclimate.com/github/Ptico/sequoia.png)](https://codeclimate.com/github/Ptico/sequoia)
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'sequoia'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sequoia
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
tree = Sequoia::Configurator.new
|
27
|
+
tree.configure do
|
28
|
+
working_folder '/srv'
|
29
|
+
timeout 30
|
30
|
+
database do
|
31
|
+
adapter 'postgres'
|
32
|
+
user 'app'
|
33
|
+
password 'secret'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
instance.configure :production do
|
38
|
+
timeout 60
|
39
|
+
cache true
|
40
|
+
database do
|
41
|
+
user 'root'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
config = instance.build(:production)
|
46
|
+
|
47
|
+
config.working_folder #=> '/srv'
|
48
|
+
config.timeout #=> 60
|
49
|
+
config.database.user #=> 'root'
|
50
|
+
```
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'reek/rake/task'
|
4
|
+
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc 'Test sequoia'
|
8
|
+
RSpec::Core::RakeTask.new('spec')
|
9
|
+
|
10
|
+
namespace :metrics do
|
11
|
+
desc 'Generate code coverage'
|
12
|
+
task :coverage do
|
13
|
+
ENV['COVERAGE'] = 'true'
|
14
|
+
Rake::Task['spec'].execute
|
15
|
+
end
|
16
|
+
|
17
|
+
Reek::Rake::Task.new do |reek|
|
18
|
+
reek.reek_opts = '--quiet'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Sequoia
|
2
|
+
|
3
|
+
##
|
4
|
+
# Class: Config builder
|
5
|
+
#
|
6
|
+
# Yields the block with definitions and then build keys and values
|
7
|
+
# Also works as a chainable builder
|
8
|
+
#
|
9
|
+
class Builder
|
10
|
+
|
11
|
+
##
|
12
|
+
# Storage for builded attributes
|
13
|
+
#
|
14
|
+
attr_reader :attrs
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
##
|
19
|
+
# Private: Initialize a new Builder
|
20
|
+
#
|
21
|
+
# Params:
|
22
|
+
# - attrs {Sequoia::Store} For internal use only (optional)
|
23
|
+
#
|
24
|
+
# Yields: block with key-value definitions
|
25
|
+
#
|
26
|
+
def initialize(attrs=Store.new, &block)
|
27
|
+
@attrs = attrs
|
28
|
+
|
29
|
+
instance_eval(&block) if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Private: Method missing handler
|
34
|
+
#
|
35
|
+
# This is where all the magic happens
|
36
|
+
#
|
37
|
+
# Params:
|
38
|
+
# - method_name {Symbol} Method name
|
39
|
+
# - args {Array} Array of arguments sended to the method
|
40
|
+
#
|
41
|
+
# Yields: Block with nested definitions
|
42
|
+
#
|
43
|
+
def method_missing(method_name, *args, &block)
|
44
|
+
key = normalize_method_name(method_name)
|
45
|
+
value = normalize_arguments(args, &block)
|
46
|
+
|
47
|
+
result = attrs[key] ||= (args.length > 0 || block_given? ? value : Store.new)
|
48
|
+
result.class == Store ? self.class.new(result) : result
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Private: Of course we respond to any key name
|
53
|
+
#
|
54
|
+
def respond_to_missing?(*)
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Private: Remove trailing `=` from getter name if exists
|
60
|
+
#
|
61
|
+
# Params:
|
62
|
+
# - method_name {Symbol} Method name
|
63
|
+
#
|
64
|
+
# Returns: {Symbol} Normalized method name
|
65
|
+
#
|
66
|
+
def normalize_method_name(method_name)
|
67
|
+
method_string = method_name.to_s
|
68
|
+
method_string.chop! if method_string.end_with?('=')
|
69
|
+
method_string.to_sym
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Private: Get value for assignment
|
74
|
+
#
|
75
|
+
# Params:
|
76
|
+
# - args {Array} Array of arguments
|
77
|
+
#
|
78
|
+
# Yields: Block with nested definitions
|
79
|
+
#
|
80
|
+
# Returns: Result of nested Builder#attrs or first argument from args or
|
81
|
+
# array of arguments if args.length > 1 or nil
|
82
|
+
#
|
83
|
+
def normalize_arguments(args, &block)
|
84
|
+
if block_given?
|
85
|
+
self.class.new(&block).attrs
|
86
|
+
else
|
87
|
+
args.length > 1 ? args : args[0]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'sequoia/entity'
|
2
|
+
|
3
|
+
module Sequoia
|
4
|
+
##
|
5
|
+
# Module: Configurable mixin
|
6
|
+
#
|
7
|
+
module Configurable
|
8
|
+
|
9
|
+
##
|
10
|
+
# Add or merge environment configuration
|
11
|
+
#
|
12
|
+
# Params:
|
13
|
+
# - env {Symbol} Environment to set (optional, default: :default)
|
14
|
+
#
|
15
|
+
# Yields: block with key-value definitions
|
16
|
+
#
|
17
|
+
# Returns: {Sequoia::Builder} builder instance
|
18
|
+
#
|
19
|
+
def configure(env=:default, &block)
|
20
|
+
environment = @config_attributes[env.to_sym] ||= Store.new
|
21
|
+
|
22
|
+
Builder.new(environment, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Build configuration object
|
27
|
+
#
|
28
|
+
# Params:
|
29
|
+
# - env {Symbol} Environment to build
|
30
|
+
#
|
31
|
+
# Returns: {Sequoia::Entity} builded configuration object
|
32
|
+
#
|
33
|
+
def build(env=nil)
|
34
|
+
result = @config_attributes[:default]
|
35
|
+
result.deep_merge(@config_attributes[env.to_sym]) if env
|
36
|
+
Entity.create(result)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def initialize(*)
|
42
|
+
@config_attributes = { default: Store.new }
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'sequoia/store'
|
2
|
+
|
3
|
+
module Sequoia
|
4
|
+
|
5
|
+
##
|
6
|
+
# Class: Resulting storage of configuration data
|
7
|
+
#
|
8
|
+
# Once it initialized - it can't be modified
|
9
|
+
#
|
10
|
+
class Entity < Struct
|
11
|
+
|
12
|
+
##
|
13
|
+
# Factory: Create new instance of entity
|
14
|
+
#
|
15
|
+
# Returns: {Sequoia::Entity}
|
16
|
+
def self.create(store)
|
17
|
+
keys = store.keys
|
18
|
+
|
19
|
+
values = store.values.map do |value|
|
20
|
+
value.class == Store ? create(value) : value
|
21
|
+
end
|
22
|
+
|
23
|
+
new(*keys).new(*values)
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Convert content of entity to hash
|
28
|
+
#
|
29
|
+
# TODO: Deep #to_hash
|
30
|
+
#
|
31
|
+
# Returns: {Hash} Hash of all keys and values
|
32
|
+
#
|
33
|
+
def to_hash
|
34
|
+
members.each_with_object({}) { |key, obj| obj[key] = self[key] }
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Represent content of entity as hash string
|
39
|
+
#
|
40
|
+
# Returns: {String} String with keys and values in hash format
|
41
|
+
#
|
42
|
+
def to_s
|
43
|
+
to_hash.to_s
|
44
|
+
end
|
45
|
+
alias :inspect :to_s
|
46
|
+
|
47
|
+
##
|
48
|
+
# Returns: {String} a pretty printed object
|
49
|
+
#
|
50
|
+
def pretty_inspect
|
51
|
+
PP.pp(to_hash, '')
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
##
|
57
|
+
# Private: Initialize and freeze the struct class
|
58
|
+
#
|
59
|
+
def initialize(*)
|
60
|
+
super
|
61
|
+
freeze
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Sequoia
|
2
|
+
##
|
3
|
+
# Class: Simple container to store internal config
|
4
|
+
#
|
5
|
+
# It exists only to make a difference between hash value and internal data
|
6
|
+
#
|
7
|
+
class Store < ::Hash
|
8
|
+
|
9
|
+
def deep_merge(store)
|
10
|
+
store.each_pair do |key, value|
|
11
|
+
if self[key].class == Store && value.class == Store
|
12
|
+
self[key].deep_merge(value)
|
13
|
+
else
|
14
|
+
self[key] = value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
##
|
24
|
+
# Private: Initialize new Store
|
25
|
+
#
|
26
|
+
# Params:
|
27
|
+
# - hash {Hash} Hash object to convert
|
28
|
+
#
|
29
|
+
def initialize(hash={})
|
30
|
+
super(nil)
|
31
|
+
self.merge!(hash)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/sequoia.rb
ADDED
data/sequoia.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 'sequoia/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'sequoia'
|
8
|
+
spec.version = Sequoia::VERSION
|
9
|
+
spec.authors = ['Andrey Savchenko', 'Dima Lunich']
|
10
|
+
spec.email = ['andrey@aejis.eu', 'dima.lunich@gmail.com']
|
11
|
+
spec.summary = %q{Gem for building data structures}
|
12
|
+
spec.description = %q{Sequoia is a gem for building environment-aware structures like configs, translations etc.}
|
13
|
+
spec.homepage = 'https://github.com/Ptico/sequoia'
|
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
|
+
spec.add_development_dependency 'reek'
|
25
|
+
spec.add_development_dependency 'simplecov'
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Configurator do
|
4
|
+
let(:instance) { described_class.new }
|
5
|
+
|
6
|
+
let(:config) do
|
7
|
+
instance.configure do
|
8
|
+
working_folder '/srv'
|
9
|
+
timeout 30
|
10
|
+
database do
|
11
|
+
adapter 'postgres'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
instance.configure :development do
|
16
|
+
timeout 60
|
17
|
+
cache false
|
18
|
+
database do
|
19
|
+
user 'dev'
|
20
|
+
pass 'null'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
instance.configure :production do
|
25
|
+
timeout 20
|
26
|
+
production true
|
27
|
+
database do
|
28
|
+
user 'admin'
|
29
|
+
pass 'secret'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
instance
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:result) { config.build(env) }
|
37
|
+
|
38
|
+
context 'without env' do
|
39
|
+
let(:env) { nil }
|
40
|
+
|
41
|
+
it 'should build config' do
|
42
|
+
expect(result.working_folder).to eql('/srv')
|
43
|
+
expect(result.timeout).to eql(30)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with env' do
|
48
|
+
let(:env) { :development }
|
49
|
+
|
50
|
+
it 'should merge config' do
|
51
|
+
expect(result.working_folder).to eql('/srv')
|
52
|
+
expect(result.timeout).to eql(60)
|
53
|
+
expect(result.cache).to be_false
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should merge namespaces' do
|
57
|
+
expect(result.database.adapter).to eql('postgres')
|
58
|
+
expect(result.database.user).to eql('dev')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
if ENV['COVERAGE']
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter '/spec/'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'sequoia'
|
9
|
+
|
10
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
11
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
12
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
13
|
+
# loaded once.
|
14
|
+
#
|
15
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
18
|
+
config.run_all_when_everything_filtered = true
|
19
|
+
config.filter_run :focus
|
20
|
+
|
21
|
+
# Run specs in random order to surface order dependencies. If you find an
|
22
|
+
# order dependency and want to debug it, you can fix the order by providing
|
23
|
+
# the seed, which is printed after each run.
|
24
|
+
# --seed 1234
|
25
|
+
config.order = 'random'
|
26
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Builder do
|
4
|
+
|
5
|
+
let(:result) { instance.attrs }
|
6
|
+
|
7
|
+
shared_examples 'block_attributes' do
|
8
|
+
it 'should set values' do
|
9
|
+
expect(result[:working_folder]).to eql('/srv')
|
10
|
+
expect(result[:timeout]).to eql(30)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should set namespaces' do
|
14
|
+
expect(result[:database][:name]).to eql('test_db')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should manage deep namespaces' do
|
18
|
+
expect(result[:database][:creds][:user]).to eql('admin')
|
19
|
+
expect(result[:database][:creds][:pass]).to eql('secret')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should handle booleans' do
|
23
|
+
expect(result[:async]).to be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should store hashes as hashes' do
|
27
|
+
expect(result[:database].class).to eql(Sequoia::Store)
|
28
|
+
expect(result[:creds].class).to eql(Hash)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'Block-style' do
|
33
|
+
let(:instance) do
|
34
|
+
described_class.new do
|
35
|
+
working_folder '/srv'
|
36
|
+
timeout 30
|
37
|
+
async false
|
38
|
+
creds(user: 'admin', pass: 'secret')
|
39
|
+
|
40
|
+
database do
|
41
|
+
creds do
|
42
|
+
user 'admin'
|
43
|
+
pass 'secret'
|
44
|
+
end
|
45
|
+
name 'test_db'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it_behaves_like 'block_attributes'
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'Object-style' do
|
54
|
+
let(:instance) do
|
55
|
+
inst = described_class.new
|
56
|
+
|
57
|
+
inst.working_folder = '/srv'
|
58
|
+
inst.timeout = 30
|
59
|
+
inst.async = false
|
60
|
+
inst.creds = { user: 'admin', pass: 'secret' }
|
61
|
+
|
62
|
+
inst.database.creds.user = 'admin'
|
63
|
+
inst.database.creds.pass = 'secret'
|
64
|
+
inst.database.name = 'test_db'
|
65
|
+
|
66
|
+
inst
|
67
|
+
end
|
68
|
+
|
69
|
+
it_behaves_like 'block_attributes'
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Entity do
|
4
|
+
let(:instance) { Sequoia::Entity.create(hash) }
|
5
|
+
|
6
|
+
let(:hash) do
|
7
|
+
Sequoia::Store.new({
|
8
|
+
working_folder: '/srv',
|
9
|
+
database: Sequoia::Store.new(name: 'test_db', user: 'inferno'),
|
10
|
+
creds: { user: 'admin', pass: 'secret' }
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should be frozen' do
|
15
|
+
expect(instance).to be_frozen
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should respond to keys' do
|
19
|
+
expect(instance).to respond_to(:working_folder)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should keep hashes' do
|
23
|
+
expect { instance.creds.user }.to raise_error
|
24
|
+
expect(instance.creds[:user]).to eql('admin')
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'as object' do
|
28
|
+
it 'should get keys' do
|
29
|
+
expect(instance.working_folder).to eql('/srv')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should get namespaces' do
|
33
|
+
expect(instance.database.name).to eql('test_db')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'as hash' do
|
38
|
+
it 'should get keys as hash keys' do
|
39
|
+
expect(instance[:working_folder]).to eql('/srv')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should get namespaces' do
|
43
|
+
expect(instance[:database][:name]).to eql('test_db')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Store do
|
4
|
+
let(:instance) { described_class.new(hash) }
|
5
|
+
let(:hash) do
|
6
|
+
{
|
7
|
+
working_folder: '/srv',
|
8
|
+
database: { name: 'test_db' },
|
9
|
+
creds: Sequoia::Store.new(name: 'admin')
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should create instance from hash' do
|
14
|
+
expect(instance[:working_folder]).to eql('/srv')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should set nested hashes' do
|
18
|
+
expect(instance[:database]).to be_a(Hash)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should merge nested stores' do
|
22
|
+
instance.deep_merge(Sequoia::Store.new(creds: Sequoia::Store.new(pass: 'secret')))
|
23
|
+
expect(instance[:creds][:name]).to eql('admin')
|
24
|
+
expect(instance[:creds][:pass]).to eql('secret')
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sequoia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Savchenko
|
8
|
+
- Dima Lunich
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: reek
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: simplecov
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: Sequoia is a gem for building environment-aware structures like configs,
|
85
|
+
translations etc.
|
86
|
+
email:
|
87
|
+
- andrey@aejis.eu
|
88
|
+
- dima.lunich@gmail.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- .gitignore
|
94
|
+
- .rspec
|
95
|
+
- .travis.yml
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- lib/sequoia.rb
|
101
|
+
- lib/sequoia/builder.rb
|
102
|
+
- lib/sequoia/configurable.rb
|
103
|
+
- lib/sequoia/configurator.rb
|
104
|
+
- lib/sequoia/entity.rb
|
105
|
+
- lib/sequoia/store.rb
|
106
|
+
- lib/sequoia/version.rb
|
107
|
+
- sequoia.gemspec
|
108
|
+
- spec/integration/configurator_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/unit/builder_spec.rb
|
111
|
+
- spec/unit/entity_spec.rb
|
112
|
+
- spec/unit/store_spec.rb
|
113
|
+
homepage: https://github.com/Ptico/sequoia
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.0.3
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Gem for building data structures
|
137
|
+
test_files:
|
138
|
+
- spec/integration/configurator_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/unit/builder_spec.rb
|
141
|
+
- spec/unit/entity_spec.rb
|
142
|
+
- spec/unit/store_spec.rb
|