Sha256: aa4d3d2d6a0b17c20d60f0b3af165f44cd0ec5c8f5b47a4c64c5f1f7ed0fd5e3

Contents?: true

Size: 814 Bytes

Versions: 1

Compression:

Stored size: 814 Bytes

Contents

# frozen_string_literal: true

require 'active_support/concern'
require 'active_support/core_ext/array/wrap'
require_relative '../merge_includes'

module PlainModel
  module Querying
    module Includes
      extend ActiveSupport::Concern

      def initialize(*args)
        super(*args)
        values[:includes] = {}
      end

      included do
        self.chainable_methods += [:includes]
      end

      # Chain method
      # @param names [Array<Symbol,Hash>] - names of includes with optional tail hash for nested includes
      # @return new instance with applied changes
      def includes(*names)
        _within_new_instance do
          new_includes = ::PlainModel::MergeIncludes.new(values[:includes]).merge(names)
          values[:includes] = new_includes
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
plain_model-0.1.0 lib/plain_model/querying/includes.rb