
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
# model
class Article < ActiveRecord::Base
# has columns: id, name, slug
has_slug
end
# creating new
item = Article.create!(name: 'First article')
item.slug # => 'first-article'
item.to_slug # => 'first-article'
# routes to the article
get "articles/:slug" => "articles#show", as: :article
# view
link_to 'My first article', article_path(item.to_slug) # => '/articles/first-article'
Add this line to your application's Gemfile:
gem 'slugable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install slugable
to_slug
, to_slug_was
, to_slug_will
class Item < ActiveRecord::Base
# columns :name, :slug
has_slug # default from: :name, to: :slug
end
# then in code
item = Item.create!(name: "my name is")
item.slug # => "my-name-is"
item.to_slug # => "my-name-is"
item.slug = "new-slug"
item.to_slug_was # => "my-name-is"
item.to_slug_will # => "new-slug"
item.to_slug # => "new-slug"
you can override defaults by passing hash
class Page < ActiveRecord::Base
# has columns: :id, :title, :seo_url
has_slug from: :title, to: :seo_url, formatter: lambda { |string| string.downcase }
end
# then in code
page = Page.create!(title: "NAME")
page.seo_url # => "name"
page.to_seo_url # => "name"
if model is a tree structure and you use ancestry gem, tree like structure will be generated
class Category < ActiveRecord::Base
# has columns: :id, :name, :slug
has_ancestry
has_slug
end
# then in code
root = Category.create!(name: "root", slug: "root")
root.slug # => "root"
root.to_slug # => ["root"]
child = Category.new(name: "child", slug: "child")
child.parent = root
child.save!
child.slug # => "child"
child.to_slug # => ["root", "child"]
branch = Category.create!(name: "branch", slug: "branch")
child.parent = branch
child.slug = "renamed"
child.to_slug_was # => ["root", "child"]
child.to_slug_will # => ["branch", "renamed"]
child.to_slug # => ["root", "child"]
child.save!
child.to_slug # => ["branch", "renamed"]
class Category < ActiveRecord::Base
# has columns: :id, :name, :slug
has_ancestry
has_slug tree_cache_storage: Rails.cache
end
You can set up default formatter and default tree_cache_storage in you initializer.
class MyFormatter
def self.call(string)
string.my_own_parameterize
end
end
Slugable.configure do |config|
config.formatter = MyFormatter
config.tree_cache_storage = Rails.cache
end
to_slug
, to_slug_was
and to_slug_will
methods are implemented by to_slug_builder. You can implement you own one and pass as configuration
# you own to slug builder
class StupidToSlug
def to_slug(record)
"to_slug_#{record.id}"
end
def to_slug_was(record)
"to_slug_was_#{record.id}"
end
def to_slug_will(record)
"to_slug_will_#{record.id}"
end
end
# model
class News < ActiveRecord::Base
# columns: :id, :name, :slug
has_slug to_slug_builder: StupidToSlug.new
end
# code
news = News.create!(name: 'whatever')
news.to_slug # => "to_slug_#{news.id}"
news.to_slug_was # => "to_slug_was_#{news.id}"
news.to_slug_will # => "to_slug_will_#{news.id}"
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that slugable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.