axiom 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -1
- data/.rubocop.yml +7 -0
- data/.travis.yml +10 -7
- data/Gemfile +4 -0
- data/Gemfile.devtools +27 -13
- data/Guardfile +2 -2
- data/README.md +36 -30
- data/TODO +22 -24
- data/axiom.gemspec +9 -9
- data/benchmarks/memory.rb +1 -2
- data/benchmarks/speed.rb +7 -8
- data/config/flay.yml +1 -1
- data/config/reek.yml +19 -7
- data/config/rubocop.yml +6 -9
- data/lib/axiom.rb +28 -13
- data/lib/axiom/aggregate/mean.rb +4 -3
- data/lib/axiom/aggregate/sum.rb +1 -1
- data/lib/axiom/algebra/extension.rb +1 -1
- data/lib/axiom/algebra/join.rb +4 -27
- data/lib/axiom/algebra/product.rb +3 -3
- data/lib/axiom/algebra/projection.rb +2 -2
- data/lib/axiom/algebra/rename.rb +2 -2
- data/lib/axiom/algebra/rename/aliases.rb +3 -3
- data/lib/axiom/algebra/summarization.rb +3 -3
- data/lib/axiom/attribute.rb +5 -4
- data/lib/axiom/attribute/comparable.rb +15 -11
- data/lib/axiom/attribute/date.rb +1 -1
- data/lib/axiom/attribute/date_time.rb +1 -1
- data/lib/axiom/attribute/length_comparable.rb +39 -0
- data/lib/axiom/attribute/numeric.rb +1 -26
- data/lib/axiom/attribute/relation.rb +64 -0
- data/lib/axiom/attribute/string.rb +1 -28
- data/lib/axiom/attribute/time.rb +1 -1
- data/lib/axiom/attribute/tuple.rb +50 -0
- data/lib/axiom/attribute/value_comparable.rb +42 -0
- data/lib/axiom/function.rb +1 -1
- data/lib/axiom/function/binary.rb +4 -16
- data/lib/axiom/function/comparable.rb +1 -1
- data/lib/axiom/function/connective/conjunction.rb +1 -1
- data/lib/axiom/function/connective/disjunction.rb +1 -1
- data/lib/axiom/function/connective/negation.rb +1 -1
- data/lib/axiom/function/numeric/exponentiation.rb +1 -1
- data/lib/axiom/function/numeric/square_root.rb +1 -1
- data/lib/axiom/function/predicate/enumerable.rb +0 -14
- data/lib/axiom/function/predicate/exclusion.rb +1 -1
- data/lib/axiom/function/predicate/inclusion.rb +1 -1
- data/lib/axiom/function/proposition.rb +12 -25
- data/lib/axiom/function/unary.rb +92 -106
- data/lib/axiom/relation.rb +3 -3
- data/lib/axiom/relation/base.rb +15 -0
- data/lib/axiom/relation/header.rb +25 -22
- data/lib/axiom/relation/index.rb +91 -0
- data/lib/axiom/relation/keys.rb +3 -3
- data/lib/axiom/relation/materialized.rb +48 -4
- data/lib/axiom/relation/operation/binary.rb +5 -5
- data/lib/axiom/relation/operation/group.rb +95 -0
- data/lib/axiom/relation/operation/limit.rb +15 -15
- data/lib/axiom/relation/operation/offset.rb +12 -12
- data/lib/axiom/relation/operation/reverse.rb +9 -9
- data/lib/axiom/relation/operation/set.rb +1 -1
- data/lib/axiom/relation/operation/{order.rb → sorted.rb} +29 -28
- data/lib/axiom/relation/operation/{order → sorted}/direction.rb +4 -4
- data/lib/axiom/relation/operation/{order → sorted}/direction_set.rb +3 -3
- data/lib/axiom/relation/operation/ungroup.rb +82 -0
- data/lib/axiom/relation/operation/unwrap.rb +80 -0
- data/lib/axiom/relation/operation/wrap.rb +85 -0
- data/lib/axiom/relation/proxy.rb +5 -6
- data/lib/axiom/relation/variable.rb +1 -2
- data/lib/axiom/support/aliasable.rb +3 -5
- data/lib/axiom/support/equalizer.rb +10 -12
- data/lib/axiom/support/operation/binary.rb +3 -2
- data/lib/axiom/support/operation/unary.rb +1 -1
- data/lib/axiom/tuple.rb +76 -26
- data/lib/axiom/types/relation.rb +13 -0
- data/lib/axiom/types/tuple.rb +13 -0
- data/lib/axiom/version.rb +1 -1
- data/spec/integration/axiom/relation/efficient_enumerable_spec.rb +9 -9
- data/spec/integration/axiom/relation/writable_relations_spec.rb +12 -12
- data/spec/shared/invertible_method_behaviour.rb +1 -1
- data/spec/spec_helper.rb +8 -6
- data/spec/unit/axiom/aggregate/call_spec.rb +7 -12
- data/spec/unit/axiom/aggregate/class_methods/default_spec.rb +7 -2
- data/spec/unit/axiom/aggregate/default_spec.rb +1 -1
- data/spec/unit/axiom/aggregate/finalize_spec.rb +1 -1
- data/spec/unit/axiom/aggregate/maximum/type_spec.rb +2 -6
- data/spec/unit/axiom/aggregate/mean/class_methods/call_spec.rb +2 -2
- data/spec/unit/axiom/aggregate/mean/class_methods/finalize_spec.rb +10 -3
- data/spec/unit/axiom/aggregate/minimum/type_spec.rb +2 -6
- data/spec/unit/axiom/aggregate/sum/default_spec.rb +32 -6
- data/spec/unit/axiom/aggregate/sum/type_spec.rb +2 -6
- data/spec/unit/axiom/aggregate/variance/class_methods/call_spec.rb +6 -6
- data/spec/unit/axiom/algebra/difference/each_spec.rb +3 -3
- data/spec/unit/axiom/algebra/extension/class_methods/new_spec.rb +1 -1
- data/spec/unit/axiom/algebra/extension/each_spec.rb +2 -2
- data/spec/unit/axiom/algebra/intersection/each_spec.rb +3 -3
- data/spec/unit/axiom/algebra/join/each_spec.rb +6 -6
- data/spec/unit/axiom/algebra/product/each_spec.rb +2 -2
- data/spec/unit/axiom/algebra/projection/each_spec.rb +2 -2
- data/spec/unit/axiom/algebra/rename/directions_spec.rb +3 -3
- data/spec/unit/axiom/algebra/rename/each_spec.rb +2 -2
- data/spec/unit/axiom/algebra/restriction/delete_spec.rb +3 -3
- data/spec/unit/axiom/algebra/restriction/each_spec.rb +12 -11
- data/spec/unit/axiom/algebra/restriction/insert_spec.rb +3 -3
- data/spec/unit/axiom/algebra/restriction/methods/restrict_spec.rb +4 -4
- data/spec/unit/axiom/algebra/summarization/each_spec.rb +2 -2
- data/spec/unit/axiom/algebra/summarization/eql_spec.rb +1 -1
- data/spec/unit/axiom/algebra/summarization/summaries/summarize_by_spec.rb +4 -4
- data/spec/unit/axiom/algebra/summarization/summaries/to_hash_spec.rb +2 -2
- data/spec/unit/axiom/algebra/summarization/summary/summarize_by_spec.rb +1 -1
- data/spec/unit/axiom/algebra/union/each_spec.rb +4 -4
- data/spec/unit/axiom/aliasable/fixtures/classes.rb +3 -1
- data/spec/unit/axiom/aliasable/inheritable_alias_spec.rb +18 -27
- data/spec/unit/axiom/attribute/call_spec.rb +1 -1
- data/spec/unit/axiom/attribute/class_methods/coerce_spec.rb +57 -51
- data/spec/unit/axiom/attribute/class_methods/new_spec.rb +1 -1
- data/spec/unit/axiom/attribute/comparable/asc_spec.rb +4 -2
- data/spec/unit/axiom/attribute/comparable/desc_spec.rb +4 -2
- data/spec/unit/axiom/attribute/comparable/range_spec.rb +20 -0
- data/spec/unit/axiom/attribute/eql_spec.rb +1 -1
- data/spec/unit/axiom/attribute/equality_operator_spec.rb +1 -1
- data/spec/unit/axiom/attribute/include_predicate_spec.rb +1 -1
- data/spec/unit/axiom/attribute/name_spec.rb +1 -1
- data/spec/unit/axiom/attribute/optional_predicate_spec.rb +1 -1
- data/spec/unit/axiom/attribute/relation/class_methods/new_spec.rb +56 -0
- data/spec/unit/axiom/attribute/relation/class_methods/type_spec.rb +13 -0
- data/spec/unit/axiom/attribute/relation/header_spec.rb +13 -0
- data/spec/unit/axiom/attribute/relation/new_relation_spec.rb +15 -0
- data/spec/unit/axiom/attribute/rename_spec.rb +1 -1
- data/spec/unit/axiom/attribute/required_predicate_spec.rb +1 -1
- data/spec/unit/axiom/attribute/tuple/class_methods/new_spec.rb +56 -0
- data/spec/unit/axiom/attribute/tuple/class_methods/type_spec.rb +13 -0
- data/spec/unit/axiom/attribute/tuple/header_spec.rb +13 -0
- data/spec/unit/axiom/equalizer/class_method/new_spec.rb +24 -54
- data/spec/unit/axiom/evaluator/context/add_spec.rb +7 -7
- data/spec/unit/axiom/evaluator/context/element_reader_spec.rb +4 -4
- data/spec/unit/axiom/evaluator/context/functions_spec.rb +1 -1
- data/spec/unit/axiom/evaluator/context/method_missing_spec.rb +3 -3
- data/spec/unit/axiom/evaluator/context/respond_to_predicate_spec.rb +3 -3
- data/spec/unit/axiom/evaluator/context/send_spec.rb +8 -8
- data/spec/unit/axiom/function/binary/call_spec.rb +1 -1
- data/spec/unit/axiom/function/binary/type_spec.rb +12 -10
- data/spec/unit/axiom/function/comparable/class_methods/included_spec.rb +2 -2
- data/spec/unit/axiom/function/connective/negation/inverse_spec.rb +1 -1
- data/spec/unit/axiom/function/predicate/call_spec.rb +5 -4
- data/spec/unit/axiom/function/predicate/enumerable/call_spec.rb +12 -2
- data/spec/unit/axiom/function/predicate/eql_spec.rb +4 -3
- data/spec/unit/axiom/function/predicate/equality/methods/eq_spec.rb +5 -1
- data/spec/unit/axiom/function/predicate/exclusion/class_methods/call_spec.rb +37 -8
- data/spec/unit/axiom/function/predicate/exclusion/methods/exclude_spec.rb +6 -2
- data/spec/unit/axiom/function/predicate/greater_than/methods/gt_spec.rb +5 -1
- data/spec/unit/axiom/function/predicate/greater_than_or_equal_to/methods/gte_spec.rb +5 -1
- data/spec/unit/axiom/function/predicate/inclusion/class_methods/call_spec.rb +37 -8
- data/spec/unit/axiom/function/predicate/inclusion/methods/include_spec.rb +6 -2
- data/spec/unit/axiom/function/predicate/inequality/methods/ne_spec.rb +5 -1
- data/spec/unit/axiom/function/predicate/less_than/methods/lt_spec.rb +5 -1
- data/spec/unit/axiom/function/predicate/less_than_or_equal_to/methods/lte_spec.rb +5 -1
- data/spec/unit/axiom/function/predicate/match/methods/match_spec.rb +7 -3
- data/spec/unit/axiom/function/predicate/no_match/methods/no_match_spec.rb +6 -2
- data/spec/unit/axiom/function/proposition/call_spec.rb +6 -4
- data/spec/unit/axiom/function/proposition/class_methods/{new_spec.rb → coerce_spec.rb} +17 -17
- data/spec/unit/axiom/function/proposition/eql_spec.rb +4 -4
- data/spec/unit/axiom/function/proposition/equality_operator_spec.rb +3 -3
- data/spec/unit/axiom/function/proposition/inverse_spec.rb +4 -4
- data/spec/unit/axiom/function/proposition/rename_spec.rb +1 -1
- data/spec/unit/axiom/function/type_spec.rb +1 -1
- data/spec/unit/axiom/function/unary/call_spec.rb +1 -1
- data/spec/unit/axiom/function/unary/callable/call_spec.rb +3 -13
- data/spec/unit/axiom/function/unary/callable/included_spec.rb +2 -2
- data/spec/unit/axiom/function/unary/type_spec.rb +11 -1
- data/spec/unit/axiom/relation/base/eql_spec.rb +1 -1
- data/spec/unit/axiom/relation/base/equality_operator_spec.rb +138 -0
- data/spec/unit/axiom/relation/class_methods/new_spec.rb +7 -7
- data/spec/unit/axiom/relation/directions_spec.rb +2 -2
- data/spec/unit/axiom/relation/each_spec.rb +5 -5
- data/spec/unit/axiom/relation/element_reader_spec.rb +1 -1
- data/spec/unit/axiom/relation/empty/each_spec.rb +1 -1
- data/spec/unit/axiom/relation/empty_predicate_spec.rb +1 -1
- data/spec/unit/axiom/relation/eql_spec.rb +1 -1
- data/spec/unit/axiom/relation/equality_operator_spec.rb +1 -1
- data/spec/unit/axiom/relation/header/class_methods/coerce_spec.rb +2 -2
- data/spec/unit/axiom/relation/header/class_methods/new_spec.rb +3 -3
- data/spec/unit/axiom/relation/header/context_spec.rb +2 -2
- data/spec/unit/axiom/relation/header/each_spec.rb +2 -2
- data/spec/unit/axiom/relation/header/extend_spec.rb +1 -1
- data/spec/unit/axiom/relation/header/{call_spec.rb → fetch_spec.rb} +1 -1
- data/spec/unit/axiom/relation/header/project_spec.rb +1 -1
- data/spec/unit/axiom/relation/header/rename_spec.rb +19 -5
- data/spec/unit/axiom/relation/header/size_spec.rb +14 -0
- data/spec/unit/axiom/relation/header_spec.rb +1 -1
- data/spec/unit/axiom/relation/index/each_spec.rb +33 -0
- data/spec/unit/axiom/relation/index/element_reader_spec.rb +17 -0
- data/spec/unit/axiom/relation/index/left_shift_operator_spec.rb +23 -0
- data/spec/unit/axiom/relation/index/merge_spec.rb +19 -0
- data/spec/unit/axiom/relation/keys/class_methods/coerce_spec.rb +19 -2
- data/spec/unit/axiom/relation/keys/class_methods/new_spec.rb +1 -1
- data/spec/unit/axiom/relation/keys/each_spec.rb +2 -2
- data/spec/unit/axiom/relation/materialize_spec.rb +1 -1
- data/spec/unit/axiom/relation/materialized/class_methods/new_spec.rb +30 -4
- data/spec/unit/axiom/relation/materialized/directions_spec.rb +1 -1
- data/spec/unit/axiom/relation/materialized/materialized_predicate_spec.rb +1 -1
- data/spec/unit/axiom/relation/materialized_predicate_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/binary/class_methods/included_spec.rb +2 -2
- data/spec/unit/axiom/relation/operation/binary/class_methods/new_spec.rb +6 -6
- data/spec/unit/axiom/relation/operation/combination/class_methods/combine_tuples_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/group/each_spec.rb +33 -0
- data/spec/unit/axiom/relation/operation/group/header_spec.rb +22 -0
- data/spec/unit/axiom/relation/operation/group/methods/group_spec.rb +25 -0
- data/spec/unit/axiom/relation/operation/limit/class_methods/new_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/limit/directions_spec.rb +3 -3
- data/spec/unit/axiom/relation/operation/limit/each_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/limit/limit_spec.rb +2 -2
- data/spec/unit/axiom/relation/operation/offset/class_methods/new_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/offset/directions_spec.rb +3 -3
- data/spec/unit/axiom/relation/operation/offset/each_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/offset/offset_spec.rb +2 -2
- data/spec/unit/axiom/relation/operation/reverse/class_methods/new_spec.rb +6 -6
- data/spec/unit/axiom/relation/operation/reverse/directions_spec.rb +3 -3
- data/spec/unit/axiom/relation/operation/reverse/each_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/set/class_methods/included_spec.rb +2 -2
- data/spec/unit/axiom/relation/operation/{order → sorted}/ascending/class_methods/call_spec.rb +22 -1
- data/spec/unit/axiom/relation/operation/sorted/ascending/class_methods/reverse_spec.rb +11 -0
- data/spec/unit/axiom/relation/operation/{order/descending → sorted/ascending}/reverse_spec.rb +2 -2
- data/spec/unit/axiom/relation/operation/{order → sorted}/class_methods/new_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/{order → sorted}/delete_spec.rb +12 -6
- data/spec/unit/axiom/relation/operation/{order → sorted}/descending/class_methods/call_spec.rb +22 -1
- data/spec/unit/axiom/relation/operation/sorted/descending/class_methods/reverse_spec.rb +11 -0
- data/spec/unit/axiom/relation/operation/{order/ascending → sorted/descending}/reverse_spec.rb +2 -2
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction/attribute_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction/call_spec.rb +7 -7
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction/class_methods/coerce_spec.rb +2 -2
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction/eql_predicate_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction/name_spec.rb +4 -4
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction/rename_spec.rb +5 -5
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction/reverse_spec.rb +9 -9
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/attributes_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/class_methods/coerce_spec.rb +3 -3
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/class_methods/new_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/eql_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/equality_operator_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/project_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/rename_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/reverse_spec.rb +2 -2
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/sort_tuples_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/direction_set/to_ary_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/directions_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/each_spec.rb +3 -3
- data/spec/unit/axiom/relation/operation/{order → sorted}/eql_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/header_spec.rb +1 -1
- data/spec/unit/axiom/relation/operation/{order → sorted}/insert_spec.rb +12 -6
- data/spec/unit/axiom/relation/operation/{order → sorted}/methods/sort_by_spec.rb +24 -24
- data/spec/unit/axiom/relation/operation/sorted/methods/sort_spec.rb +19 -0
- data/spec/unit/axiom/relation/operation/ungroup/each_spec.rb +33 -0
- data/spec/unit/axiom/relation/operation/ungroup/header_spec.rb +19 -0
- data/spec/unit/axiom/relation/operation/ungroup/methods/ungroup_spec.rb +21 -0
- data/spec/unit/axiom/relation/operation/unwrap/each_spec.rb +33 -0
- data/spec/unit/axiom/relation/operation/unwrap/header_spec.rb +19 -0
- data/spec/unit/axiom/relation/operation/unwrap/methods/unwrap_spec.rb +21 -0
- data/spec/unit/axiom/relation/operation/wrap/each_spec.rb +33 -0
- data/spec/unit/axiom/relation/operation/wrap/header_spec.rb +22 -0
- data/spec/unit/axiom/relation/operation/wrap/methods/wrap_spec.rb +25 -0
- data/spec/unit/axiom/relation/proxy/each_spec.rb +2 -2
- data/spec/unit/axiom/relation/proxy/respond_to_predicate_spec.rb +48 -12
- data/spec/unit/axiom/relation/replace_spec.rb +8 -8
- data/spec/unit/axiom/tuple/class_methods/coerce_spec.rb +7 -1
- data/spec/unit/axiom/tuple/{call_spec.rb → fetch_spec.rb} +1 -1
- data/spec/unit/axiom/tuple/inspect_spec.rb +14 -0
- data/spec/unit/axiom/tuple/rename_spec.rb +17 -0
- data/spec/unit/axiom/tuple/size_spec.rb +14 -0
- data/spec/unit/axiom/tuple/to_ary_spec.rb +22 -5
- data/spec/unit/axiom/tuple/to_hash_spec.rb +14 -0
- data/spec/unit/axiom/types/relation/class_methods/primitive_spec.rb +13 -0
- data/spec/unit/axiom/types/tuple/class_methods/primitive_spec.rb +13 -0
- data/spec/unit/axiom/visitable/accept_spec.rb +1 -1
- data/spec/unit/date/pred_spec.rb +1 -1
- data/spec/unit/time/pred_spec.rb +1 -1
- metadata +631 -107
- data/spec/unit/axiom/aggregate/hash_spec.rb +0 -15
- data/spec/unit/axiom/algebra/extension/hash_spec.rb +0 -15
- data/spec/unit/axiom/algebra/projection/hash_spec.rb +0 -16
- data/spec/unit/axiom/algebra/rename/aliases/hash_spec.rb +0 -15
- data/spec/unit/axiom/algebra/rename/hash_spec.rb +0 -15
- data/spec/unit/axiom/algebra/restriction/hash_spec.rb +0 -15
- data/spec/unit/axiom/algebra/summarization/hash_spec.rb +0 -16
- data/spec/unit/axiom/attribute/hash_spec.rb +0 -21
- data/spec/unit/axiom/attribute/numeric/hash_spec.rb +0 -17
- data/spec/unit/axiom/attribute/string/hash_spec.rb +0 -25
- data/spec/unit/axiom/equalizer/methods/eql_spec.rb +0 -49
- data/spec/unit/axiom/equalizer/methods/equality_operator_spec.rb +0 -85
- data/spec/unit/axiom/function/binary/invertible/class_methods/included_spec.rb +0 -29
- data/spec/unit/axiom/function/predicate/hash_spec.rb +0 -16
- data/spec/unit/axiom/function/predicate/inverse_spec.rb +0 -17
- data/spec/unit/axiom/function/proposition/hash_spec.rb +0 -14
- data/spec/unit/axiom/function/unary/hash_spec.rb +0 -18
- data/spec/unit/axiom/function/unary/invertible/class_methods/included_spec.rb +0 -29
- data/spec/unit/axiom/operation/binary/hash_spec.rb +0 -16
- data/spec/unit/axiom/operation/unary/hash_spec.rb +0 -15
- data/spec/unit/axiom/relation/base/hash_spec.rb +0 -16
- data/spec/unit/axiom/relation/hash_spec.rb +0 -19
- data/spec/unit/axiom/relation/header/hash_spec.rb +0 -15
- data/spec/unit/axiom/relation/operation/limit/hash_spec.rb +0 -16
- data/spec/unit/axiom/relation/operation/offset/hash_spec.rb +0 -16
- data/spec/unit/axiom/relation/operation/order/ascending/class_methods/reverse_spec.rb +0 -11
- data/spec/unit/axiom/relation/operation/order/descending/class_methods/reverse_spec.rb +0 -11
- data/spec/unit/axiom/relation/operation/order/direction/hash_spec.rb +0 -15
- data/spec/unit/axiom/relation/operation/order/direction_set/hash_spec.rb +0 -15
- data/spec/unit/axiom/relation/operation/order/hash_spec.rb +0 -15
- data/spec/unit/axiom/relation/operation/order/methods/sort_spec.rb +0 -19
- data/spec/unit/axiom/relation/proxy/hash_spec.rb +0 -26
- data/spec/unit/axiom/relation/proxy/method_missing_spec.rb +0 -24
- data/spec/unit/axiom/tuple/hash_spec.rb +0 -15
data/lib/axiom/relation/proxy.rb
CHANGED
@@ -7,10 +7,10 @@ module Axiom
|
|
7
7
|
module Proxy
|
8
8
|
include Equalizer.new(:relation)
|
9
9
|
|
10
|
-
# Relation methods to proxy
|
11
|
-
ENUMERABLE_METHODS = Enumerable.public_instance_methods.map(&:to_s).freeze
|
12
10
|
PROXY_METHODS = %w[header each empty? materialized?].freeze
|
13
|
-
|
11
|
+
ENUMERABLE_METHODS = Enumerable.public_instance_methods.map(&:to_s).freeze
|
12
|
+
RELATION_METHODS = Relation.public_instance_methods.map(&:to_s).freeze
|
13
|
+
REMOVE_METHODS = PROXY_METHODS | (ENUMERABLE_METHODS - RELATION_METHODS)
|
14
14
|
|
15
15
|
# Hook called when module is included
|
16
16
|
#
|
@@ -21,9 +21,8 @@ module Axiom
|
|
21
21
|
#
|
22
22
|
# @api private
|
23
23
|
def self.included(descendant)
|
24
|
-
|
25
|
-
|
26
|
-
end
|
24
|
+
super
|
25
|
+
descendant.class_eval { undef_method(*REMOVE_METHODS) }
|
27
26
|
end
|
28
27
|
|
29
28
|
private_class_method :included
|
@@ -99,8 +99,6 @@ module Axiom
|
|
99
99
|
# A materialized relation variable
|
100
100
|
class Materialized < self
|
101
101
|
|
102
|
-
private
|
103
|
-
|
104
102
|
# Mutate and materialize the relation variable
|
105
103
|
#
|
106
104
|
# @return [undefined]
|
@@ -110,6 +108,7 @@ module Axiom
|
|
110
108
|
super
|
111
109
|
@relation = relation.materialize
|
112
110
|
end
|
111
|
+
private :mutate_relation
|
113
112
|
|
114
113
|
end # class Materialized
|
115
114
|
end # class Variable
|
@@ -33,11 +33,9 @@ module Axiom
|
|
33
33
|
#
|
34
34
|
# @api private
|
35
35
|
def define_inheritable_alias_method(new_method, original_method)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end # end
|
40
|
-
RUBY
|
36
|
+
define_method(new_method) do |*args, &block|
|
37
|
+
public_send(original_method, *args, &block)
|
38
|
+
end
|
41
39
|
end
|
42
40
|
|
43
41
|
end # module Aliasable
|
@@ -5,25 +5,23 @@ module Axiom
|
|
5
5
|
# Define equality, equivalence and inspection methods
|
6
6
|
class Equalizer < ::Equalizer
|
7
7
|
|
8
|
-
#
|
8
|
+
# Hook called when module is included
|
9
9
|
#
|
10
|
-
# @
|
10
|
+
# @param [Module] descendant
|
11
|
+
# the module or class including Equalizer
|
11
12
|
#
|
12
|
-
# @
|
13
|
+
# @return [self]
|
13
14
|
#
|
14
|
-
#
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
include_comparison_methods
|
19
|
-
|
20
|
-
module_eval do
|
15
|
+
# @api private
|
16
|
+
def included(descendant)
|
17
|
+
super
|
18
|
+
descendant.module_eval do
|
21
19
|
include Adamantium
|
22
20
|
memoize :hash
|
23
21
|
end
|
24
|
-
|
25
|
-
freeze
|
26
22
|
end
|
27
23
|
|
24
|
+
private :included
|
25
|
+
|
28
26
|
end # class Equalizer
|
29
27
|
end # module Axiom
|
@@ -36,8 +36,9 @@ module Axiom
|
|
36
36
|
#
|
37
37
|
# @api private
|
38
38
|
def initialize(left, right)
|
39
|
-
|
40
|
-
@
|
39
|
+
freezer = self.class.freezer
|
40
|
+
@left = freezer.call(left)
|
41
|
+
@right = freezer.call(right)
|
41
42
|
end
|
42
43
|
|
43
44
|
end # module Binary
|
data/lib/axiom/tuple.rb
CHANGED
@@ -7,7 +7,7 @@ module Axiom
|
|
7
7
|
extend Aliasable
|
8
8
|
include Equalizer.new(:data)
|
9
9
|
|
10
|
-
inheritable_alias(:[] => :
|
10
|
+
inheritable_alias(:[] => :fetch)
|
11
11
|
|
12
12
|
# The tuple header
|
13
13
|
#
|
@@ -23,6 +23,16 @@ module Axiom
|
|
23
23
|
# @api private
|
24
24
|
attr_reader :data
|
25
25
|
|
26
|
+
# Convert the Tuple into an Array
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# array = tuple.to_ary
|
30
|
+
#
|
31
|
+
# @return [Array]
|
32
|
+
#
|
33
|
+
# @api public
|
34
|
+
attr_reader :to_ary
|
35
|
+
|
26
36
|
# Initialize a Tuple
|
27
37
|
#
|
28
38
|
# @param [Header] header
|
@@ -35,7 +45,8 @@ module Axiom
|
|
35
45
|
# @api private
|
36
46
|
def initialize(header, data)
|
37
47
|
@header = header
|
38
|
-
@
|
48
|
+
@to_ary = self.class.freezer.call(data)
|
49
|
+
@data = Hash[header.zip(@to_ary)]
|
39
50
|
end
|
40
51
|
|
41
52
|
# Lookup a value in the tuple given an attribute
|
@@ -48,8 +59,8 @@ module Axiom
|
|
48
59
|
# @return [Object]
|
49
60
|
#
|
50
61
|
# @api public
|
51
|
-
def
|
52
|
-
data.fetch(header.
|
62
|
+
def fetch(attribute)
|
63
|
+
data.fetch(header.fetch(attribute))
|
53
64
|
end
|
54
65
|
|
55
66
|
# Return a tuple with only the specified attributes
|
@@ -67,41 +78,55 @@ module Axiom
|
|
67
78
|
self.class.new(header, data.values_at(*header))
|
68
79
|
end
|
69
80
|
|
70
|
-
#
|
81
|
+
# Extend a tuple with function results
|
71
82
|
#
|
72
83
|
# @example
|
73
|
-
# new_tuple = tuple.
|
84
|
+
# new_tuple = tuple.extend(header, [func1, func2])
|
74
85
|
#
|
75
86
|
# @param [Header] header
|
76
87
|
# the attributes to include in the tuple
|
77
|
-
# @param [Array]
|
78
|
-
# the
|
88
|
+
# @param [Array<Object>] extensions
|
89
|
+
# the functions to extend the tuple with
|
79
90
|
#
|
80
91
|
# @return [Tuple]
|
81
92
|
#
|
82
93
|
# @api public
|
83
|
-
def
|
84
|
-
|
94
|
+
def extend(header, extensions)
|
95
|
+
join(
|
96
|
+
header,
|
97
|
+
extensions.map { |extension| Function.extract_value(extension, self) }
|
98
|
+
)
|
85
99
|
end
|
86
100
|
|
87
|
-
#
|
101
|
+
# Rename a tuple to use a new header
|
88
102
|
#
|
89
103
|
# @example
|
90
|
-
# new_tuple = tuple.
|
104
|
+
# new_tuple = tuple.rename(header)
|
105
|
+
#
|
106
|
+
# @param [Header] header
|
107
|
+
#
|
108
|
+
# @return [Tuple]
|
109
|
+
#
|
110
|
+
# @api public
|
111
|
+
def rename(header)
|
112
|
+
self.class.new(header, to_ary)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Append values to the tuple and return a new tuple
|
116
|
+
#
|
117
|
+
# @example
|
118
|
+
# new_tuple = tuple.join(header, [1, 2, 3])
|
91
119
|
#
|
92
120
|
# @param [Header] header
|
93
121
|
# the attributes to include in the tuple
|
94
|
-
# @param [Array
|
95
|
-
# the
|
122
|
+
# @param [Array] values
|
123
|
+
# the values to append
|
96
124
|
#
|
97
125
|
# @return [Tuple]
|
98
126
|
#
|
99
127
|
# @api public
|
100
|
-
def
|
101
|
-
|
102
|
-
header,
|
103
|
-
extensions.map { |extension| Function.extract_value(extension, self) }
|
104
|
-
)
|
128
|
+
def join(header, values)
|
129
|
+
self.class.new(header, to_ary + values)
|
105
130
|
end
|
106
131
|
|
107
132
|
# Return the predicate matching the tuple
|
@@ -115,16 +140,37 @@ module Axiom
|
|
115
140
|
end
|
116
141
|
end
|
117
142
|
|
118
|
-
#
|
143
|
+
# Coerce the tuple into a Hash
|
119
144
|
#
|
120
145
|
# @example
|
121
|
-
#
|
146
|
+
# tuple.to_hash # => data as a Hash
|
122
147
|
#
|
123
|
-
# @return [
|
148
|
+
# @return [Hash{Symbol => Object}]
|
149
|
+
#
|
150
|
+
# @api public
|
151
|
+
def to_hash
|
152
|
+
Hash[data.map { |attribute, value| [attribute.name, value] }]
|
153
|
+
end
|
154
|
+
|
155
|
+
# The number of attributes
|
156
|
+
#
|
157
|
+
# @return [Integer]
|
124
158
|
#
|
125
159
|
# @api public
|
126
|
-
def
|
127
|
-
|
160
|
+
def size
|
161
|
+
header.size
|
162
|
+
end
|
163
|
+
|
164
|
+
# Display the tuple data in a human readable form
|
165
|
+
#
|
166
|
+
# @example
|
167
|
+
# tuple.inspect # => data as a String
|
168
|
+
#
|
169
|
+
# @return [String]
|
170
|
+
#
|
171
|
+
# @api public
|
172
|
+
def inspect
|
173
|
+
to_hash.inspect
|
128
174
|
end
|
129
175
|
|
130
176
|
private
|
@@ -152,10 +198,14 @@ module Axiom
|
|
152
198
|
#
|
153
199
|
# @api private
|
154
200
|
def self.coerce(header, object)
|
155
|
-
object.kind_of?(Tuple)
|
201
|
+
if object.kind_of?(Tuple) || header.size != object.to_ary.size
|
202
|
+
object
|
203
|
+
else
|
204
|
+
new(header, object)
|
205
|
+
end
|
156
206
|
end
|
157
207
|
|
158
|
-
memoize :predicate, :
|
208
|
+
memoize :predicate, :to_hash, :inspect
|
159
209
|
|
160
210
|
end # class Tuple
|
161
211
|
end # module Axiom
|
data/lib/axiom/version.rb
CHANGED
@@ -26,17 +26,17 @@ describe Relation do
|
|
26
26
|
|
27
27
|
it '#project should be efficient' do
|
28
28
|
projected = relation.project([:id])
|
29
|
-
sample(projected).
|
29
|
+
expect(sample(projected)).to eq([[0], [1], [2], [3], [4]])
|
30
30
|
end
|
31
31
|
|
32
32
|
it '#restrict should be efficient' do
|
33
33
|
restricted = relation.restrict { |r| r.id.gt(5) }
|
34
|
-
sample(restricted).
|
34
|
+
expect(sample(restricted)).to eq([[6], [7], [8], [9], [10]])
|
35
35
|
end
|
36
36
|
|
37
37
|
it '#rename should be efficient' do
|
38
38
|
renamed = relation.rename(id: :other_id)
|
39
|
-
sample(renamed).
|
39
|
+
expect(sample(renamed)).to eq([[0], [1], [2], [3], [4]])
|
40
40
|
end
|
41
41
|
|
42
42
|
describe '#join should be efficient' do
|
@@ -45,13 +45,13 @@ describe Relation do
|
|
45
45
|
it 'has an infinite left relation' do
|
46
46
|
pending 'Change #join to handle infinite sets'
|
47
47
|
join = other.join(relation)
|
48
|
-
sample(join).
|
48
|
+
expect(sample(join)).to eq([[1, 'Dan Kubb']])
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'has an infinite right relation' do
|
52
52
|
pending 'Change #join to handle infinite sets'
|
53
53
|
join = relation.join(other)
|
54
|
-
sample(join).
|
54
|
+
expect(sample(join)).to eq([[1, 'Dan Kubb']])
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -60,24 +60,24 @@ describe Relation do
|
|
60
60
|
|
61
61
|
it 'has an infinite left relation' do
|
62
62
|
product = relation.product(other)
|
63
|
-
sample(product).
|
63
|
+
expect(sample(product)).to eq([[0, 'Dan Kubb'], [1, 'Dan Kubb'], [2, 'Dan Kubb'], [3, 'Dan Kubb'], [4, 'Dan Kubb']])
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'has an infinite right relation' do
|
67
67
|
pending 'Change #product to handle infinite sets'
|
68
68
|
product = other.product(relation)
|
69
|
-
sample(product).
|
69
|
+
expect(sample(product)).to eq([[0, 'Dan Kubb'], [1, 'Dan Kubb'], [2, 'Dan Kubb'], [3, 'Dan Kubb'], [4, 'Dan Kubb']])
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
it '#difference should be efficient' do
|
74
74
|
difference = relation.difference(Relation.new(relation.header, [[1]]))
|
75
|
-
sample(difference).
|
75
|
+
expect(sample(difference)).to eq([[0], [2], [3], [4], [5]])
|
76
76
|
end
|
77
77
|
|
78
78
|
it '#union should be efficient' do
|
79
79
|
union = relation.union(Relation.new(relation.header, [[1]]))
|
80
|
-
sample(union).
|
80
|
+
expect(sample(union)).to eq([[0], [1], [2], [3], [4]])
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -14,55 +14,55 @@ describe Relation do
|
|
14
14
|
it 'Rename#insert and #delete of a disjoint relation are symmetrical' do
|
15
15
|
rename = relation.rename(id: :other_id)
|
16
16
|
other = [[4, 'John Doe']]
|
17
|
-
rename.insert(other).delete(other).
|
17
|
+
expect(rename.insert(other).delete(other)).to eq(rename)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'Projection#insert and #delete of a disjoint relation are symmetrical' do
|
21
21
|
projection = relation.project([:id])
|
22
22
|
other = [[4]]
|
23
|
-
projection.insert(other).delete(other).
|
23
|
+
expect(projection.insert(other).delete(other)).to eq(projection)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'Extension#insert and #delete of a disjoint relation are symmetrical' do
|
27
27
|
extension = relation.extend { |r| r.add(:age, 30) }
|
28
28
|
other = Relation.new(relation.header, [[4, 'John Doe']]).extend(extension.extensions)
|
29
|
-
extension.insert(other).delete(other).
|
29
|
+
expect(extension.insert(other).delete(other)).to eq(extension)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'Restriction#insert and #delete of a disjoint relation are symmetrical' do
|
33
33
|
restriction = relation.restrict { |r| r.id.gte(1) }
|
34
34
|
other = [[4, 'John Doe']]
|
35
|
-
restriction.insert(other).delete(other).
|
35
|
+
expect(restriction.insert(other).delete(other)).to eq(restriction)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'Join#insert and #delete of a disjoint relation are symmetrical' do
|
39
39
|
join = relation + Relation.new([[:id, Integer]], [[1]])
|
40
40
|
other = [[4, 'John Doe']]
|
41
|
-
join.insert(other).delete(other).
|
41
|
+
expect(join.insert(other).delete(other)).to eq(join)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'Difference#insert and #delete of a disjoint relation are symmetrical' do
|
45
45
|
difference = relation - relation
|
46
46
|
other = [[4, 'John Doe']]
|
47
|
-
difference.insert(other).delete(other).
|
47
|
+
expect(difference.insert(other).delete(other)).to eq(difference)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'Union#insert and #delete of a disjoint relation are symmetrical' do
|
51
51
|
union = relation | relation
|
52
52
|
other = [[4, 'John Doe']]
|
53
|
-
union.insert(other).delete(other).
|
53
|
+
expect(union.insert(other).delete(other)).to eq(union)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'Intersection#insert and #delete of a disjoint relation are symmetrical' do
|
57
57
|
intersection = relation & relation
|
58
58
|
other = [[4, 'John Doe']]
|
59
|
-
intersection.insert(other).delete(other).
|
59
|
+
expect(intersection.insert(other).delete(other)).to eq(intersection)
|
60
60
|
end
|
61
61
|
|
62
|
-
it '
|
63
|
-
|
64
|
-
other
|
65
|
-
|
62
|
+
it 'Sorted#insert and #delete of a disjoint relation are symmetrical' do
|
63
|
+
sorted = relation.sort_by(relation.header)
|
64
|
+
other = Relation.new(relation.header, [[4, 'John Doe']]).sort_by(relation.header)
|
65
|
+
expect(sorted.insert(other).delete(other)).to eq(sorted)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|