Skip to content

Commit

Permalink
adding an i18n_scope instance method for improved readability
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronLasseigne committed Aug 13, 2013
1 parent 906fff7 commit fca41a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/active_interaction/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions spec/active_interaction/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fca41a5

Please sign in to comment.