Sha256: a6dc19354d1e86f9bef9b0b139298f6147c8be1463db14e9273c245a4948d17b

Contents?: true

Size: 840 Bytes

Versions: 6

Compression:

Stored size: 840 Bytes

Contents

module EntryDeletion
  include Chanko::Unit

  scope(:view) do
    function(:delete_link) do
      render "/delete_link", :entry => entry if entry.persisted?
    end
  end

  scope(:controller) do
    function(:destroy) do
      entry = Entry.find(params[:id])
      entry.unit.soft_delete
      redirect_to entries_path
    end

    function(:index) do
      @entries = Entry.unit.active
    end
  end

  models do
    expand(:Entry) do
      scope :active, lambda { where(:deleted_at => nil) }

      def soft_delete
        update_attributes(:deleted_at => Time.now)
      end

      class_methods do
        def gc_all_soft_deleted_users
          where.not(deleted_at: nil).delete_all
        end
      end
    end
  end

  helpers do
    def link_to_deletion(entry)
      link_to "Delete", entry, :method => :delete
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
chanko-2.3.0 spec/dummy/app/units/entry_deletion/entry_deletion.rb
chanko-2.2.1 spec/dummy/app/units/entry_deletion/entry_deletion.rb
chanko-2.2.0 spec/dummy/app/units/entry_deletion/entry_deletion.rb
chanko-2.1.1 spec/dummy/app/units/entry_deletion/entry_deletion.rb
chanko-2.1.0 spec/dummy/app/units/entry_deletion/entry_deletion.rb
chanko-2.0.8 spec/dummy/app/units/entry_deletion/entry_deletion.rb