Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

private_field

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

private_field

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

private_field

Make Rails fields private to avoid those lazy temptations.

Background

It's easy to fall into the temptation of modifying model fields in random places (like your views), but this just makes the world worse. In most cases, it's a better idea to define a method within your model or a service class that's responsible for handling all of your data manipulation.

This gem enforces that rule by allowing for private field definitions.

Now you may be thinking, "That's already possible, just override the accessors." And you'd be right, but I'm lazy and think that writing:

private_field :id

is easier than writing:

field :id
private attr_accessor :id

Config

This is the best (or worst) part: there's no config because I wrote this for one specific use case and don't feel like writing config stuff that I won't use. Feel free to submit a pr if it doesn't suit your needs.

All this was written for Mongoid (I'm sorry), so it may take a bit of tweaking to make work for other ORMs.

How to

Just do private_field :field_name instead of field :field_name. If you're feeling feisty, you can do readable_field :field_name to make the reader public and the writer private.

MAKE SURE THAT YOU DO include Mongoid::Document OR WHATEVER ORM YOU'RE USING THIS ISN'T A REPLACEMENT FOR THAT CRAP.

FAQs

Package last updated on 17 Apr 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc