
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
= HasCrudFor
Follow Law of Demeter in ActiveRecord models.
HasCrudFor is a small meta-programming snippet that adds find_, build_, create_, update_ and destroy_* methods intended as a better API for your associations.
== Example
class Blog < ActiveRecord::Base has_many :posts
extend HasCrudFor
has_crud_for :posts
has_crud_for :comments, :through => :posts
end
class Post has_many :comments end
blog.create_post(post_attributes) blog.build_post(post_attributes) blog.create_comment(post_id, comment_attributes) blog.create_comment!(post_id, comment_attributes) # will raise exception upon failed validation
== Benefits
easily delegate methods to other objects:
class User belongs_to :blog delegate :create_post, :to => :blog end
replace methods with own implementation
class Blog has_crud_for :posts
def create_post(attributes)
posts.create(attributes).tap { |post| post.publish! }
end
end
You can do whatever you need when creating new post, without hunting for blog.posts.create through your codebase! And without resorting to ActiveRecord callbacks.
less coupling - objects don't have to know about internal structure of other objects
easier to mock in tests
== Options
== FAQ
Do I need to use ActiveRecord? Or Rails?
No. But HasCrudFor depends on inflections from ActiveSupport. And that pulls i18n gem as well.
== License
This project rocks and uses MIT-LICENSE.
FAQs
Unknown package
We found that has_crud_for 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
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.