This is library that allows you to update a object values without any code changes in the project. Main condition is the target object is mutable.
Add this line to your application's Gemfile:
gem 'kansen', github: 'valikos/kansen'
And then execute:
$ bundle
The best thing start with the configuration. In configuration you can describe which attributes you want to change. You should set attribute name and describe note
and type
. note
it's value of attribute that you want change. type
it's format of new value.
Kansen
suports next types:
- string
- integer
- float
- constant
In practice this will be as follows:
first:
note: 'one'
type: 'string'
second:
note: 2
type: 'integer'
third:
note: 'Three'
type: 'constant'
You can change any type of a object. Main condition is the object responds to messages.
Kansen
can change hashes and objects. When you're working on modification of target you can use next modification strategies:
accessor
. This strategy similar how you useattr_accessor
in ruby.setter
. This strategy useinstance_variable_set(name, value)
to change instance variable.hash
. This strategy is actual for hashes only.
In the end it should look like this:
notes = Kansen.parse YAML.load_file(notes_cfg)
Kansen.modify TargetObject, with: notes, via: :accessor
Where notes
is special collection of changes and :accessor
is strategy.
Note: for hashes you should redefine hash like target_hash = Kansen.modify target_hash, with: notes, via: :hash
Add code below to the config/environments/development.rb
or any other environment file or to the config/application.rb
config.after_initialize do
notes = Kansen.parse YAML.load_file(notes_cfg)
Kansen.modify Rails.application.config, with: notes, via: :accessor
end
After that your target object should be changed with our notes.
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
- Fork it ( https://github.com/[my-github-username]/kansen/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request