summaryrefslogtreecommitdiff
path: root/app/controllers/controller_extension/json_file.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/controller_extension/json_file.rb')
-rw-r--r--app/controllers/controller_extension/json_file.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/controllers/controller_extension/json_file.rb b/app/controllers/controller_extension/json_file.rb
new file mode 100644
index 0000000..6be919a
--- /dev/null
+++ b/app/controllers/controller_extension/json_file.rb
@@ -0,0 +1,23 @@
+module ControllerExtension::JsonFile
+ extend ActiveSupport::Concern
+ include ControllerExtension::Errors
+
+ protected
+
+ def send_file
+ if stale?(:last_modified => @file.mtime)
+ response.content_type = 'application/json'
+ render :text => @file.read
+ end
+ end
+
+ def fetch_file
+ if File.exists?(@filename)
+ @file = File.new(@filename)
+ else
+ not_found
+ end
+ end
+
+end
+