Commit 18540bd3 authored by John E. Vincent's avatar John E. Vincent

Initial stab at short=true

parent 3efdef0f
...@@ -62,10 +62,15 @@ module Noah ...@@ -62,10 +62,15 @@ module Noah
end end
class Configurations class Configurations
def self.all(options = {}) def self.all(options = {}, short=false)
short_keys = [:format, :created_at, :updated_at]
config_hash = Hash.new config_hash = Hash.new
options.empty? ? configs=Configuration.all.sort : configs=Configuration.find(options).sort options.empty? ? configs=Configuration.all.sort : configs=Configuration.find(options).sort
configs.each {|x| config_hash["#{x.name}"] = x.to_hash.reject {|k,v| k == :name} } if short == false
configs.each {|x| config_hash["#{x.name}"] = x.to_hash.reject {|k,v| k == :name} }
else
configs.each {|x| config_hash["#{x.name}"] = x.to_hash.select {|k,v| k if short_keys.include?(k)} }
end
config_hash config_hash
end end
end end
......
...@@ -14,15 +14,21 @@ class Noah::App ...@@ -14,15 +14,21 @@ class Noah::App
c = Noah::Configuration.find(:name => configname).first c = Noah::Configuration.find(:name => configname).first
(halt 404) if c.nil? (halt 404) if c.nil?
content_type content_type_mapping[c.format.to_sym] if content_type_mapping[c.format.to_sym] content_type content_type_mapping[c.format.to_sym] if content_type_mapping[c.format.to_sym]
#response.headers['Content-Disposition'] = "attachment; filename=#{configname}"
c.body c.body
end end
# GET all configurations # GET all configurations
get '/configurations/?' do get '/configurations/?' do
configs = Noah::Configurations.all.to_hash params[:short] ||= false
configs = Noah::Configurations.all({},params[:short])
(halt 404) if configs.size == 0 (halt 404) if configs.size == 0
configs.each do |config, values|
u = request.url.gsub(/(\/\?short=true|\?short=true)/,'/'+config)
values.merge!({:location=>u}) if params[:short]
end
configs.to_json configs.to_json
end end
# Add configuration object to a custom link hierarchy # Add configuration object to a custom link hierarchy
put '/configurations/:configname/link' do |configname| put '/configurations/:configname/link' do |configname|
required_params = ["link_name"] required_params = ["link_name"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment