sequoia 0.0.1 → 0.1.0
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 +4 -4
- data/.gitignore +4 -1
- data/.travis.yml +6 -2
- data/Gemfile +5 -1
- data/README.md +2 -2
- data/Thorfile +43 -0
- data/lib/sequoia/builder.rb +34 -34
- data/lib/sequoia/configurable.rb +9 -7
- data/lib/sequoia/entity.rb +6 -12
- data/lib/sequoia/store.rb +4 -5
- data/lib/sequoia/version.rb +1 -1
- data/sequoia.gemspec +3 -2
- data/spec/integration/configurator_spec.rb +2 -0
- data/spec/spec_helper.rb +0 -4
- data/spec/unit/sequoia/builder/attrs_spec.rb +84 -0
- data/spec/unit/sequoia/builder/class_spec.rb +10 -0
- data/spec/unit/sequoia/builder/respond_to_predicate_spec.rb +10 -0
- data/spec/unit/sequoia/builder/to_s_spec.rb +18 -0
- data/spec/unit/sequoia/configurable/build_spec.rb +30 -0
- data/spec/unit/sequoia/configurable/configure_spec.rb +44 -0
- data/spec/unit/sequoia/entity/class_methods/create_spec.rb +48 -0
- data/spec/unit/sequoia/entity/pretty_inspect_spec.rb +15 -0
- data/spec/unit/sequoia/entity/to_hash_spec.rb +12 -0
- data/spec/unit/sequoia/entity/to_s_spec.rb +15 -0
- data/spec/unit/sequoia/store/deep_merge_bang_spec.rb +66 -0
- data/spec/unit/sequoia/store/element_reader_spec.rb +19 -0
- metadata +31 -26
- data/Rakefile +0 -20
- data/spec/unit/builder_spec.rb +0 -71
- data/spec/unit/entity_spec.rb +0 -46
- data/spec/unit/store_spec.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb4670af90bd4e43c4dc7b5088bba98bd15809df
|
4
|
+
data.tar.gz: d08b4ed06fe2c4e6968aaec315a7d3a2e6f50d15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b88512b37e30fafb89304575902be384129e7c36ea3069a5feeafce901822898b1a670ad805e8a9c72636871dadfce4d4adec1fe2eae0d6cde0b6d35bde60bf
|
7
|
+
data.tar.gz: a982713a595a9b7f6e8ddde173a1dff9d72b83551c8d7c45bae61e5a6f9f1408526dc8b40e2dbc38fdf4b7aa5bca6809a02e04a557a757f4edfe048444339374
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,7 @@ tree.configure do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
tree.configure :production do
|
38
38
|
timeout 60
|
39
39
|
cache true
|
40
40
|
database do
|
@@ -42,7 +42,7 @@ instance.configure :production do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
config =
|
45
|
+
config = tree.build(:production)
|
46
46
|
|
47
47
|
config.working_folder #=> '/srv'
|
48
48
|
config.timeout #=> 60
|
data/Thorfile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require 'sequoia/version'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'mutant'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
class Default < Thor
|
11
|
+
desc 'spec [TYPE]', 'Run RSpec code examples (integration, unit or all)'
|
12
|
+
def spec(type=nil)
|
13
|
+
exec "rspec --color spec/#{type}"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'coverage [TYPE]', 'Generate code coverage'
|
17
|
+
def coverage(type=nil)
|
18
|
+
ENV['COVERAGE'] = 'true'
|
19
|
+
spec(type)
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'mutant [NAMESPACE]', 'Run mutation tests for NAMESPACE'
|
23
|
+
def mutant(namespace='*')
|
24
|
+
Mutant::CLI.run(%W(--include lib --require sequoia ::Sequoia#{namespace} --rspec))
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'build', "Build sequoia-#{Sequoia::VERSION}.gem into the pkg directory"
|
28
|
+
def build
|
29
|
+
Bundler::GemHelper.new.build_gem
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'install', "Build and install sequoia-#{Sequoia::VERSION}.gem into system gems"
|
33
|
+
def install
|
34
|
+
helper = Bundler::GemHelper.new
|
35
|
+
helper.install_gem(helper.build_gem)
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'release', "Create tag v#{Sequoia::VERSION} and build and push sequoia-#{Sequoia::VERSION}.gem to Rubygems"
|
39
|
+
def release
|
40
|
+
helper = Bundler::GemHelper.new
|
41
|
+
helper.release_gem(helper.build_gem)
|
42
|
+
end
|
43
|
+
end
|
data/lib/sequoia/builder.rb
CHANGED
@@ -6,13 +6,37 @@ module Sequoia
|
|
6
6
|
# Yields the block with definitions and then build keys and values
|
7
7
|
# Also works as a chainable builder
|
8
8
|
#
|
9
|
-
class Builder
|
10
|
-
|
9
|
+
class Builder < BasicObject
|
11
10
|
##
|
12
11
|
# Storage for builded attributes
|
13
12
|
#
|
14
13
|
attr_reader :attrs
|
15
14
|
|
15
|
+
##
|
16
|
+
# Returns the class of object
|
17
|
+
#
|
18
|
+
# This method must always be called with an explicit receiver, as `class` is also a reserved word in Ruby
|
19
|
+
#
|
20
|
+
def class
|
21
|
+
Builder
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Of course we respond to any key name
|
26
|
+
#
|
27
|
+
def respond_to?(*)
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Represent builder as string
|
33
|
+
#
|
34
|
+
def to_s
|
35
|
+
"#<Sequoia::Builder attrs=#{attrs}>"
|
36
|
+
end
|
37
|
+
alias :inspect :to_s
|
38
|
+
alias :pretty_inspect :to_s
|
39
|
+
|
16
40
|
private
|
17
41
|
|
18
42
|
##
|
@@ -25,8 +49,7 @@ module Sequoia
|
|
25
49
|
#
|
26
50
|
def initialize(attrs=Store.new, &block)
|
27
51
|
@attrs = attrs
|
28
|
-
|
29
|
-
instance_eval(&block) if block_given?
|
52
|
+
instance_eval(&block) if ::Kernel.block_given?
|
30
53
|
end
|
31
54
|
|
32
55
|
##
|
@@ -41,18 +64,14 @@ module Sequoia
|
|
41
64
|
# Yields: Block with nested definitions
|
42
65
|
#
|
43
66
|
def method_missing(method_name, *args, &block)
|
44
|
-
key
|
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
|
67
|
+
key = normalize_method_name(method_name)
|
50
68
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
69
|
+
if args.length > 0
|
70
|
+
attrs[key] = args.length > 1 ? args : args[0]
|
71
|
+
else
|
72
|
+
attrs[key] ||= Store.new
|
73
|
+
self.class.new(attrs[key], &block)
|
74
|
+
end
|
56
75
|
end
|
57
76
|
|
58
77
|
##
|
@@ -69,24 +88,5 @@ module Sequoia
|
|
69
88
|
method_string.to_sym
|
70
89
|
end
|
71
90
|
|
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
91
|
end
|
92
92
|
end
|
data/lib/sequoia/configurable.rb
CHANGED
@@ -17,7 +17,7 @@ module Sequoia
|
|
17
17
|
# Returns: {Sequoia::Builder} builder instance
|
18
18
|
#
|
19
19
|
def configure(env=:default, &block)
|
20
|
-
environment =
|
20
|
+
environment = config_attributes[env.to_sym] ||= Store.new
|
21
21
|
|
22
22
|
Builder.new(environment, &block)
|
23
23
|
end
|
@@ -31,16 +31,18 @@ module Sequoia
|
|
31
31
|
# Returns: {Sequoia::Entity} builded configuration object
|
32
32
|
#
|
33
33
|
def build(env=nil)
|
34
|
-
result =
|
35
|
-
result.deep_merge(
|
34
|
+
result = config_attributes[:default]
|
35
|
+
result.deep_merge!(config_attributes[env.to_sym]) if env
|
36
36
|
Entity.create(result)
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
protected
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
##
|
42
|
+
# Config environments storage
|
43
|
+
#
|
44
|
+
def config_attributes
|
45
|
+
@config_attributes ||= { default: Store.new }
|
44
46
|
end
|
45
47
|
|
46
48
|
end
|
data/lib/sequoia/entity.rb
CHANGED
@@ -13,14 +13,18 @@ module Sequoia
|
|
13
13
|
# Factory: Create new instance of entity
|
14
14
|
#
|
15
15
|
# Returns: {Sequoia::Entity}
|
16
|
-
def self.create(store)
|
16
|
+
def self.create(store=Store.new)
|
17
17
|
keys = store.keys
|
18
18
|
|
19
19
|
values = store.values.map do |value|
|
20
20
|
value.class == Store ? create(value) : value
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
if keys.any?
|
24
|
+
new(*keys).new(*values).freeze
|
25
|
+
else
|
26
|
+
Object.new.freeze
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
##
|
@@ -51,15 +55,5 @@ module Sequoia
|
|
51
55
|
PP.pp(to_hash, '')
|
52
56
|
end
|
53
57
|
|
54
|
-
private
|
55
|
-
|
56
|
-
##
|
57
|
-
# Private: Initialize and freeze the struct class
|
58
|
-
#
|
59
|
-
def initialize(*)
|
60
|
-
super
|
61
|
-
freeze
|
62
|
-
end
|
63
|
-
|
64
58
|
end
|
65
59
|
end
|
data/lib/sequoia/store.rb
CHANGED
@@ -6,10 +6,10 @@ module Sequoia
|
|
6
6
|
#
|
7
7
|
class Store < ::Hash
|
8
8
|
|
9
|
-
def deep_merge(store)
|
9
|
+
def deep_merge!(store)
|
10
10
|
store.each_pair do |key, value|
|
11
|
-
if self[key].
|
12
|
-
self[key].deep_merge(value)
|
11
|
+
if self[key].is_a?(Store)
|
12
|
+
self[key].deep_merge!(value)
|
13
13
|
else
|
14
14
|
self[key] = value
|
15
15
|
end
|
@@ -27,8 +27,7 @@ module Sequoia
|
|
27
27
|
# - hash {Hash} Hash object to convert
|
28
28
|
#
|
29
29
|
def initialize(hash={})
|
30
|
-
|
31
|
-
self.merge!(hash)
|
30
|
+
merge!(hash)
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
data/lib/sequoia/version.rb
CHANGED
data/sequoia.gemspec
CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.required_ruby_version = '>= 1.9.2'
|
22
|
+
|
21
23
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
-
spec.add_development_dependency '
|
24
|
+
spec.add_development_dependency 'thor'
|
23
25
|
spec.add_development_dependency 'rspec'
|
24
|
-
spec.add_development_dependency 'reek'
|
25
26
|
spec.add_development_dependency 'simplecov'
|
26
27
|
end
|
@@ -6,6 +6,7 @@ describe Sequoia::Configurator do
|
|
6
6
|
let(:config) do
|
7
7
|
instance.configure do
|
8
8
|
working_folder '/srv'
|
9
|
+
puts 22
|
9
10
|
timeout 30
|
10
11
|
database do
|
11
12
|
adapter 'postgres'
|
@@ -41,6 +42,7 @@ describe Sequoia::Configurator do
|
|
41
42
|
it 'should build config' do
|
42
43
|
expect(result.working_folder).to eql('/srv')
|
43
44
|
expect(result.timeout).to eql(30)
|
45
|
+
expect(result.puts).to eql(22)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
data/spec/spec_helper.rb
CHANGED
@@ -14,10 +14,6 @@ require 'sequoia'
|
|
14
14
|
#
|
15
15
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
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
17
|
# Run specs in random order to surface order dependencies. If you find an
|
22
18
|
# order dependency and want to debug it, you can fix the order by providing
|
23
19
|
# the seed, which is printed after each run.
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Builder, '#attrs' do
|
4
|
+
let(:subject) { instance.attrs }
|
5
|
+
|
6
|
+
shared_examples 'builder_attributes' do
|
7
|
+
it 'should have values' do
|
8
|
+
expect(subject[:working_folder]).to eql('/srv')
|
9
|
+
expect(subject[:timeout]).to eql(30)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have namespaces' do
|
13
|
+
expect(subject[:database][:name]).to eql('test_db')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have deep namespaces' do
|
17
|
+
expect(subject[:database][:creds][:user]).to eql('admin')
|
18
|
+
expect(subject[:database][:creds][:pass]).to eql('secret')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should handle booleans' do
|
22
|
+
expect(subject[:async]).to be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should store hashes as hashes' do
|
26
|
+
expect(subject[:database]).to be_instance_of(Sequoia::Store)
|
27
|
+
expect(subject[:creds]).to be_instance_of(Hash)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'Block-style' do
|
32
|
+
let(:instance) do
|
33
|
+
described_class.new do
|
34
|
+
working_folder '/srv'
|
35
|
+
timeout 30
|
36
|
+
async false
|
37
|
+
creds(user: 'admin', pass: 'secret')
|
38
|
+
|
39
|
+
database do
|
40
|
+
creds do
|
41
|
+
user 'admin'
|
42
|
+
end
|
43
|
+
name 'test_db'
|
44
|
+
end
|
45
|
+
|
46
|
+
database do
|
47
|
+
creds do
|
48
|
+
pass 'secret'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it_behaves_like 'builder_attributes'
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'Object-style' do
|
58
|
+
let(:instance) do
|
59
|
+
inst = described_class.new
|
60
|
+
|
61
|
+
inst.working_folder = '/srv'
|
62
|
+
inst.timeout = 30
|
63
|
+
inst.async = false
|
64
|
+
inst.creds = { user: 'admin', pass: 'secret' }
|
65
|
+
|
66
|
+
inst.database.creds.user = 'admin'
|
67
|
+
inst.database.creds.pass = 'secret'
|
68
|
+
inst.database.name = 'test_db'
|
69
|
+
|
70
|
+
inst
|
71
|
+
end
|
72
|
+
|
73
|
+
it_behaves_like 'builder_attributes'
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'Empty' do
|
77
|
+
let(:instance) { described_class.new }
|
78
|
+
|
79
|
+
it "should be an empty store" do
|
80
|
+
expect(subject).to eq({})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Builder, '#respond_to?' do
|
4
|
+
let(:instance) { described_class.new }
|
5
|
+
|
6
|
+
it 'should respond to any method' do
|
7
|
+
expect(instance).to respond_to(:qqeeellzmls)
|
8
|
+
expect(instance.respond_to?(:qqeeellzmls)).to be_true
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Builder, '#to_s' do
|
4
|
+
let(:subject) { instance.to_s }
|
5
|
+
let(:instance) { described_class.new }
|
6
|
+
|
7
|
+
it 'should return string' do
|
8
|
+
expect(subject.class).to eql(String)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should contain class name' do
|
12
|
+
expect(subject).to start_with('#<Sequoia::Builder')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should contain attrs hash' do
|
16
|
+
expect(subject).to match(/attrs={.*}/)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Configurable, '#build' do
|
4
|
+
let(:instance) { Class.new.send(:include, Sequoia::Configurable).new }
|
5
|
+
|
6
|
+
it 'should return object if empty' do
|
7
|
+
expect(instance.build).to be_an(Object)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return entity if not empty' do
|
11
|
+
instance.configure do
|
12
|
+
path '/home'
|
13
|
+
end
|
14
|
+
|
15
|
+
expect(instance.build).to be_a(Sequoia::Entity)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should merge envs' do
|
19
|
+
instance.configure do
|
20
|
+
path '/home'
|
21
|
+
end
|
22
|
+
|
23
|
+
instance.configure :test do
|
24
|
+
log_level :info
|
25
|
+
end
|
26
|
+
|
27
|
+
expect(instance.build('test').path).to eq('/home')
|
28
|
+
expect(instance.build(:test).log_level).to eq(:info)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Configurable, '#configure' do
|
4
|
+
let(:object) {
|
5
|
+
Class.new do
|
6
|
+
include Sequoia::Configurable
|
7
|
+
attr_reader :foo
|
8
|
+
private
|
9
|
+
def initialize(foo)
|
10
|
+
@foo = foo
|
11
|
+
end
|
12
|
+
end
|
13
|
+
}
|
14
|
+
let(:instance) { object.new(5) }
|
15
|
+
let(:attrs) { instance.instance_variable_get(:@config_attributes) }
|
16
|
+
|
17
|
+
it 'should not be broken when included' do
|
18
|
+
expect { instance.configure }.to_not raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should create default environment' do
|
22
|
+
instance.configure do
|
23
|
+
path '/home'
|
24
|
+
end
|
25
|
+
|
26
|
+
expect(attrs[:default]).to have_key(:path)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'environment should be a store' do
|
30
|
+
instance.configure do
|
31
|
+
path '/home'
|
32
|
+
end
|
33
|
+
|
34
|
+
expect(attrs[:default]).to be_instance_of(Sequoia::Store)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should create custom environment' do
|
38
|
+
instance.configure :development do
|
39
|
+
path '/home'
|
40
|
+
end
|
41
|
+
|
42
|
+
expect(attrs[:development]).to have_key(:path)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Entity, '.create' do
|
4
|
+
let(:subject) { Sequoia::Entity.create(hash) }
|
5
|
+
let(:empty_subject) { Sequoia::Entity.create }
|
6
|
+
|
7
|
+
let(:hash) do
|
8
|
+
Sequoia::Store.new({
|
9
|
+
working_folder: '/srv',
|
10
|
+
database: Sequoia::Store.new(name: 'test_db', user: 'inferno'),
|
11
|
+
creds: { user: 'admin', pass: 'secret' }
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should create empty object if empty' do
|
16
|
+
expect(empty_subject).to be_instance_of(Object)
|
17
|
+
expect(empty_subject).to be_frozen
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should be frozen' do
|
21
|
+
expect(subject).to be_frozen
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should keep hashes' do
|
25
|
+
expect { subject.creds.user }.to raise_error
|
26
|
+
expect(subject.creds[:user]).to eql('admin')
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'as object' do
|
30
|
+
it 'should get keys' do
|
31
|
+
expect(subject.working_folder).to eql('/srv')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should get namespaces' do
|
35
|
+
expect(subject.database.name).to eql('test_db')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'as hash' do
|
40
|
+
it 'should get keys' do
|
41
|
+
expect(subject[:working_folder]).to eql('/srv')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should get namespaces' do
|
45
|
+
expect(subject[:database][:name]).to eql('test_db')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Entity, '#pretty_inspect' do
|
4
|
+
let(:subject) { instance.pretty_inspect }
|
5
|
+
let(:instance) { Sequoia::Entity.create(hash) }
|
6
|
+
let(:hash) { Sequoia::Store.new(working_folder: '/srv') }
|
7
|
+
|
8
|
+
it 'should return string' do
|
9
|
+
expect(subject).to be_instance_of(String)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should represent hash' do
|
13
|
+
expect(subject).to match(/^\{\:?working_folder.*srv/)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Entity, '#to_hash' do
|
4
|
+
let(:subject) { instance.to_hash }
|
5
|
+
let(:instance) { Sequoia::Entity.create(hash) }
|
6
|
+
let(:hash) { Sequoia::Store.new(working_folder: '/srv') }
|
7
|
+
|
8
|
+
it 'should convert instance to hash' do
|
9
|
+
expect(subject).to be_instance_of(Hash)
|
10
|
+
expect(subject).to eq({working_folder: '/srv'})
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Entity, '#to_s' do
|
4
|
+
let(:subject) { instance.to_s }
|
5
|
+
let(:instance) { Sequoia::Entity.create(hash) }
|
6
|
+
let(:hash) { Sequoia::Store.new(working_folder: '/srv') }
|
7
|
+
|
8
|
+
it 'should return string' do
|
9
|
+
expect(subject).to be_instance_of(String)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should represent hash' do
|
13
|
+
expect(subject).to match(/^\{\:?working_folder.*srv/)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Store, '#deep_merge!' do
|
4
|
+
let(:subject) { instance.deep_merge!(secondary_hash) }
|
5
|
+
let(:instance) { described_class.new(start_hash) }
|
6
|
+
let(:start_hash) do
|
7
|
+
{
|
8
|
+
working_folder: '/srv',
|
9
|
+
database: { name: 'test_db' },
|
10
|
+
creds: Sequoia::Store.new(name: 'admin')
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'empty store' do
|
15
|
+
let(:instance) { described_class.new }
|
16
|
+
let(:secondary_hash) { Sequoia::Store.new(working_folder: '/srv') }
|
17
|
+
|
18
|
+
it 'should merge' do
|
19
|
+
expect(subject[:working_folder]).to eql('/srv')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'nested stores' do
|
24
|
+
let(:secondary_hash) { Sequoia::Store.new(creds: Sequoia::Store.new(pass: 'secret')) }
|
25
|
+
|
26
|
+
it 'should merge' do
|
27
|
+
expect(subject[:creds][:name]).to eql('admin')
|
28
|
+
expect(subject[:creds][:pass]).to eql('secret')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'nested hashes' do
|
33
|
+
let(:secondary_hash) { { database: { user: 'postgres' } } }
|
34
|
+
|
35
|
+
it 'should rewrite' do
|
36
|
+
expect(subject[:database][:user]).to eql('postgres')
|
37
|
+
expect(subject[:database][:name]).to be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'nested hash and store' do
|
42
|
+
let(:secondary_hash) { Sequoia::Store.new(database: Sequoia::Store.new(user: 'postgres')) }
|
43
|
+
|
44
|
+
it 'should rewrite' do
|
45
|
+
expect(subject[:database][:user]).to eql('postgres')
|
46
|
+
expect(subject[:database][:name]).to be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'nested store and hash' do
|
51
|
+
let(:secondary_hash) { { creds: { pass: 'secret' } } }
|
52
|
+
|
53
|
+
it 'should merge' do
|
54
|
+
expect(subject[:creds][:name]).to eql('admin')
|
55
|
+
expect(subject[:creds][:pass]).to eql('secret')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'simple value' do
|
60
|
+
let(:secondary_hash) { { database: 'postgres://localhost/test_db' } }
|
61
|
+
|
62
|
+
it 'should rewrite' do
|
63
|
+
expect(subject[:database]).to eql('postgres://localhost/test_db')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequoia::Store, '#[]' do
|
4
|
+
let(:instance) { described_class.new(hash) }
|
5
|
+
let(:hash) {
|
6
|
+
{
|
7
|
+
working_folder: '/srv',
|
8
|
+
database: { name: 'test_db' }
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
it 'should read keys' do
|
13
|
+
expect(instance[:working_folder]).to eql('/srv')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should should store nested hashes' do
|
17
|
+
expect(instance[:database]).to be_a(Hash)
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequoia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Savchenko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.3'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: thor
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - '>='
|
@@ -53,20 +53,6 @@ dependencies:
|
|
53
53
|
- - '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
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
56
|
- !ruby/object:Gem::Dependency
|
71
57
|
name: simplecov
|
72
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,7 +82,7 @@ files:
|
|
96
82
|
- Gemfile
|
97
83
|
- LICENSE.txt
|
98
84
|
- README.md
|
99
|
-
-
|
85
|
+
- Thorfile
|
100
86
|
- lib/sequoia.rb
|
101
87
|
- lib/sequoia/builder.rb
|
102
88
|
- lib/sequoia/configurable.rb
|
@@ -107,9 +93,18 @@ files:
|
|
107
93
|
- sequoia.gemspec
|
108
94
|
- spec/integration/configurator_spec.rb
|
109
95
|
- spec/spec_helper.rb
|
110
|
-
- spec/unit/
|
111
|
-
- spec/unit/
|
112
|
-
- spec/unit/
|
96
|
+
- spec/unit/sequoia/builder/attrs_spec.rb
|
97
|
+
- spec/unit/sequoia/builder/class_spec.rb
|
98
|
+
- spec/unit/sequoia/builder/respond_to_predicate_spec.rb
|
99
|
+
- spec/unit/sequoia/builder/to_s_spec.rb
|
100
|
+
- spec/unit/sequoia/configurable/build_spec.rb
|
101
|
+
- spec/unit/sequoia/configurable/configure_spec.rb
|
102
|
+
- spec/unit/sequoia/entity/class_methods/create_spec.rb
|
103
|
+
- spec/unit/sequoia/entity/pretty_inspect_spec.rb
|
104
|
+
- spec/unit/sequoia/entity/to_hash_spec.rb
|
105
|
+
- spec/unit/sequoia/entity/to_s_spec.rb
|
106
|
+
- spec/unit/sequoia/store/deep_merge_bang_spec.rb
|
107
|
+
- spec/unit/sequoia/store/element_reader_spec.rb
|
113
108
|
homepage: https://github.com/Ptico/sequoia
|
114
109
|
licenses:
|
115
110
|
- MIT
|
@@ -122,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
117
|
requirements:
|
123
118
|
- - '>='
|
124
119
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
120
|
+
version: 1.9.2
|
126
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
122
|
requirements:
|
128
123
|
- - '>='
|
@@ -130,13 +125,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
125
|
version: '0'
|
131
126
|
requirements: []
|
132
127
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.0.
|
128
|
+
rubygems_version: 2.0.14
|
134
129
|
signing_key:
|
135
130
|
specification_version: 4
|
136
131
|
summary: Gem for building data structures
|
137
132
|
test_files:
|
138
133
|
- spec/integration/configurator_spec.rb
|
139
134
|
- spec/spec_helper.rb
|
140
|
-
- spec/unit/
|
141
|
-
- spec/unit/
|
142
|
-
- spec/unit/
|
135
|
+
- spec/unit/sequoia/builder/attrs_spec.rb
|
136
|
+
- spec/unit/sequoia/builder/class_spec.rb
|
137
|
+
- spec/unit/sequoia/builder/respond_to_predicate_spec.rb
|
138
|
+
- spec/unit/sequoia/builder/to_s_spec.rb
|
139
|
+
- spec/unit/sequoia/configurable/build_spec.rb
|
140
|
+
- spec/unit/sequoia/configurable/configure_spec.rb
|
141
|
+
- spec/unit/sequoia/entity/class_methods/create_spec.rb
|
142
|
+
- spec/unit/sequoia/entity/pretty_inspect_spec.rb
|
143
|
+
- spec/unit/sequoia/entity/to_hash_spec.rb
|
144
|
+
- spec/unit/sequoia/entity/to_s_spec.rb
|
145
|
+
- spec/unit/sequoia/store/deep_merge_bang_spec.rb
|
146
|
+
- spec/unit/sequoia/store/element_reader_spec.rb
|
147
|
+
has_rdoc:
|
data/Rakefile
DELETED
@@ -1,20 +0,0 @@
|
|
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
|
data/spec/unit/builder_spec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
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
|
data/spec/unit/entity_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
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
|
data/spec/unit/store_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
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
|