Sha256: e8d25f80d092badcd02ff12349a070670cee02376983a955d2fee42ea6c8b549

Contents?: true

Size: 806 Bytes

Versions: 7

Compression:

Stored size: 806 Bytes

Contents

# frozen_string_literal: true

module ActiveResource::Associations::Builder
  class Association #:nodoc:
    # providing a Class-Variable, which will have a different store of subclasses
    class_attribute :valid_options
    self.valid_options = [:class_name]

    # would identify subclasses of association
    class_attribute :macro

    attr_reader :model, :name, :options, :klass

    def self.build(model, name, options)
      new(model, name, options).build
    end

    def initialize(model, name, options)
      @model, @name, @options = model, name, options
    end

    def build
      validate_options
      model.create_reflection(self.class.macro, name, options)
    end

    private

      def validate_options
        options.assert_valid_keys(self.class.valid_options)
      end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ric-0.14.2 vendor/bundle/ruby/2.7.0/gems/activeresource-5.1.1/lib/active_resource/associations/builder/association.rb
ric-0.14.1 vendor/bundle/ruby/2.7.0/gems/activeresource-5.1.1/lib/active_resource/associations/builder/association.rb
ric-0.14.0 vendor/bundle/ruby/2.7.0/gems/activeresource-5.1.1/lib/active_resource/associations/builder/association.rb
activeresource-5.1.1 lib/active_resource/associations/builder/association.rb
ric-0.13.0 vendor/bundle/ruby/2.5.0/gems/activeresource-5.1.0/lib/active_resource/associations/builder/association.rb
ric-0.12.2 vendor/bundle/ruby/2.5.0/gems/activeresource-5.1.0/lib/active_resource/associations/builder/association.rb
activeresource-5.1.0 lib/active_resource/associations/builder/association.rb