Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I'm having problem to setup a nice approach to config login credentials
- # for different sites. I have different classes/strategies to login on
- # sites and I wanna config them at the same place (seems wise).
- # The sites can have different variables needed for the login. Some needs
- # username/password and some uses api-keys only.
- # This is the first approach but I don't like it. Any suggestions?
- module Foobar
- # Helper method from active support to set module attributes
- mattr_accessor :credentials
- @@credentials = {}
- def self.setup
- yield self
- end
- end
- Foobar.setup do |config|
- config.credentials = {
- :my_site = {
- :username => 'foo',
- :password => 'bar'
- }
- :my_other_site = {
- :user_id => '123',
- :api_key => 'abc123'
- }
- }
- end
- class MySite
- def credentials
- Foobar.credentials[:my_site]
- end
- end
- puts MySite.new.credentials
Add Comment
Please, Sign In to add comment