Sha256: 4fccee7a8a1d992892afa703d0a71ccb85350e46fa32e59ebaeeb8a3e54871b0
Contents?: true
Size: 1.46 KB
Versions: 34
Compression:
Stored size: 1.46 KB
Contents
module Mobility module Plugins =begin Adds translated attribute names and values to the hash returned by #attributes. Also adds a method #translated_attributes with names and values of translated attributes only. @note Adding translated attributes to +attributes+ can have unexpected consequences, since these attributes do not have corresponding columns in the model table. Using this plugin may lead to conflicts with other gems. =end module AttributeMethods class << self # Applies attribute_methods plugin for a given option value. # @param [Attributes] attributes # @param [Boolean] option Value of option # @raise [ArgumentError] if model class does not support dirty tracking def apply(attributes, option) if option include_attribute_methods_module(attributes.model_class, *attributes.names) end end private def include_attribute_methods_module(model_class, *attribute_names) module_builder = if Loaded::ActiveRecord && model_class.ancestors.include?(::ActiveRecord::AttributeMethods) require "mobility/plugins/active_record/attribute_methods" Plugins::ActiveRecord::AttributeMethods else raise ArgumentError, "#{model_class} does not support AttributeMethods plugin." end model_class.include module_builder.new(*attribute_names) end end end end end
Version data entries
34 entries across 34 versions & 1 rubygems