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
@@ -0,0 +1,18 @@
|
|
1
|
+
module Alf
|
2
|
+
module Types
|
3
|
+
class Selection
|
4
|
+
extend Domain::Reuse.new(Array)
|
5
|
+
|
6
|
+
coercions do |c|
|
7
|
+
c.coercion(Array){|x,_|
|
8
|
+
Selection.new(x.map{|y| Selector.coerce(y) })
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def select(tuple)
|
13
|
+
reused_instance.map{|s| s.select(tuple) }
|
14
|
+
end
|
15
|
+
|
16
|
+
end # class Selection
|
17
|
+
end # module Types
|
18
|
+
end # module Alf
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Alf
|
2
|
+
module Types
|
3
|
+
class Selector
|
4
|
+
extend Domain::Reuse.new(Object)
|
5
|
+
|
6
|
+
coercions do |c|
|
7
|
+
c.coercion(Symbol){|v,_|
|
8
|
+
Selector.new(AttrName.coerce(v))
|
9
|
+
}
|
10
|
+
c.coercion(String){|v,_|
|
11
|
+
v =~ /\./ ? c.coerce(v.split('.')) : c.coerce(v.to_sym)
|
12
|
+
}
|
13
|
+
c.coercion(Array){|v,_|
|
14
|
+
Selector.new(v.map{|v| AttrName.coerce(v) })
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def simple?
|
19
|
+
reused_instance.is_a?(Symbol)
|
20
|
+
end
|
21
|
+
|
22
|
+
def composite?
|
23
|
+
!simple?
|
24
|
+
end
|
25
|
+
|
26
|
+
def outcoerce
|
27
|
+
reused_instance
|
28
|
+
end
|
29
|
+
|
30
|
+
def select(tuple)
|
31
|
+
return tuple[reused_instance] unless reused_instance.is_a?(Array)
|
32
|
+
reused_instance.inject(tuple){|t,a| t && t[a] }
|
33
|
+
end
|
34
|
+
|
35
|
+
def dive(attr)
|
36
|
+
components = to_a
|
37
|
+
return nil unless (components.first == attr) && components.size > 1
|
38
|
+
rest = components[1..-1]
|
39
|
+
Selector.new(rest.size == 1 ? rest.first : rest)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_a
|
43
|
+
Array(reused_instance)
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_lispy
|
47
|
+
Support.to_ruby_literal(reused_instance)
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_ruby_literal
|
51
|
+
"Alf::Selector[#{Support.to_ruby_literal(reused_instance)}]"
|
52
|
+
end
|
53
|
+
|
54
|
+
alias :to_s :to_ruby_literal
|
55
|
+
alias :inspect :to_ruby_literal
|
56
|
+
|
57
|
+
end # class Selector
|
58
|
+
end # module Types
|
59
|
+
end # module Alf
|
@@ -54,8 +54,8 @@ module Alf
|
|
54
54
|
#
|
55
55
|
# @param [TupleScope] scope a tuple scope instance.
|
56
56
|
# @return [Hash] the resulting tuple
|
57
|
-
def evaluate(scope = nil)
|
58
|
-
hmap{|_,v| v.is_a?(TupleExpression) ? v.evaluate(scope) : v }
|
57
|
+
def evaluate(scope = nil, connection = nil)
|
58
|
+
hmap{|_,v| v.is_a?(TupleExpression) ? v.evaluate(scope, connection) : v }
|
59
59
|
end
|
60
60
|
|
61
61
|
# Returns self
|
@@ -60,8 +60,18 @@ module Alf
|
|
60
60
|
# @param [TupleScope] scope a tuple scope instance.
|
61
61
|
# @return [Object] the result of evaluating the expression in the context
|
62
62
|
# of `scope`
|
63
|
-
def evaluate(scope = nil)
|
64
|
-
|
63
|
+
def evaluate(scope = nil, connection = nil)
|
64
|
+
result = if @expr_lambda.arity == 1
|
65
|
+
@expr_lambda.call(scope)
|
66
|
+
else
|
67
|
+
scope.instance_exec(&@expr_lambda)
|
68
|
+
end
|
69
|
+
if looks_an_expression?(result)
|
70
|
+
result = result.bind(connection) unless result.bound?
|
71
|
+
result.to_relation
|
72
|
+
else
|
73
|
+
result
|
74
|
+
end
|
65
75
|
end
|
66
76
|
|
67
77
|
# Infers the resulting type.
|
@@ -127,6 +137,12 @@ module Alf
|
|
127
137
|
end
|
128
138
|
end
|
129
139
|
|
140
|
+
private
|
141
|
+
|
142
|
+
def looks_an_expression?(y)
|
143
|
+
Algebra::Operand::Named === y || Algebra::Operator === y
|
144
|
+
end
|
145
|
+
|
130
146
|
end # class TupleExpression
|
131
147
|
end # module Types
|
132
148
|
end # module Alf
|
@@ -1,8 +1,27 @@
|
|
1
|
+
require_relative 'viewpoint/metadata'
|
1
2
|
module Alf
|
2
3
|
module Viewpoint
|
3
4
|
|
4
5
|
module ClassMethods
|
5
6
|
|
7
|
+
def metadata
|
8
|
+
@metadata ||= Metadata.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def expects(*viewpoints)
|
12
|
+
metadata.expects(viewpoints)
|
13
|
+
end
|
14
|
+
|
15
|
+
def depends(as, *viewpoints)
|
16
|
+
metadata.depends(as => viewpoints)
|
17
|
+
end
|
18
|
+
|
19
|
+
def build(context = {})
|
20
|
+
x = self
|
21
|
+
metadata.to_module(context){ include(x) }
|
22
|
+
end
|
23
|
+
alias :[] :build
|
24
|
+
|
6
25
|
def parser(connection = nil)
|
7
26
|
Lang::Lispy.new([ self ], connection)
|
8
27
|
end
|
@@ -17,18 +36,14 @@ module Alf
|
|
17
36
|
end
|
18
37
|
end
|
19
38
|
|
20
|
-
def namespace(name, *viewpoints)
|
21
|
-
define_method(name) do
|
22
|
-
Lang::Lispy.new(viewpoints, connection)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
39
|
def members
|
27
|
-
|
40
|
+
metadata.all_members
|
28
41
|
end
|
29
42
|
|
30
43
|
def method_added(m)
|
31
|
-
super.tap{
|
44
|
+
super.tap{
|
45
|
+
metadata.add_members([m]) if public_method_defined?(m)
|
46
|
+
}
|
32
47
|
end
|
33
48
|
end
|
34
49
|
extend ClassMethods
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Alf
|
2
|
+
module Viewpoint
|
3
|
+
class Metadata
|
4
|
+
|
5
|
+
def initialize(expectations = [], dependencies = {}, members = [])
|
6
|
+
@expectations = expectations
|
7
|
+
@dependencies = dependencies
|
8
|
+
@members = members
|
9
|
+
yield(self) if block_given?
|
10
|
+
end
|
11
|
+
attr_reader :expectations, :dependencies, :members
|
12
|
+
|
13
|
+
def expects(viewpoints)
|
14
|
+
@expectations |= viewpoints
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def depends(pairs)
|
19
|
+
@dependencies.merge!(pairs) do |k,v1,v2|
|
20
|
+
v1 == v2 ? v1 : raise("Composition conflict on `#{k}`: #{v1.inspect} vs. #{v2.inspect}")
|
21
|
+
end
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_members(members)
|
26
|
+
@members |= members
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def all_members
|
31
|
+
expand.members
|
32
|
+
end
|
33
|
+
|
34
|
+
def expand
|
35
|
+
Metadata.new do |m|
|
36
|
+
expectations.map{|e| e.metadata.expand }.each do |m2|
|
37
|
+
m.expects(m2.expectations)
|
38
|
+
m.depends(m2.dependencies)
|
39
|
+
m.add_members(m2.members)
|
40
|
+
end
|
41
|
+
m.expects(expectations)
|
42
|
+
m.depends(dependencies)
|
43
|
+
m.add_members(members)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def dup
|
48
|
+
Metadata.new(expectations.dup, dependencies.dup, members.dup)
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_module(context = {}, &bl)
|
52
|
+
expanded = expand
|
53
|
+
Module.new{
|
54
|
+
include Alf::Viewpoint
|
55
|
+
define_method(:contextual_params) do
|
56
|
+
context
|
57
|
+
end
|
58
|
+
expanded.expectations.each do |exp|
|
59
|
+
include(exp)
|
60
|
+
end
|
61
|
+
expanded.dependencies.each_pair do |as, vps|
|
62
|
+
provider = Metadata.new(vps).to_module(context)
|
63
|
+
define_method(as) do
|
64
|
+
Lang::Lispy.new([provider], connection)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
instance_exec(&bl) if bl
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
end # class Metadata
|
72
|
+
end # module Viewpoint
|
73
|
+
end # module Alf
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Alf::Relation, 'extend' do
|
3
|
+
|
4
|
+
let(:rel) {
|
5
|
+
Relation(name: ["Jones", "Smith"])
|
6
|
+
}
|
7
|
+
|
8
|
+
let(:expected){
|
9
|
+
Relation(name: ["JONESfoo", "SMITHfoo"])
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:scoped){
|
13
|
+
"foo"
|
14
|
+
}
|
15
|
+
|
16
|
+
it 'supports procs of arity 1' do
|
17
|
+
rel.extend(foo: ->(t){ t.name.upcase + scoped })
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -6,8 +6,24 @@ Dir["#{File.expand_path('../../../examples', __FILE__)}/**/*.alf"].each do |file
|
|
6
6
|
let(:example_dir) { File.dirname(file) }
|
7
7
|
let(:example_db) { Alf.connect(example_dir) }
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
let(:source){ File.read(example_path) }
|
10
|
+
|
11
|
+
context 'when compiled' do
|
12
|
+
subject{
|
13
|
+
example_db.compile(example_db.parse(source))
|
14
|
+
}
|
15
|
+
|
16
|
+
it_should_behave_like "a traceable cog"
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when queried' do
|
20
|
+
subject{
|
21
|
+
example_db.query(source, example_path)
|
22
|
+
}
|
23
|
+
|
24
|
+
it "should run without error" do
|
25
|
+
subject.should be_a(Relation)
|
26
|
+
end
|
11
27
|
end
|
12
28
|
end
|
13
29
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_examples_for 'a cog' do
|
2
|
+
|
3
|
+
it { should be_a(Alf::Engine::Cog) }
|
4
|
+
|
5
|
+
it 'should return self on to_cog' do
|
6
|
+
subject.to_cog.should be(subject)
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples_for 'a traceable cog' do
|
12
|
+
|
13
|
+
it_should_behave_like "a cog"
|
14
|
+
|
15
|
+
def has_tracking!(compiled)
|
16
|
+
case compiled
|
17
|
+
when Alf::Engine::Leaf
|
18
|
+
compiled.expr.should be_a(Alf::Algebra::Operand)
|
19
|
+
when Alf::Engine::Cog
|
20
|
+
compiled.expr.should be_a(Alf::Algebra::Operand)
|
21
|
+
operands = compiled.respond_to?(:operands) ?
|
22
|
+
compiled.operands :
|
23
|
+
[ compiled.operand ]
|
24
|
+
operands.each do |op|
|
25
|
+
has_tracking!(op)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
raise "Unexpected cog: #{compiled}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should have traceability all way down expression' do
|
33
|
+
has_tracking!(subject)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,7 @@ require 'shared/an_operator_class'
|
|
5
5
|
require 'shared/a_valid_type_implementation'
|
6
6
|
require 'shared/a_value'
|
7
7
|
require 'shared/a_scope'
|
8
|
+
require 'shared/a_cog'
|
8
9
|
|
9
10
|
(Path.dir/"unit").glob("**/shared_examples/*").each do |f|
|
10
11
|
require(f)
|
@@ -54,6 +55,13 @@ module Helpers
|
|
54
55
|
Alf::Algebra::Operand::Fake.new
|
55
56
|
end
|
56
57
|
|
58
|
+
def viewpoint(&bl)
|
59
|
+
Module.new{
|
60
|
+
include Alf::Viewpoint
|
61
|
+
instance_exec(&bl)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
57
65
|
end
|
58
66
|
|
59
67
|
module HelpersInScope
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Algebra
|
4
|
+
module Operand
|
5
|
+
describe Proxy do
|
6
|
+
|
7
|
+
DELEGATED = [ :heading, :keys ]
|
8
|
+
|
9
|
+
subject{
|
10
|
+
Proxy.new(victim).send(method)
|
11
|
+
}
|
12
|
+
|
13
|
+
DELEGATED.each do |method|
|
14
|
+
context "with #{method} with knowing victim" do
|
15
|
+
let(:method){
|
16
|
+
method
|
17
|
+
}
|
18
|
+
let(:victim){
|
19
|
+
Struct.new(method).new("foo")
|
20
|
+
}
|
21
|
+
|
22
|
+
before do
|
23
|
+
victim.should respond_to(method)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should delegate it" do
|
27
|
+
subject.should eq("foo")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with #{method} with knowing victim" do
|
32
|
+
let(:method){
|
33
|
+
method
|
34
|
+
}
|
35
|
+
let(:victim){
|
36
|
+
Object.new
|
37
|
+
}
|
38
|
+
|
39
|
+
before do
|
40
|
+
victim.should_not respond_to(method)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should raise a NotSupportedError" do
|
44
|
+
lambda{
|
45
|
+
subject
|
46
|
+
}.should raise_error(NotSupportedError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Algebra
|
4
|
+
describe Hierarchize, "heading" do
|
5
|
+
|
6
|
+
let(:base){
|
7
|
+
{id: Integer, parent: Integer, city: String}
|
8
|
+
}
|
9
|
+
let(:operand){
|
10
|
+
an_operand.with_heading(base)
|
11
|
+
}
|
12
|
+
let(:op){
|
13
|
+
a_lispy.hierarchize(operand, :id, :parent, :as)
|
14
|
+
}
|
15
|
+
subject{ op.heading }
|
16
|
+
|
17
|
+
it{
|
18
|
+
should eq(Relation.type(base){|r| {:as => r} }.heading)
|
19
|
+
}
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|