Permalink
Browse files

Add Veritas::Algebra::Rename::Aliases#inverse

  • Loading branch information...
1 parent 71ac8c0 commit 77abd85d1dca041a02e4e4320e05ae4899ac6bb9 @dkubb committed May 14, 2012
@@ -135,6 +135,19 @@ def empty?
@aliases.empty?
end
+ # Return the inverse aliases
+ #
+ # @example
+ # inverse = aliases.inverse
+ #
+ # @return [Aliases]
+ #
+ # @api public
+ def inverse
+ self.class.new(@aliases.invert).
+ memoize(:inverse, self)
+ end
+
# Compare the aliases with other aliases for equivalency
#
# @example
@@ -200,6 +213,8 @@ def self.coerce_alias_pair(attributes, old_attr, new_attr)
private_class_method :coerce_alias_pair
+ memoize :inverse
+
end # class Aliases
end # class Rename
end # module Algebra
@@ -0,0 +1,30 @@
+# encoding: utf-8
+
+require 'spec_helper'
+
+describe Algebra::Rename::Aliases, '#inverse' do
+ subject { object.inverse }
+
+ let(:object) { described_class.new(aliases) }
+ let(:attribute) { Attribute::Integer.new(:id) }
+
+ context 'when aliases are empty' do
+ let(:aliases) { {} }
+
+ it_should_behave_like 'an invertible method'
+
+ it { should be_instance_of(described_class) }
+
+ its(:to_hash) { should == {} }
+ end
+
+ context 'when aliases are not empty' do
+ let(:aliases) { { attribute => attribute.rename(:other_id) } }
+
+ it_should_behave_like 'an invertible method'
+
+ it { should be_instance_of(described_class) }
+
+ its(:to_hash) { should == { attribute.rename(:other_id) => attribute } }
+ end
+end
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Dan Kubb"]
- s.date = "2012-05-10"
+ s.date = "2012-05-14"
s.description = "Simplifies querying of structured data using relational algebra"
s.email = "dan.kubb@gmail.com"
s.extra_rdoc_files = [
@@ -225,6 +225,7 @@ Gem::Specification.new do |s|
"spec/unit/veritas/algebra/rename/aliases/eql_spec.rb",
"spec/unit/veritas/algebra/rename/aliases/equal_value_spec.rb",
"spec/unit/veritas/algebra/rename/aliases/hash_spec.rb",
+ "spec/unit/veritas/algebra/rename/aliases/inverse_spec.rb",
"spec/unit/veritas/algebra/rename/aliases/to_hash_spec.rb",
"spec/unit/veritas/algebra/rename/aliases/union_spec.rb",
"spec/unit/veritas/algebra/rename/aliases_spec.rb",

0 comments on commit 77abd85

Please sign in to comment.