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, render_with, #set_headers!

Constructor Details

#initialize(sections = {}) ⇒ Environment

Returns a new instance of Environment.



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

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

#envObject



9
10
11
# File 'lib/about_page/environment.rb', line 9

def env
  ENV
end

#section_for(key, value) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/about_page/environment.rb', line 27

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

#to_hObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/about_page/environment.rb', line 13

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

     env.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