Socket
Book a DemoInstallSign in
Socket

sentient_model

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sentient_model

1.0.4
bundlerRubygems
Version published
Maintainers
1
Created
Source

sentient_model

sentient_model is simple piece of code trying to solve a common problem.

Imagine you are writing an authentication system for Ruby on Rails. Usually you would define a method called current_user in your ApplicationController and expose it to your views and so on (which is fine in most cases).

However, if you need current_user in locations where you can't easily expose the method, sentient_model is the perfect solution. Instead of manually exposing current_user, you would just rely on User.current. sentient_model's methods are globally accessible - therefore you don't have to worry about anything - it just works.

This Gem has been inspired by David Bock's sentient_user.

Usage

Define your models as usual and include the module SentientModel:

class YourModel
  include SentientModel
  # more code such as validations or associations
end

By including SentientModel, the following methods are added to your model:

YourModel#make_current # instance method - makes the callee object the sentient object
YourModel#current?     # instance method - true if the callee is the current sentient object or false otherwise
YourModel.current      # class method    - returns the sentient object or nil
YourModel.current=(m)  # class method    - sets the sentient object to the supplied argument (must be an instance of YourModel)
YourModel.has_current? # class method    - true if a sentient object defined or false otherwise 

Compatibility

  • MRI Ruby 1.8.7
  • MRI Ruby 1.9.2
  • JRuby 1.6

How to contribute?

  • Fork on GitHub.
  • Make sure, that all specs are still passing (run rake spec).
  • Send Pull Request.

Copyright ©2011 Christoph Schiessl. See LICENSE for details.

FAQs

Package last updated on 04 Jun 2011

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.