Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix deprecation warning againts activesupport 3.2.

Signed-off-by: chatgris <jboyer@af83.com>
  • Loading branch information...
commit 5fcb3e08f26b62e73b759b37e04f0e5658f4d87a 1 parent 0fbe6e2
chatgris authored
View
43 lib/mongoid/translate.rb
@@ -21,32 +21,29 @@ module Translate
index 'translations.language'
end
- module InstanceMethods
- # Return list of existing languages
- #
- # @return [ Array ]
- #
- def languages
- translations.map(&:language)
- end
+ # Return list of existing languages
+ #
+ # @return [ Array ]
+ #
+ def languages
+ translations.map(&:language)
+ end
- # Return main translation object
- #
- # @return [ Document ]
- #
- def main_translation
- translations.where(language: main_language).one
- end
+ # Return main translation object
+ #
+ # @return [ Document ]
+ #
+ def main_translation
+ translations.where(language: main_language).one
+ end
- def method_missing(method, *args, &block)
- if self.languages.include?(method)
- translations.where(language: method).one
- else
- super(method, *args, &block)
- end
+ def method_missing(method, *args, &block)
+ if self.languages.include?(method)
+ translations.where(language: method).one
+ else
+ super(method, *args, &block)
end
-
- end # InstanceMethods
+ end
module ClassMethods
attr_accessor :translated_fields
View
26 lib/mongoid/translate/slug.rb
@@ -12,20 +12,18 @@ module Slug
index 'translations.slug'
end
- module InstanceMethods
- # Return slug.
- # Didn't want to mess with to_param.
- #
- # @example
- # document.to_slug
- #
- # @return [ String ]
- #
- def to_slug
- locale = languages.include?(I18n.locale) ? I18n.locale : main_language
- translations.where(language: locale).one.slug
- end
- end # InstanceMethods
+ # Return slug.
+ # Didn't want to mess with to_param.
+ #
+ # @example
+ # document.to_slug
+ #
+ # @return [ String ]
+ #
+ def to_slug
+ locale = languages.include?(I18n.locale) ? I18n.locale : main_language
+ translations.where(language: locale).one.slug
+ end
module ClassMethods
attr_accessor :slugged
View
18 lib/mongoid/translation.rb
@@ -19,15 +19,13 @@ module Translation
embedded_in name.underscore.to_sym, class_name: class_name
end
- module InstanceMethods
- # Check if current translation is main_translation.
- #
- # @return [ Boolean ]
- #
- def main_translation?
- parent = self.class.to_s.sub(/^.*::/, '').underscore
- self.send(parent).main_language == self.language
- end
- end # InstanceMethods
+ # Check if current translation is main_translation.
+ #
+ # @return [ Boolean ]
+ #
+ def main_translation?
+ parent = self.class.to_s.sub(/^.*::/, '').underscore
+ self.send(parent).main_language == self.language
+ end
end # Translation
end # Mongoid
View
62 lib/mongoid/translation/slug.rb
@@ -12,47 +12,45 @@ module Slug
after_validation :set_slug
end
- module InstanceMethods
- # Slug creation.
- #
- # @return [ Object ]
- #
- def set_slug
- if self.slug.blank? && slugged_field.present?
- if translation_parent_class.send(:by_slug, slugged).one
- self.slug = slugged_with_token
- else
- self.slug = slugged
- end
+ # Slug creation.
+ #
+ # @return [ Object ]
+ #
+ def set_slug
+ if self.slug.blank? && slugged_field.present?
+ if translation_parent_class.send(:by_slug, slugged).one
+ self.slug = slugged_with_token
+ else
+ self.slug = slugged
end
end
+ end
- private
+ private
- def slugged_field
- @slugged_field ||= self.send(translation_parent_class.slugged)
- end
+ def slugged_field
+ @slugged_field ||= self.send(translation_parent_class.slugged)
+ end
- def slugged
- @slugged ||= slugged_field.parameterize.blank? ? slugged_field : slugged_field.parameterize
- end
+ def slugged
+ @slugged ||= slugged_field.parameterize.blank? ? slugged_field : slugged_field.parameterize
+ end
- def slugged_with_token
- @slugged_with_token ||= [slugged, generate_token].join('-')
- end
+ def slugged_with_token
+ @slugged_with_token ||= [slugged, generate_token].join('-')
+ end
- def translation_parent_class
- self.class.to_s.sub('Translation::', '').constantize
- end
+ def translation_parent_class
+ self.class.to_s.sub('Translation::', '').constantize
+ end
- def translation_parent
- self.send(self.class.to_s.sub(/^.*::/, '').underscore)
- end
+ def translation_parent
+ self.send(self.class.to_s.sub(/^.*::/, '').underscore)
+ end
- def generate_token
- SecureRandom.base64(4).tr('+/=', '-_ ').strip.delete("\n")
- end
+ def generate_token
+ SecureRandom.base64(4).tr('+/=', '-_ ').strip.delete("\n")
+ end
end
- end # InstanceMethods
end # Translation
end # Mongoid
Please sign in to comment.
Something went wrong with that request. Please try again.