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

Version Path
mobility-0.8.13 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.11 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.10 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.9 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.8 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.7 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.6 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.5 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.4 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.3 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.2 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.1 lib/mobility/plugins/attribute_methods.rb
mobility-0.8.0 lib/mobility/plugins/attribute_methods.rb
mobility-0.7.6 lib/mobility/plugins/attribute_methods.rb
mobility-0.7.5 lib/mobility/plugins/attribute_methods.rb
mobility-0.7.4 lib/mobility/plugins/attribute_methods.rb
mobility-0.7.3 lib/mobility/plugins/attribute_methods.rb
mobility-0.7.2 lib/mobility/plugins/attribute_methods.rb
mobility-0.7.1 lib/mobility/plugins/attribute_methods.rb
mobility-0.7.0 lib/mobility/plugins/attribute_methods.rb