Sha256: 25688f5c759d51451910247ed490ea14952b670e9b8ffc0e07ff9a648fb0c3a6
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
require 'ostruct' module AboutPage class OpenStructWithHashAccess < OpenStruct delegate :each, :map, :to => :to_h def to_json(options = {}) Hash[*@table.map { |k, v| [k, (v.to_h if v.respond_to? :to_h || v) ] }.flatten ] end def to_xml(options = {}) @table end def to_h @table end end class Configuration attr_accessor :hash delegate :to_xml, :to_h, :to_json, :to => :hash delegate :each, :map, :to => :to_h def initialize @hash = OpenStructWithHashAccess.new end def method_missing *args @hash.send(*args) end 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? } end def nodes self.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 class Node def preflight request end def set_headers! response end def add_header response, text response.headers['X-AboutPage-Warning'] ||= "" response.headers['X-AboutPage-Warning'] += "#{text};" end def ok? true end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
about_page-0.0.1 | lib/about_page/configuration.rb |