From 3d626853f759704f45005159954524391c7b8500 Mon Sep 17 00:00:00 2001 From: Rafael George Date: Thu, 15 Aug 2013 17:00:08 -0400 Subject: [PATCH] Remove feature envy smell from ROM::Mapping#build_relation --- config/reek.yml | 2 -- lib/rom/mapping.rb | 3 +-- lib/rom/relation.rb | 12 ++++++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config/reek.yml b/config/reek.yml index 748cb66..75dcf2a 100644 --- a/config/reek.yml +++ b/config/reek.yml @@ -20,8 +20,6 @@ DuplicateMethodCall: max_calls: 1 FeatureEnvy: enabled: true - exclude: - - 'ROM::Mapping#build_relation' IrresponsibleModule: enabled: true exclude: [] diff --git a/lib/rom/mapping.rb b/lib/rom/mapping.rb index ccf9b82..ab74f62 100644 --- a/lib/rom/mapping.rb +++ b/lib/rom/mapping.rb @@ -72,8 +72,7 @@ def method_missing(name, *, &block) # # @api private def build_relation(relation, &block) - definition = Definition.build(relation.header, &block) - environment[relation.name] = Relation.build(relation, definition.mapper) + environment[relation.name] = Relation.build_from(relation, &block) end end # Mapping diff --git a/lib/rom/relation.rb b/lib/rom/relation.rb index a9f2f5b..16b24df 100644 --- a/lib/rom/relation.rb +++ b/lib/rom/relation.rb @@ -58,6 +58,18 @@ def self.build(relation, mapper) new(mapper.call(relation), mapper) end + # Build a new relation from a given relation + # + # @param [Axiom::Relation] + # + # @return [Relation] + # + # @api publi + def self.build_from(relation, &block) + definition = Mapping::Definition.build(relation.header, &block) + Relation.build(relation, definition.mapper) + end + # Iterate over tuples yielded by the wrapped relation # # @example