Sha256: fb4180fa2c5d44c5550eeaa812ab91ddbdaeec99806ffa05efd9d9409e265e1b

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'clowne/ext/string_constantize'

module Clowne
  module Declarations
    class IncludeAssociation # :nodoc: all
      using Clowne::Ext::StringConstantize

      attr_accessor :name, :scope, :options

      def initialize(name, scope = nil, **options)
        @name = name.to_sym
        @scope = scope
        @options = options
      end

      def compile(plan)
        plan.add_to(:association, name, self)
      end

      def clone_with
        return @clone_with if instance_variable_defined?(:@clone_with)
        @clone_with =
          case options[:clone_with]
          when String, Symbol
            options[:clone_with].to_s.constantize
          else
            options[:clone_with]
          end
      end

      def traits
        options[:traits]
      end
    end
  end
end

Clowne::Declarations.add :include_association, Clowne::Declarations::IncludeAssociation
Clowne::Declarations.add :include_associations do |*names|
  names.each do |name|
    declarations.push Clowne::Declarations::IncludeAssociation.new(name)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clowne-0.1.0 lib/clowne/declarations/include_association.rb
clowne-0.1.0.beta1 lib/clowne/declarations/include_association.rb