Sha256: e212be33d9f4c63e1e83cf44600c84880ea5c935c212be5739fbcbb50f3122d4

Contents?: true

Size: 674 Bytes

Versions: 6

Compression:

Stored size: 674 Bytes

Contents

module Mongoid # :nodoc:
  module Relations #:nodoc:

    module Builders
      extend ActiveSupport::Concern

      module ClassMethods #:nodoc:

        def builder_with_custom_fields(name, metadata)
          tap do
            define_method("build_#{name}") do |*args|
              if self.custom_fields?(metadata.name)
                metadata = self.clone_metadata_for_custom_fields(metadata)
              end

              document = Factory.build(metadata.klass, args.first || {})
              send("#{name}=", document, :binding => true)
            end
          end
        end

        alias_method_chain :builder, :custom_fields

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
custom_fields-1.0.0.beta.20 lib/custom_fields/extensions/mongoid/relations/builders.rb
custom_fields-1.0.0.beta.19 lib/custom_fields/extensions/mongoid/relations/builders.rb
custom_fields-1.0.0.beta.18 lib/custom_fields/extensions/mongoid/relations/builders.rb
custom_fields-1.0.0.beta.17 lib/custom_fields/extensions/mongoid/relations/builders.rb
custom_fields-1.0.0.beta.16 lib/custom_fields/extensions/mongoid/relations/builders.rb
custom_fields-1.0.0.beta.15 lib/custom_fields/extensions/mongoid/relations/builders.rb