lib/frenetic/configuration.rb in frenetic-0.0.1 vs lib/frenetic/configuration.rb in frenetic-0.0.2.alpha1
- old
+ new
@@ -13,22 +13,19 @@
config[:username] = config[:api_key] if config[:api_key]
config[:headers] ||= {}
config[:request] ||= {}
- if config[:"content-type"]
- config[:headers][:accepts] = config[:"content-type"]
- else
- config[:headers][:accepts] = "application/hal+json"
- end
+ config[:headers][:accept] ||= "application/hal+json"
# Copy the config into this Configuration instance.
config.each { |k, v| self[k] = v }
super()
configure_user_agent
+ configure_cache
validate
end
private
@@ -41,15 +38,38 @@
else
self[:headers][:user_agent] = frenetic_ua
end
end
+ def configure_cache
+ if self[:cache]
+ ignore_headers = (self[:cache][:ignore_headers] || '').split(' ')
+
+ self[:cache][:ignore_headers] = (ignore_headers + %w[Set-Cookie X-Content-Digest]).uniq
+ end
+ end
+
def validate
unless self[:url]
raise ConfigurationError, "No API URL defined!"
end
+ if self[:cache]
+ raise( ConfigurationError, "No cache :metastore defined!" ) if self[:cache][:metastore].to_s == ""
+ raise( ConfigurationError, "No cache :entitystore defined!" ) if self[:cache][:entitystore].to_s == ""
+ raise( ConfigurationError, "Required cache header filters are missing!" ) if missing_required_headers?
+ end
end
+ def missing_required_headers?
+ return true if self[:cache][:ignore_headers].empty?
+
+ header_set = self[:cache][:ignore_headers]
+ custom_headers = header_set - %w[Set-Cookie X-Content-Digest]
+
+ header_set == custom_headers
+ end
+
+ # TODO: Is this even being used?
def config_file
config_path = File.join( 'config', 'frenetic.yml' )
if File.exists? config_path
config = YAML.load_file( config_path )
\ No newline at end of file