Sha256: 2ef712900a0c98b69cc87ed912bf35f6424c3e31e6129c01f6ab657f6ce375f9

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

module Abstractor
  module Methods
    module Models
      module AbstractorAbstractionGroup
        def self.included(base)
          base.send :include, SoftDelete

          # Associations
          base.send :belongs_to, :abstractor_subject_group
          base.send :belongs_to, :about, polymorphic: true

          base.send :has_many, :abstractor_abstraction_group_members
          base.send :has_many, :abstractor_abstractions, :through => :abstractor_abstraction_group_members

          # base.send :attr_accessible, :abstractor_subject_group, :abstractor_subject_group_id, :deleted_at, :about, :about_type, :about_id

          # Hooks
          base.send :after_commit, :update_abstractor_abstraction_group_members, :on => :update, :if => Proc.new { |record| record.previous_changes.include?('deleted_at') }
        end

        ##
        # Determines if the group can be removed.
        #
        # @return [Boolean]
        def removable?
          abstractor_abstractions.map(&:abstractor_suggestions).flatten.empty?
        end

        private
          def update_abstractor_abstraction_group_members
            return unless deleted?
            abstractor_abstraction_group_members.each do |gm|
              gm.soft_delete!
              gm.abstractor_abstraction.soft_delete!
            end
          end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
abstractor-4.0.2 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-4.0.1 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-4.0.0 lib/abstractor/methods/models/abstractor_abstraction_group.rb