Sha256: f247b256f953686be0b2241931fab9ed4de308f1d927a7c6f10f7af1b0be5a6f

Contents?: true

Size: 560 Bytes

Versions: 33

Compression:

Stored size: 560 Bytes

Contents

module Mongoid
  module Fields
    module LocalizedDefaults
      def create_accessors(name, meth, options = {})
        super

        if options[:localize]
          field = fields[name]

          define_method meth do |*args|
            result = super(*args)
            return result unless result.nil?

            default_name = field.send(:default_name)
            return send(default_name) if respond_to?(default_name)

            field.default_val
          end
        end
      end
    end

    ClassMethods.prepend(LocalizedDefaults)
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
workarea-core-3.5.27 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.26 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.45 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.25 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.23 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.44 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.22 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.43 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.21 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.42 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.20 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.41 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.19 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.40 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.18 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.39 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.17 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.38 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.5.16 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
workarea-core-3.4.37 lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb