From fca41a519bcdc4580d5c0e9aee13d42675561bb8 Mon Sep 17 00:00:00 2001 From: Aaron Lasseigne Date: Tue, 13 Aug 2013 15:37:18 -0500 Subject: [PATCH] adding an i18n_scope instance method for improved readability --- lib/active_interaction/base.rb | 6 +++++- spec/active_interaction/base_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/active_interaction/base.rb b/lib/active_interaction/base.rb index 11fd18c7..48cf7313 100644 --- a/lib/active_interaction/base.rb +++ b/lib/active_interaction/base.rb @@ -48,6 +48,10 @@ def self.i18n_scope :active_interaction end + def i18n_scope + self.class.i18n_scope + end + extend OverloadHash # Returns the output from {#execute} if there are no validation errors or @@ -198,7 +202,7 @@ def self.set_up_validator(attribute, type, filter, options, &block) errors.add(attribute, :invalid_nested) rescue InvalidValue errors.add(attribute, :invalid, - type: I18n.translate(:"#{self.class.i18n_scope}.types.#{type.to_s}") + type: I18n.translate(:"#{i18n_scope}.types.#{type.to_s}") ) rescue MissingValue errors.add(attribute, :missing) diff --git a/spec/active_interaction/base_spec.rb b/spec/active_interaction/base_spec.rb index 672dc56d..7c676e0b 100644 --- a/spec/active_interaction/base_spec.rb +++ b/spec/active_interaction/base_spec.rb @@ -240,4 +240,10 @@ def execute; end expect(described_class.i18n_scope).to eq :active_interaction end end + + describe '#i18n_scope' do + it 'returns the scope' do + expect(described_class.new.i18n_scope).to eq :active_interaction + end + end end