Permalink
Browse files

Added dynamic settings to the Blog class

  • Loading branch information...
1 parent a496898 commit 5d6285f2b9a5ac2f52faf03b69a8870612d0b2ee Dan Watson committed Nov 2, 2011
Showing with 18 additions and 1 deletion.
  1. +2 −1 README.rdoc
  2. +11 −0 app/models/blog.rb
  3. +5 −0 tests/configuration_specs.rb
View
@@ -18,7 +18,7 @@ Runs the site on test data (bundler must be installed)
Deploy shout mouth to your server and browse to http://yourblog.com and follow the on screen instructions
===Rake Tasks
- rake check:all_urls (Send a get request to every url ShoutMouth has generated and will show a status code - sanity check that the blog is performing correctly
+ rake check:all_urls (Send a GET request to every url ShoutMouth has generated and will show a status code - sanity check that the blog is performing correctly
rake db:create (Create The Database)
@@ -84,6 +84,7 @@ Automated syntax highlighting will occur for any techincal posts by wrapping you
- our EasyRiderPlugin classes data method can return any object and will be passed down to the view
- a HAML layout file should be included in the view folder called easy_rider_plugin.haml. The view folder should reside under the easy rider directory
- by convention the variable name containing the returned data inside the view will be called easy_rider
+- you can also add global settings by calling Blog.your_setting = "your value" which can be retrieved using Blog.your_setting
-easy_rider.each do |easy_rider|
%li
View
@@ -211,6 +211,17 @@ def self.urls
urls
end
+ #----Now add or retrieve any key you like! ----#
+ def self.method_missing(method, *arguments, &block)
+ if method.to_s =~ /=/
+ #setter
+ return self.create_or_update method.to_s.gsub("=", ""), arguments.first
+ else
+ #getter
+ return configuration method.to_s
+ end
+ end
+
private
def self.configuration setting
entry = Blog.first(:key_name => setting)
@@ -84,6 +84,11 @@
it "should return the correct administrator email" do
Blog.administrator_email.should == "admin@yourserver.com"
end
+
+ it "should be able to create and retrieve a phantom key via method missing" do
+ Blog.whats_the_time_mr_wolf = "10:00pm"
+ Blog.whats_the_time_mr_wolf.should == "10:00pm"
+ end
it "setup should verify when not all the settings have been passed to the method that the method will return false" do
settings = {}

0 comments on commit 5d6285f

Please sign in to comment.