Class: AboutPage::Environment

Inherits:
Configuration::Node show all
Defined in:
lib/about_page/environment.rb

Direct Known Subclasses

RequestEnvironment

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Configuration::Node

#add_header, #expects, #messages, #preflight, #set_headers!

Constructor Details

#initialize(sections = {}) ⇒ Environment

Returns a new instance of Environment.



6
7
8
# File 'lib/about_page/environment.rb', line 6

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

Instance Attribute Details

#sectionsObject

Returns the value of attribute sections.



3
4
5
# File 'lib/about_page/environment.rb', line 3

def sections
  @sections
end

Instance Method Details

#environmentObject



34
35
36
# File 'lib/about_page/environment.rb', line 34

def environment
  ENV
end

#section_for(key, value) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/about_page/environment.rb', line 24

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

#to_hObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/about_page/environment.rb', line 10

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