lib/about_page/configuration.rb in about_page-0.1.1 vs lib/about_page/configuration.rb in about_page-0.2.0

- old
+ new

@@ -25,11 +25,11 @@ end end class Configuration attr_accessor :hash - delegate :to_xml, :to_h, :to_json, :to => :hash + delegate :to_xml, :to_json, :to_yaml, :to => :to_h delegate :each, :map, :to => :to_h def initialize hash = nil @hash = hash || OpenStructWithHashAccess.new end @@ -53,19 +53,35 @@ 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 } + self.hash.to_h.select { |key, profile| profile.is_a? AboutPage::Configuration::Node } end def set_headers! response self.nodes.each { |key, profile| profile.set_headers! response } end + def to_h + self.hash.to_h.inject({}) { |h,v| h[v[0]] = v[1].respond_to?(:to_h) ? v[1].to_h : v[1]; h } + end + + def health_report + self.nodes.collect do |key, profile| + if profile.class.validators.length > 0 + health = profile.valid? ? 'ok' : 'error' + { 'component' => key.to_s, 'status' => health, 'errors' => profile.errors.to_a } + else + nil + end + end.compact + end + class Node include ActiveModel::Validations + delegate :each_pair, :to_xml, :to_json, :to_yaml, :to => :to_h class << self attr_reader :partial def render_with partial @partial = partial @@ -82,9 +98,13 @@ end def messages run_validations! errors.to_a.uniq + end + + def to_h + nil end def set_headers! response messages.each { |m| add_header(response, m) } end