Class: Extension::Models::ServerConfig::Base
- Inherits:
-
Object
- Object
- Extension::Models::ServerConfig::Base
show all
- Defined in:
- lib/project_types/extension/models/server_config/base.rb
Instance Method Summary
collapse
Instance Method Details
#to_h ⇒ Object
7
8
9
|
# File 'lib/project_types/extension/models/server_config/base.rb', line 7
def to_h
to_hash
end
|
#to_hash ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/project_types/extension/models/server_config/base.rb', line 11
def to_hash
is_hashable = ->(obj) { obj.respond_to?(:to_hash) }
is_collection_of_hashables = ->(obj) { obj.is_a?(Enumerable) && obj.all?(&is_hashable) }
self.class.properties.each.reduce({}) do |data, (_, property)|
data.merge(property.name.to_s => send(property.reader).yield_self do |value|
case value
when is_collection_of_hashables
value.map { |element| element.to_hash.transform_keys(&:to_s) }
when is_hashable
value.to_hash.transform_keys(&:to_s)
else
value
end
end)
end
end
|