Class: AboutPage::Configuration
- Inherits:
-
Object
- Object
- AboutPage::Configuration
show all
- Defined in:
- lib/about_page/configuration.rb
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Configuration.
33
34
35
|
# File 'lib/about_page/configuration.rb', line 33
def initialize hash = nil
@hash = hash || OpenStructWithHashAccess.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
45
46
47
|
# File 'lib/about_page/configuration.rb', line 45
def method_missing *args
@hash.send(*args)
end
|
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
29
30
31
|
# File 'lib/about_page/configuration.rb', line 29
def hash
@hash
end
|
Instance Method Details
#health_report ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/about_page/configuration.rb', line 69
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
|
#nodes ⇒ Object
57
58
59
|
# File 'lib/about_page/configuration.rb', line 57
def nodes
self.hash.to_h.select { |key, profile| profile.is_a? AboutPage::Configuration::Node }
end
|
#preflight(request) ⇒ Object
49
50
51
|
# File 'lib/about_page/configuration.rb', line 49
def preflight request
self.nodes.each { |key, profile| profile.preflight(request) }
end
|
#reject(&block) ⇒ Object
37
38
39
|
# File 'lib/about_page/configuration.rb', line 37
def reject &block
AboutPage::Configuration.new @hash.reject(&block)
end
|
#select(&block) ⇒ Object
41
42
43
|
# File 'lib/about_page/configuration.rb', line 41
def select &block
AboutPage::Configuration.new @hash.select(&block)
end
|
61
62
63
|
# File 'lib/about_page/configuration.rb', line 61
def response
self.nodes.each { |key, profile| profile. response }
end
|
#to_h ⇒ Object
65
66
67
|
# File 'lib/about_page/configuration.rb', line 65
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
|
#valid? ⇒ Boolean
53
54
55
|
# File 'lib/about_page/configuration.rb', line 53
def valid?
self.nodes.select { |key, profile| profile.respond_to? :ok? }.all? { |key, profile| profile.valid? }
end
|