Sha256: 1089b6cfcd1eaf69ccace4ffc8163c78315754c850dc0e54d2daa3f511e240dc

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module VestalVersions
  # Provides +versioned+ options conversion and cleanup.
  module Options
    def self.included(base) # :nodoc:
      base.class_eval do
        extend ClassMethods
      end
    end

    # Class methods that provide preparation of options passed to the +versioned+ method.
    module ClassMethods
      # The +prepare_versioned_options+ method has three purposes:
      # 1. Populate the provided options with default values where needed
      # 2. Prepare options for use with the +has_many+ association
      # 3. Save user-configurable options in a class-level variable
      #
      # Options are given priority in the following order:
      # 1. Those passed directly to the +versioned+ method
      # 2. Those specified in an initializer +configure+ block
      # 3. Default values specified in +prepare_versioned_options+
      #
      # The method is overridden in feature modules that require specific options outside the
      # standard +has_many+ associations.
      def prepare_versioned_options(options)
        options.symbolize_keys!
        options.reverse_merge!(Configuration.options)
        options.reverse_merge!(
          :class_name => 'VestalVersions::Version',
          :dependent => :delete_all
        )

        class_inheritable_accessor :vestal_versions_options
        self.vestal_versions_options = options.dup

        options.merge!(
          :as => :versioned,
          :extend => Array(options[:extend]).unshift(Versions)
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vestal_versions-1.0.1 lib/vestal_versions/options.rb
vestal_versions-1.0.0 lib/vestal_versions/options.rb