alf-core 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +77 -0
- data/examples/operators/page.alf +4 -0
- data/lib/alf-adapter-fs/alf/adapter/folder.rb +4 -0
- data/lib/alf-adapter-fs/alf/adapter/folder/connection.rb +3 -2
- data/lib/alf-adapter/alf/adapter/connection.rb +1 -1
- data/lib/alf-algebra/alf/algebra/operand.rb +2 -2
- data/lib/alf-algebra/alf/algebra/operand/fake.rb +3 -3
- data/lib/alf-algebra/alf/algebra/operand/named.rb +1 -1
- data/lib/alf-algebra/alf/algebra/operand/proxy.rb +14 -0
- data/lib/alf-algebra/alf/algebra/operator.rb +4 -1
- data/lib/alf-algebra/alf/algebra/operator/clip.rb +7 -4
- data/lib/alf-algebra/alf/algebra/operator/frame.rb +22 -0
- data/lib/alf-algebra/alf/algebra/operator/hierarchize.rb +22 -0
- data/lib/alf-algebra/alf/algebra/operator/page.rb +22 -0
- data/lib/alf-algebra/alf/algebra/operator/project.rb +4 -9
- data/lib/alf-algebra/alf/algebra/operator/rank.rb +2 -2
- data/lib/alf-algebra/alf/algebra/support.rb +2 -0
- data/lib/alf-algebra/alf/algebra/support/signature.rb +2 -1
- data/lib/alf-algebra/alf/algebra/support/with_ordering.rb +11 -0
- data/lib/alf-core/ext/domain/heading_based.rb +16 -4
- data/lib/alf-core/facade.rb +5 -1
- data/lib/alf-core/version.rb +2 -2
- data/lib/alf-database/alf/database/connection.rb +2 -2
- data/lib/alf-database/alf/database/options.rb +0 -3
- data/lib/alf-engine/alf/engine.rb +4 -1
- data/lib/alf-engine/alf/engine/aggregate.rb +2 -1
- data/lib/alf-engine/alf/engine/autonum.rb +2 -1
- data/lib/alf-engine/alf/engine/clip.rb +2 -1
- data/lib/alf-engine/alf/engine/coerce.rb +2 -1
- data/lib/alf-engine/alf/engine/cog.rb +23 -0
- data/lib/alf-engine/alf/engine/compact.rb +3 -2
- data/lib/alf-engine/alf/engine/compact/set.rb +2 -1
- data/lib/alf-engine/alf/engine/compact/uniq.rb +2 -1
- data/lib/alf-engine/alf/engine/compiler.rb +60 -33
- data/lib/alf-engine/alf/engine/concat.rb +2 -1
- data/lib/alf-engine/alf/engine/defaults.rb +2 -1
- data/lib/alf-engine/alf/engine/filter.rb +4 -2
- data/lib/alf-engine/alf/engine/generator.rb +2 -1
- data/lib/alf-engine/alf/engine/group/hash.rb +4 -3
- data/lib/alf-engine/alf/engine/hierarchize.rb +87 -0
- data/lib/alf-engine/alf/engine/infer_heading.rb +2 -1
- data/lib/alf-engine/alf/engine/join.rb +5 -1
- data/lib/alf-engine/alf/engine/join/hash.rb +9 -2
- data/lib/alf-engine/alf/engine/leaf.rb +6 -1
- data/lib/alf-engine/alf/engine/materialize/array.rb +2 -1
- data/lib/alf-engine/alf/engine/materialize/hash.rb +2 -1
- data/lib/alf-engine/alf/engine/quota/cesure.rb +2 -1
- data/lib/alf-engine/alf/engine/rank/cesure.rb +2 -1
- data/lib/alf-engine/alf/engine/rename.rb +2 -1
- data/lib/alf-engine/alf/engine/semi/hash.rb +7 -1
- data/lib/alf-engine/alf/engine/set_attr.rb +4 -3
- data/lib/alf-engine/alf/engine/sort.rb +3 -2
- data/lib/alf-engine/alf/engine/sort/in_memory.rb +2 -1
- data/lib/alf-engine/alf/engine/summarize/cesure.rb +2 -1
- data/lib/alf-engine/alf/engine/summarize/hash.rb +3 -2
- data/lib/alf-engine/alf/engine/{cesure.rb → support/cesure.rb} +0 -0
- data/lib/alf-engine/alf/engine/take.rb +53 -0
- data/lib/alf-engine/alf/engine/to_array.rb +6 -5
- data/lib/alf-engine/alf/engine/type_safe.rb +2 -1
- data/lib/alf-engine/alf/engine/ungroup.rb +2 -1
- data/lib/alf-engine/alf/engine/unwrap.rb +2 -1
- data/lib/alf-engine/alf/engine/wrap.rb +2 -1
- data/lib/alf-io/alf/reader.rb +1 -1
- data/lib/alf-io/alf/reader/ruby.rb +23 -0
- data/lib/alf-io/alf/renderer/text.rb +22 -9
- data/lib/alf-lang/alf/lang/lispy.rb +41 -29
- data/lib/alf-lang/alf/lang/oo/algebra_methods.rb +17 -1
- data/lib/alf-optimizer/alf/optimizer/restrict.rb +7 -1
- data/lib/alf-predicate/alf/predicate.rb +11 -2
- data/lib/alf-relation/alf/relation.rb +21 -1
- data/lib/alf-relvar/alf/relvar.rb +21 -1
- data/lib/alf-relvar/alf/relvar/base.rb +11 -6
- data/lib/alf-relvar/alf/relvar/fake.rb +3 -2
- data/lib/alf-relvar/alf/relvar/virtual.rb +1 -2
- data/lib/alf-support/alf/support/bindable.rb +1 -1
- data/lib/alf-support/alf/support/config.rb +91 -18
- data/lib/alf-support/alf/support/tuple_scope.rb +8 -4
- data/lib/alf-types/alf/types.rb +2 -0
- data/lib/alf-types/alf/types/attr_list.rb +3 -1
- data/lib/alf-types/alf/types/heading.rb +4 -1
- data/lib/alf-types/alf/types/keys.rb +0 -4
- data/lib/alf-types/alf/types/ordering.rb +104 -18
- data/lib/alf-types/alf/types/selection.rb +18 -0
- data/lib/alf-types/alf/types/selector.rb +59 -0
- data/lib/alf-types/alf/types/tuple_computation.rb +2 -2
- data/lib/alf-types/alf/types/tuple_expression.rb +18 -2
- data/lib/alf-viewpoint/alf/viewpoint.rb +23 -8
- data/lib/alf-viewpoint/alf/viewpoint/metadata.rb +73 -0
- data/spec/integration/relation/test_extend.rb +20 -0
- data/spec/integration/relation/test_to_array.rb +1 -1
- data/spec/integration/test_examples.rb +18 -2
- data/spec/shared/a_cog.rb +36 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/unit/alf-algebra/operand/test_proxy.rb +54 -0
- data/spec/unit/alf-algebra/operator/hierarchize/test_heading.rb +23 -0
- data/spec/unit/alf-algebra/operator/project/test_key_preserving.rb +3 -0
- data/spec/unit/alf-algebra/operator/project/test_keys.rb +54 -17
- data/spec/unit/alf-algebra/operator/rank/test_keys.rb +2 -2
- data/spec/unit/alf-algebra/operator/restrict/test_keys.rb +2 -2
- data/spec/unit/alf-algebra/operator/test_page.rb +30 -0
- data/spec/unit/alf-algebra/support/test_relational.rb +3 -0
- data/spec/unit/alf-algebra/support/with_ordering/test_total_ordering.rb +61 -0
- data/spec/unit/alf-database/connection/test_reconnect.rb +1 -1
- data/spec/unit/alf-database/options/test_new.rb +4 -4
- data/spec/unit/alf-database/shared_examples/a_facade_on_database_options.rb +1 -2
- data/spec/unit/alf-engine/cog/test_to_cog.rb +14 -0
- data/spec/unit/alf-engine/compiler/test_on_frame.rb +70 -0
- data/spec/unit/alf-engine/compiler/test_on_hierarchize.rb +33 -0
- data/spec/unit/alf-engine/compiler/test_on_page.rb +128 -0
- data/spec/unit/alf-engine/compiler/test_unsupported.rb +48 -0
- data/spec/unit/alf-engine/hierarchize/test_renamer.rb +18 -0
- data/spec/unit/alf-engine/test_filter.rb +43 -11
- data/spec/unit/alf-engine/test_hierarchize.rb +71 -0
- data/spec/unit/alf-engine/test_set_attr.rb +13 -0
- data/spec/unit/alf-engine/test_take.rb +46 -0
- data/spec/unit/alf-engine/test_to_array.rb +45 -28
- data/spec/unit/alf-io/reader/{input.rb → input.rash} +0 -0
- data/spec/unit/alf-io/reader/input.ruby +4 -0
- data/spec/unit/alf-io/reader/test_rash.rb +1 -1
- data/spec/unit/alf-io/reader/test_ruby.rb +25 -0
- data/spec/unit/alf-predicate/predicate/test_evaluate.rb +51 -13
- data/spec/unit/alf-relation/relation/class/test_recursive_type.rb +42 -0
- data/spec/unit/alf-relation/relation/test_equality.rb +19 -1
- data/spec/unit/alf-relation/relation/test_relops.rb +14 -2
- data/spec/unit/alf-relation/relation/test_to_hash.rb +31 -0
- data/spec/unit/alf-relvar/base/test_connection.rb +8 -2
- data/spec/unit/alf-relvar/base/test_delete.rb +2 -2
- data/spec/unit/alf-relvar/base/test_heading.rb +2 -2
- data/spec/unit/alf-relvar/base/test_insert.rb +3 -3
- data/spec/unit/alf-relvar/base/test_keys.rb +2 -2
- data/spec/unit/alf-relvar/base/test_lock.rb +2 -2
- data/spec/unit/alf-relvar/base/test_name.rb +3 -2
- data/spec/unit/alf-relvar/base/test_oo_lang.rb +2 -1
- data/spec/unit/alf-relvar/base/test_to_cog.rb +3 -3
- data/spec/unit/alf-relvar/base/test_to_lispy.rb +3 -2
- data/spec/unit/alf-relvar/base/test_to_relvar.rb +2 -1
- data/spec/unit/alf-relvar/base/test_to_s.rb +3 -2
- data/spec/unit/alf-relvar/base/test_update.rb +5 -4
- data/spec/unit/alf-relvar/virtual/test_connection.rb +3 -2
- data/spec/unit/alf-relvar/virtual/test_delete.rb +3 -4
- data/spec/unit/alf-relvar/virtual/test_expr.rb +3 -2
- data/spec/unit/alf-relvar/virtual/test_heading.rb +5 -4
- data/spec/unit/alf-relvar/virtual/test_insert.rb +2 -2
- data/spec/unit/alf-relvar/virtual/test_keys.rb +5 -4
- data/spec/unit/alf-relvar/virtual/test_oo_lang.rb +7 -2
- data/spec/unit/alf-relvar/virtual/test_to_cog.rb +4 -3
- data/spec/unit/alf-relvar/virtual/test_to_lispy.rb +3 -6
- data/spec/unit/alf-relvar/virtual/test_to_relvar.rb +2 -1
- data/spec/unit/alf-relvar/virtual/test_to_s.rb +3 -3
- data/spec/unit/alf-relvar/virtual/test_update.rb +4 -5
- data/spec/unit/alf-support/config/test_dup.rb +58 -0
- data/spec/unit/alf-support/config/test_freeze.rb +37 -0
- data/spec/unit/alf-support/config/test_hash_get.rb +41 -0
- data/spec/unit/alf-support/config/test_hash_set.rb +61 -0
- data/spec/unit/alf-support/config/test_new.rb +10 -0
- data/spec/unit/alf-support/config/test_option.rb +15 -0
- data/spec/unit/alf-support/config/test_option_setter.rb +72 -0
- data/spec/unit/alf-support/config/test_options.rb +22 -0
- data/spec/unit/alf-support/tuple_scope/test_hash_get.rb +20 -0
- data/spec/unit/alf-support/tuple_scope/test_respond_to.rb +6 -0
- data/spec/unit/alf-support/tuple_scope/test_to_s.rb +22 -0
- data/spec/unit/alf-types/keys/test_select.rb +57 -8
- data/spec/unit/alf-types/ordering/test_coerce.rb +46 -35
- data/spec/unit/alf-types/ordering/test_dive.rb +41 -0
- data/spec/unit/alf-types/ordering/test_hash_get.rb +20 -0
- data/spec/unit/alf-types/ordering/test_merge.rb +61 -0
- data/spec/unit/alf-types/ordering/test_reverse.rb +40 -0
- data/spec/unit/alf-types/ordering/test_selectors.rb +24 -0
- data/spec/unit/alf-types/ordering/test_sorter.rb +62 -8
- data/spec/unit/alf-types/ordering/test_to_attr_list.rb +16 -4
- data/spec/unit/alf-types/ordering/test_total.rb +56 -0
- data/spec/unit/alf-types/selection/test_coerce.rb +38 -0
- data/spec/unit/alf-types/selection/test_select.rb +34 -0
- data/spec/unit/alf-types/selector/test_coerce.rb +36 -0
- data/spec/unit/alf-types/selector/test_composite_q.rb +20 -0
- data/spec/unit/alf-types/selector/test_dive.rb +32 -0
- data/spec/unit/alf-types/selector/test_select.rb +40 -0
- data/spec/unit/alf-types/selector/test_simple_q.rb +20 -0
- data/spec/unit/alf-types/selector/test_to_a.rb +20 -0
- data/spec/unit/alf-types/selector/test_to_lispy.rb +20 -0
- data/spec/unit/alf-types/selector/test_to_ruby_literal.rb +20 -0
- data/spec/unit/alf-types/tuple_expression/test_evaluate.rb +38 -0
- data/spec/unit/alf-viewpoint/metadata/test_add_members.rb +38 -0
- data/spec/unit/alf-viewpoint/metadata/test_all_members.rb +33 -0
- data/spec/unit/alf-viewpoint/metadata/test_depends.rb +50 -0
- data/spec/unit/alf-viewpoint/metadata/test_dup.rb +32 -0
- data/spec/unit/alf-viewpoint/metadata/test_expand.rb +31 -0
- data/spec/unit/alf-viewpoint/metadata/test_expects.rb +38 -0
- data/spec/unit/alf-viewpoint/metadata/test_initialize.rb +40 -0
- data/spec/unit/alf-viewpoint/metadata/test_to_module.rb +37 -0
- data/spec/unit/alf-viewpoint/test_depends.rb +18 -0
- data/spec/unit/alf-viewpoint/test_expects.rb +18 -0
- data/spec/unit/alf-viewpoint/test_members.rb +33 -0
- data/spec/unit/alf-viewpoint/test_metadata.rb +27 -0
- data/spec/unit/alf-viewpoint/test_native_const.rb +6 -0
- metadata +125 -14
- data/spec/unit/alf-database/options/test_default_viewpoint.rb +0 -25
- data/spec/unit/alf-types/keys/test_compact.rb +0 -21
- data/spec/unit/alf-types/ordering/test_plus.rb +0 -27
- data/spec/unit/alf-viewpoint/test_namespace.rb +0 -23
@@ -3,15 +3,16 @@ module Alf
|
|
3
3
|
module Relvar
|
4
4
|
describe Virtual, "to_cog" do
|
5
5
|
|
6
|
-
let(:
|
6
|
+
let(:expr){ Algebra::Operand::Named.new(:aname, self) }
|
7
|
+
let(:rv) { Virtual.new(expr) }
|
7
8
|
|
8
9
|
subject{ rv.to_cog }
|
9
10
|
|
10
11
|
def cog(expr)
|
11
|
-
[expr]
|
12
|
+
[:seen, expr]
|
12
13
|
end
|
13
14
|
|
14
|
-
it{ should eq([:expr]) }
|
15
|
+
it{ should eq([:seen, expr]) }
|
15
16
|
|
16
17
|
end
|
17
18
|
end
|
@@ -3,16 +3,13 @@ module Alf
|
|
3
3
|
module Relvar
|
4
4
|
describe Virtual, "to_lispy" do
|
5
5
|
|
6
|
-
let(:
|
7
|
-
|
8
|
-
def to_lispy
|
9
|
-
"a lispy expression"
|
10
|
-
end
|
6
|
+
let(:expr){ Algebra::Operand::Named.new(:aname, self) }
|
7
|
+
let(:rv) { Virtual.new(expr) }
|
11
8
|
|
12
9
|
subject{ rv.to_lispy }
|
13
10
|
|
14
11
|
it 'delegates to the expression' do
|
15
|
-
subject.should eq("
|
12
|
+
subject.should eq("aname")
|
16
13
|
end
|
17
14
|
|
18
15
|
end
|
@@ -3,12 +3,12 @@ module Alf
|
|
3
3
|
module Relvar
|
4
4
|
describe Virtual, "to_s" do
|
5
5
|
|
6
|
-
let(:
|
7
|
-
let(:
|
6
|
+
let(:expr){ Algebra::Operand::Named.new(:aname, self) }
|
7
|
+
let(:rv) { Virtual.new(expr) }
|
8
8
|
|
9
9
|
subject{ rv.to_s }
|
10
10
|
|
11
|
-
it{ should eq("Relvar::Virtual(
|
11
|
+
it{ should eq("Relvar::Virtual(Operand::Named(:aname))") }
|
12
12
|
|
13
13
|
end
|
14
14
|
end
|
@@ -3,11 +3,10 @@ module Alf
|
|
3
3
|
module Relvar
|
4
4
|
describe Virtual, "update" do
|
5
5
|
|
6
|
-
let(:rv) { Virtual.new(expr
|
7
|
-
let(:expr) { Algebra.named_operand(:suppliers,
|
8
|
-
let(:updating) { {sname: 'Jones'}
|
9
|
-
let(:predicate) { Predicate.eq(:sid, 1)
|
10
|
-
let(:connection){ self }
|
6
|
+
let(:rv) { Virtual.new(expr) }
|
7
|
+
let(:expr) { Algebra.named_operand(:suppliers, self) }
|
8
|
+
let(:updating) { {sname: 'Jones'} }
|
9
|
+
let(:predicate) { Predicate.eq(:sid, 1) }
|
11
10
|
|
12
11
|
def update(*args)
|
13
12
|
@seen = args
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Support
|
4
|
+
describe Config, 'dup' do
|
5
|
+
|
6
|
+
let(:conf_subclass){
|
7
|
+
Class.new(Config){
|
8
|
+
option :ready, Boolean, false
|
9
|
+
option :preferences, Array, []
|
10
|
+
option :aproc, Boolean, ->{ !ready? }
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:config){ conf_subclass.new }
|
15
|
+
|
16
|
+
context 'when not freezed' do
|
17
|
+
subject{ config.dup }
|
18
|
+
|
19
|
+
it 'should return a different instance' do
|
20
|
+
subject.should be_a(conf_subclass)
|
21
|
+
subject.should_not be(config)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should dup all options while keeping them equal' do
|
25
|
+
conf_subclass.options.each do |name,_,_|
|
26
|
+
mine, yours = subject[name], config[name]
|
27
|
+
mine.should eq(yours)
|
28
|
+
mine.should_not be(yours) unless Boolean===mine
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should keep the semantics of Proc options' do
|
33
|
+
subject.aproc?.should be_true
|
34
|
+
subject.ready = true
|
35
|
+
subject.aproc?.should be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when frozen' do
|
40
|
+
subject{ config.freeze.dup }
|
41
|
+
|
42
|
+
it 'should return a non-frezed instance' do
|
43
|
+
subject.should be_a(conf_subclass)
|
44
|
+
subject.should_not be_frozen
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'allow modifying options on the new instance' do
|
48
|
+
lambda{
|
49
|
+
subject.ready = true
|
50
|
+
}.should_not raise_error
|
51
|
+
subject.ready?.should be_true
|
52
|
+
config.ready?.should be_false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Support
|
4
|
+
describe Config, 'freeze' do
|
5
|
+
|
6
|
+
let(:conf_subclass){
|
7
|
+
Class.new(Config){
|
8
|
+
option :ready, Boolean, false
|
9
|
+
option :preferences, Array, []
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:config){ conf_subclass.new }
|
14
|
+
|
15
|
+
subject{ config.freeze }
|
16
|
+
|
17
|
+
it 'should return the instance' do
|
18
|
+
subject.should be(config)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should freeze the scalar options' do
|
22
|
+
subject
|
23
|
+
lambda{
|
24
|
+
config.ready = true
|
25
|
+
}.should raise_error(/can't modify frozen/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should freeze the non-scalar options' do
|
29
|
+
subject
|
30
|
+
lambda{
|
31
|
+
config.preferences << "foo"
|
32
|
+
}.should raise_error(/can't modify frozen/)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Support
|
4
|
+
describe Config, '[]' do
|
5
|
+
|
6
|
+
let(:conf_subclass){
|
7
|
+
Class.new(Config){
|
8
|
+
option :ready, Boolean, false
|
9
|
+
option :preferences, Array, ["foo"]
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:config){ conf_subclass.new }
|
14
|
+
|
15
|
+
subject{ config[attr] }
|
16
|
+
|
17
|
+
context 'on a boolean' do
|
18
|
+
let(:attr){ :ready }
|
19
|
+
|
20
|
+
it{ should eq(false) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'on a non-boolean' do
|
24
|
+
let(:attr){ :preferences }
|
25
|
+
|
26
|
+
it{ should eq(["foo"]) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'after being set' do
|
30
|
+
let(:attr){ :preferences }
|
31
|
+
|
32
|
+
before do
|
33
|
+
config.preferences = ["bar"]
|
34
|
+
end
|
35
|
+
|
36
|
+
it{ should eq(["bar"]) }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Support
|
4
|
+
describe Config, '[]=' do
|
5
|
+
|
6
|
+
let(:conf_subclass){
|
7
|
+
Class.new(Config){
|
8
|
+
option :ready, Boolean, false
|
9
|
+
option :preferences, Array, ["foo"]
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:config){ conf_subclass.new }
|
14
|
+
|
15
|
+
subject{ config[attr] = value }
|
16
|
+
|
17
|
+
context 'on a boolean' do
|
18
|
+
let(:attr){ :ready }
|
19
|
+
let(:value){ true }
|
20
|
+
|
21
|
+
it 'should return the value' do
|
22
|
+
subject.should eq(value)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should set the value' do
|
26
|
+
subject
|
27
|
+
config.ready?.should eq(true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'on a non boolean' do
|
32
|
+
let(:attr){ :preferences }
|
33
|
+
let(:value){ ["bar"] }
|
34
|
+
|
35
|
+
it 'should return the value' do
|
36
|
+
subject.should eq(value)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should set the value' do
|
40
|
+
subject
|
41
|
+
config.preferences.should eq(["bar"])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when used for merging arrays' do
|
46
|
+
let(:attr){ :preferences }
|
47
|
+
let(:value){ ["bar"] }
|
48
|
+
|
49
|
+
subject{
|
50
|
+
config[:preferences] |= value
|
51
|
+
}
|
52
|
+
|
53
|
+
it 'should merge the values' do
|
54
|
+
subject
|
55
|
+
config.preferences.should eq(["foo", "bar"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -39,6 +39,16 @@ module Alf
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
context 'with a block passed' do
|
43
|
+
subject{
|
44
|
+
conf_subclass.new{|c| c.ready = true }
|
45
|
+
}
|
46
|
+
|
47
|
+
it 'yields the block' do
|
48
|
+
subject.ready?.should be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
42
52
|
context 'when nothing is passed' do
|
43
53
|
subject{ conf_subclass.new }
|
44
54
|
|
@@ -6,6 +6,9 @@ module Alf
|
|
6
6
|
let(:conf1){
|
7
7
|
Class.new(Config){
|
8
8
|
option :ready, Boolean, false
|
9
|
+
option :which, String, ->{ "foo" }
|
10
|
+
option :done, Proc, ->{ "bar" }
|
11
|
+
option :cross, String, ->{ which.capitalize }
|
9
12
|
}
|
10
13
|
}
|
11
14
|
|
@@ -22,6 +25,18 @@ module Alf
|
|
22
25
|
conf2.new.should respond_to(:hello)
|
23
26
|
end
|
24
27
|
|
28
|
+
it 'supports procs' do
|
29
|
+
conf1.new.which.should eq("foo")
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'executes proc in that context' do
|
33
|
+
conf1.new.cross.should eq("Foo")
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'does not confuse procs' do
|
37
|
+
conf1.new.done.should be_a(Proc)
|
38
|
+
end
|
39
|
+
|
25
40
|
end
|
26
41
|
end
|
27
42
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Support
|
4
|
+
describe Config, 'option setter' do
|
5
|
+
|
6
|
+
let(:conf_subclass){
|
7
|
+
Class.new(Config){
|
8
|
+
option :ready, Boolean, false
|
9
|
+
option :which, String, ->{ "foo" }
|
10
|
+
option :done, Proc, ->{ "bar" }
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:config){ conf_subclass.new }
|
15
|
+
|
16
|
+
context 'on `ready` with a boolean' do
|
17
|
+
subject{ config.ready = true }
|
18
|
+
|
19
|
+
it 'should return the value' do
|
20
|
+
subject.should eq(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should set the value' do
|
24
|
+
subject
|
25
|
+
config.ready?.should eq(true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'on `ready` with needed coercion' do
|
30
|
+
subject{ config.ready = "true" }
|
31
|
+
|
32
|
+
it 'returns the non-coerced value' do
|
33
|
+
subject.should eq("true")
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should set the value' do
|
37
|
+
subject
|
38
|
+
config.ready?.should eq(true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'on `which` with a string' do
|
43
|
+
subject{ config.which = "blah" }
|
44
|
+
|
45
|
+
it 'should return the value' do
|
46
|
+
subject.should eq("blah")
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should set the value' do
|
50
|
+
subject
|
51
|
+
config.which.should eq("blah")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'on `which` with a Proc' do
|
56
|
+
let(:proc){ ->{ "blah" } }
|
57
|
+
|
58
|
+
subject{ config.which = proc }
|
59
|
+
|
60
|
+
it 'should return the value' do
|
61
|
+
subject.should be(proc)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should call the proc when option is get' do
|
65
|
+
subject
|
66
|
+
config.which.should eq("blah")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Support
|
4
|
+
describe Config, '.options' do
|
5
|
+
|
6
|
+
let(:conf){
|
7
|
+
Class.new(Config){
|
8
|
+
option :ready, Boolean, false
|
9
|
+
option :hello, String, "world"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
it 'should contain the options' do
|
14
|
+
conf.options.should eq([
|
15
|
+
[:ready, Boolean, false],
|
16
|
+
[:hello, String, "world"]
|
17
|
+
])
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Support
|
4
|
+
describe TupleScope, "[]" do
|
5
|
+
|
6
|
+
context 'with a simple TupleScope' do
|
7
|
+
let(:scope){ TupleScope.new(:a => 1, :b => 2) }
|
8
|
+
|
9
|
+
it "delegates to the tuple" do
|
10
|
+
scope[:a].should == 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it "return nil on unexisting" do
|
14
|
+
scope[:c].should be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|