New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

super_current

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

super_current

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

SuperCurrent

SuperCurrent takes away the need to define a Current class and instead makes it available from anywhere in your app without having to define it.

This means that your test coverage will not suffer from ActiveSupport::CurrentAttributes!

You can define the class name of the Current class, so if you're already using Current for something else, you can use a different name.

# config/initializers/super_current.rb
SuperCurrent.config.current_class_name = 'SuperCurrent'

Then you can have your existing Current class be a subclass of SuperCurrent and it will still work with all the exciting features of SuperCurrent.

class Current < SuperCurrent
  # ...
end

Usage

Just think up a name for your attribute and assign it! It will be created on the Current class automatically.

Current.foo = 'bar'
Current.foo # => 'bar'

SuperCurrent also adds the ability to use [] and []= to access the attributes.

Current[:foo] = 'bar'
Current[:foo] # => 'bar'

Even something like Current[:foo][:bar] will work!

# No need to define Current[:hoge] beforehand!
Current[:hoge][:bar] = "hello"
Current[:hoge][:bar] # => 'bar'

This means that you no longer need to define the attributes on the Current class beforehand.

So if you have a class like this:

class Current < ActiveSupport::CurrentAttributes
  attribute :foo
  attribute :bar
  attribute :baz
  attribute :hoge
end

You can just delete it and enjoy the benefits of SuperCurrent! Test coverage might go up, too!

Installation

Add this line to your application's Gemfile:

gem "super_current"

And then execute:

$ bundle

Or install it yourself as:

$ gem install super_current

Inspiration

Inspired by: https://wiki.php.net/rfc/deprecate_dynamic_properties

Contributing

Feel free to contribute.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 29 Nov 2022

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