Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Added discard Ruby Gem (#10)
Browse files Browse the repository at this point in the history
* Added discard Ruby Gem
  • Loading branch information
igor-alexandrov authored Feb 13, 2023
1 parent 4b3998a commit 94e6361
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/curated/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ class Authentication < Base; end

class Authorization < Base; end

class ActiveRecordExtensions < Base; end

class Other < Base; end
end
30 changes: 30 additions & 0 deletions lib/curated/utils/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,34 @@ def demodulize(path)
path
end
end

def humanize(lower_case_and_underscored_word, capitalize: true, keep_id_suffix: false)
result = lower_case_and_underscored_word.to_s.dup

result.tr!('_', ' ')
result.lstrip!
unless keep_id_suffix
result.delete_suffix!(' id')
end

result.gsub!(/([a-z\d]+)/i) do |match|
match.downcase!
match
end

if capitalize
result.sub!(/\A\w/) do |match|
match.upcase!
match
end
end

result
end

def titleize(word, keep_id_suffix: false)
humanize(underscore(word), keep_id_suffix: keep_id_suffix).gsub(/\b(?<!\w['’`()])[a-z]/) do |match|
match.capitalize
end
end
end
13 changes: 13 additions & 0 deletions lib/ruby/discard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class Curated::Discard < Curated::RubyGem
package 'discard'
homepage 'https://github.com/jhawthorn/discard'
category Category::ActiveRecordExtensions

pros 'Allows to soft-delete `ActiveRecord` records.'
pros 'Does not pollute `ActiveRecord::Base` automatically. You can include `Discard::Model` into any model you want.'
pros 'Does not override any existing `ActiveRecord` methods.'

comment "We've used [acts_as_paranoid](https://github.com/ActsAsParanoid/acts_as_paranoid) and [paranoia](https://github.com/rubysherpas/paranoia) in the past. The both are great libraries, however they both override some `ActiveRecord` methods. Besides this you can run into issues when working with associations. Discard seems to be a better alternative."
end
2 changes: 1 addition & 1 deletion lib/templates/readme.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Contribution is welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details.

<% ruby_curates.each do |category, curates| %>
## <%= category.name %>
## <%= Utils.titleize(category.name) %>

<% curates.each do |curated| %>
### [¶ <%= curated.name %>](#<%= curated.name %>)
Expand Down

0 comments on commit 94e6361

Please sign in to comment.