0.0
No release in over a year
SuperCurrent adds more fun to your Rails app by making it harder to predict!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 7.0.4
 Project Readme

SuperCurrent

A supercurrent is a superconducting current, that is, electric current which flows without dissipation in a superconductor.

Wikipedia

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.