Sha256: af27eae86580f2b5bd780f7d8ebd34fb8dc3d7a7e5ac8f2514a0ad7fc587e851

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

module Quickery
  class QuickeryBuilder
    attr_reader :model
    attr_reader :depender_column_name
    attr_reader :dependee_column_name
    attr_reader :first_association_builder
    attr_reader :last_association_builder
    attr_reader :callbacks_builder

    def initialize(dependee_column_name:, last_association_builder:)
      @dependee_column_name = dependee_column_name
      @last_association_builder = last_association_builder
      @first_association_builder = last_association_builder._quickery_get_parent_builders.last
      @model = @first_association_builder.model
    end

    def ==(depender_column_name)
      @depender_column_name = depender_column_name

      @callbacks_builder = CallbacksBuilder.new(quickery_builder: self)

      define_quickery_builders_in_model_class unless @model.respond_to? :quickery_builders

      # include this to the list of quickery builders defined for this model
      @model.quickery_builders[depender_column_name] = self
    end

    private

    def define_quickery_builders_in_model_class
      # set default empty Hash if first time setting quickery_builders
      @model.class_eval do
        @quickery_builders = {}

        class << self
          attr_reader :quickery_builders
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
quickery-0.1.4 lib/quickery/quickery_builder.rb
quickery-0.1.3 lib/quickery/quickery_builder.rb
quickery-0.1.2 lib/quickery/quickery_builder.rb
quickery-0.1.1 lib/quickery/quickery_builder.rb
quickery-0.1.0 lib/quickery/quickery_builder.rb