Sha256: 65617e9aae0b417dcf2ad3a325b245015442d4f6ea3976afdf5ecda07f09fcb7

Contents?: true

Size: 932 Bytes

Versions: 2

Compression:

Stored size: 932 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 initial_values
        super.merge 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)
        dup.includes!(*names)
      end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plain_model-0.2.1 lib/plain_model/querying/includes.rb
plain_model-0.2.0 lib/plain_model/querying/includes.rb