Skip to content

Rails Application Configuration for Yield Main

License

Notifications You must be signed in to change notification settings

usertesting/racym

Repository files navigation

racym

Travis Coveralls github Code Climate maintainability

Rails Application Configuration for Yield Main (RACYM)

racym is used as a shortcut to rails configuration.

Installation

Add this line to your application's Gemfile:

gem "racym"

And then execute:

$ bundle install

Usage

Setting config values

In your config/application.rb add config settings:

module MyApp
  class Application < Rails::Application

  ...

  # Add a custom config setting here:
  config.foo = "bar"

  # Or a proc:
  config.biz = -> { DateTime.current }

Getting config values

From anywhere in your Rails application (controllers/helpers/views - should be available anywhere!)

puts racym(:foo)
# => "bar"

puts racym(:biz)
# => Wed, 02 Oct 2019 11:13:20 -0700

# ten minutes later:
puts racym(:biz)
# => Wed, 02 Oct 2019 11:23:20 -0700

Multilevel key/values

Setting:

module MyApp
  class Application < Rails::Application

  ...

  config.foo.username = "BAR"
  config.foo.password = "BIZ"

Getting:

puts racym(:foo, :username)
# => "BAR"

puts racym(:foo, :password)
# => "BIZ"

Testing

There's some convenient methods you can use to test code using racym:

  • racym_set
  • racym_undo!

For example, to test this simple method:

class Foo
  def self.hi
    "Hi #{racym :person_to_hi}"
  end
end
describe Foo do
  describe ".hi" do
    before  { racym_set :person_to_hi, "Dave" }
    specify { expect(Foo.hi).to eq "Hi Dave"  }
    after   { racym_undo! }
  end
end

License

MIT.

Library created by UserTesting

UserTesting

Contributing

  1. Fork it ( https://github.com/usertesting/racym/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request