Created
February 12, 2009 06:26
-
-
Save Oshuma/62514 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Return the given key's value from the (CakePHP) database config | |
| # file. This will read through the config string looking for | |
| # 'key' => 'value' pairs in the PHP array. Then, it will | |
| # strip newlines, spaces, and substitute any quotes. | |
| # | |
| # I use this in a Rakefile I created to help ease the | |
| # pain of working with CakePHP. | |
| # | |
| # Usage: | |
| # File.open('database.php') do |f| | |
| # config = f.read | |
| # host = fetch_from(config, 'host') | |
| # password = fetch_from(config, 'password') | |
| # # ...etc... | |
| # end | |
| # | |
| # Yes, it is completely hackish. | |
| def fetch_from(config, key) | |
| value = config.grep(/'#{key}' => (\w*)/).first.split('=>')[1] | |
| value.gsub!(',', '').gsub!("'", '').chomp!.strip! | |
| value | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment