Skip to content

Commit

Permalink
Replace Mobility::Translates module with simple def on extending class
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed Oct 25, 2020
1 parent 2628133 commit 3457c20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
15 changes: 3 additions & 12 deletions lib/mobility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class VersionNotSupportedError < ArgumentError; end

class << self
def extended(model_class)
model_class.extend Translates
def model_class.translates(*args, **options)
include Mobility.translations_class.new(*args, **options)
end
end

# Extends model with this class so that +include Mobility+ is equivalent to
Expand Down Expand Up @@ -177,17 +179,6 @@ def set_locale(locale)
end
end

module Translates
# Includes translated attributes on model class.
# @!method translates(*attributes, **options)
# @param [Array<String>] attributes
# @param [Hash] options
# @yield Yields to block with backend as context
def translates(*args, **options)
include Mobility.translations_class.new(*args, **options)
end
end

class InvalidLocale < I18n::InvalidLocale; end
class NotImplementedError < StandardError; end
end
6 changes: 3 additions & 3 deletions lib/mobility/translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module Mobility
Module containing translation accessor methods and other methods for accessing
translations.
Normally this class will be created by calling
{Mobility::Translates#translates}, which is a class method on any model that
extends {Mobility}, but it can also be used independent of that macro.
Normally this class will be created by calling +translates+ on the model class,
added when extending {Mobility}, but it can also be used independent of that
macro.
==Including Translations in a Class
Expand Down

0 comments on commit 3457c20

Please sign in to comment.