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
# ...
endUsage
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
endYou 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:
$ bundleOr install it yourself as:
$ gem install super_currentInspiration
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.