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

JackDanger-immutable_attributes

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

JackDanger-immutable_attributes

  • 1.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ImmutableAttributes

When you want to prevent certain attributes from being changed once set you can declare them as immutable:

class MyModel < ActiveRecord::Base attr_immutable :permalink, :param_identifier end

When MyModel.find(:first).permalink = 'anything' is called it will raise an ImmutableAttributeError MyModel.new.permalink = 'works!' will properly set the value because the record is unsaved.

If you'd only like this to happen for certain conditions, and want to handle other attribute-writers, too (like update_attribute), you can use the validation.

validates_immutable :permalink

Configuration options for the validation:

  • :message - A customer error message (default is: "can't be changed")
  • :if - Specifies a method, proc, or string to call to determine if the validation should occure (e.g., :if => :allow_validation or :if => Proc.new{|user| user.signup_step > 2}. The method, proc or string should return or evaluate to a true or false value.
  • :unless - Specifies a method, proc, or string to call to determine if the validation should not occure (e.g., :unless => :skip_validation or :unless => Proc.new{|user| user.signup_step <= 2}. The method, proc or string should return or evaluate to a true or false value.

Created by Jack Danger Canty @ http://6brand.com Released under the same licence as Rails (MIT)

FAQs

Package last updated on 11 Aug 2014

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