Sha256: 37336a6a90bd00d423670c4e72a4eb401e6f1b35e669b352067494e5bed2313c

Contents?: true

Size: 774 Bytes

Versions: 9

Compression:

Stored size: 774 Bytes

Contents

module AboutPage
  class Environment < AboutPage::Configuration::Node
    attr_accessor :sections
    delegate :each_pair, :to_json, :to_xml, :to => :to_h

    def initialize(sections = {})
      self.sections = sections
    end

    def to_h
      @request_env ||= begin
         h = Hash.new { |h,k| h[k] = {} }

         environment.each_pair do |key,value|
           section = section_for(key,value)
           unless section.nil?
             h[section][key] = value if value.is_a? String
           end
         end
         h
      end
    end

    def section_for(key, value)
      if sections.nil?
        nil
      else
        sections.keys.find do |k| 
          key =~ sections[k]
        end
      end
    end

    def environment
      ENV
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
about_page-0.1.1 lib/about_page/environment.rb
about_page-0.1.0 lib/about_page/environment.rb
about_page-0.0.7 lib/about_page/environment.rb
about_page-0.0.6 lib/about_page/environment.rb
about_page-0.0.5 lib/about_page/environment.rb
about_page-0.0.4 lib/about_page/environment.rb
about_page-0.0.3 lib/about_page/environment.rb
about_page-0.0.2 lib/about_page/environment.rb
about_page-0.0.1 lib/about_page/environment.rb