Sha256: 9211945cedd53885aeb93f24196a65b90076f177ec954b010e2214a9f7038aa6

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 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

        # Instance Methods
        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

10 entries across 10 versions & 1 rubygems

Version Path
abstractor-1.0.17 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.16 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.15 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.14 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.13 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.12 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.11 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.10 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.9 lib/abstractor/methods/models/abstractor_abstraction_group.rb
abstractor-1.0.8 lib/abstractor/methods/models/abstractor_abstraction_group.rb