lib/about_page/configuration.rb in about_page-0.0.2 vs lib/about_page/configuration.rb in about_page-0.0.3

- old
+ new

@@ -48,12 +48,12 @@ def preflight request self.nodes.each { |key, profile| profile.preflight(request) } end - def ok? - self.nodes.select { |key, profile| profile.respond_to? :ok? }.all? { |key, profile| profile.ok? } + def valid? + self.nodes.select { |key, profile| profile.respond_to? :ok? }.all? { |key, profile| profile.valid? } end def nodes self.to_h.select { |key, profile| profile.is_a? AboutPage::Configuration::Node } end @@ -61,29 +61,38 @@ def set_headers! response self.nodes.each { |key, profile| profile.set_headers! response } end class Node + include ActiveModel::Validations + def preflight request + errors.clear + @request_expectations = request.params.select { |k,v| k =~ /^#{namespace}\./ } + end + def expects key + @request_expectations["#{namespace}.#{key}"] || self.options[:expects][key] if @request_expectations end + def messages + run_validations! + errors.to_a.uniq + end + def set_headers! response messages.each { |m| add_header(response, m) } end def add_header response, text response.headers['X-AboutPage-Warning'] ||= "" - response.headers['X-AboutPage-Warning'] += "#{text};" + response.headers['X-AboutPage-Warning'] += "#{self.class.name}: #{text};" end - def ok? - true - end - - def messages - [] + protected + def namespace + self.class.name.split("::").last.downcase end end end end