Sha256: a53228bf6fd1db526a682982b2fb0d3047e5b1d1674b743f173f44d01fca0f72

Contents?: true

Size: 1.09 KB

Versions: 21

Compression:

Stored size: 1.09 KB

Contents

module Virtus
  class Builder

    # Context used for building "included" and "extended" hooks
    #
    # @private
    class HookContext
      attr_reader :builder, :config, :attribute_method

      # @api private
      def initialize(builder, config)
        @builder, @config = builder, config
        initialize_attribute_method
      end

      # @api private
      def modules
        modules = builder.extensions
        modules << Model::Constructor    if constructor?
        modules << Model::MassAssignment if mass_assignment?
        modules
      end

      # @api private
      def constructor?
        config.constructor
      end

      # @api private
      def mass_assignment?
        config.mass_assignment
      end

      # @api private
      def finalize?
        config.finalize
      end

      # @api private
      def initialize_attribute_method
        method_options = builder.options

        @attribute_method = lambda do |name, type = nil, options = {}|
          super(name, type, method_options.merge(options))
        end
      end

    end # HookContext

  end # Builder
end # Virtus

Version data entries

21 entries across 19 versions & 5 rubygems

Version Path
virtus-1.0.0.rc1 lib/virtus/builder/hook_context.rb