Class: Wrappix::Templates::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/wrappix/templates/object.rb

Class Method Summary collapse

Class Method Details

.render(module_name, _config) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wrappix/templates/object.rb', line 6

def self.render(module_name, _config)
  "    # frozen_string_literal: true\n\n    require \"ostruct\"\n\n    module \#{module_name}\n      class Object < OpenStruct\n        def initialize(attributes)\n          super(to_ostruct(attributes))\n        end\n\n        def to_ostruct(obj)\n          if obj.is_a?(Hash)\n            OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })\n          elsif obj.is_a?(Array)\n            obj.map { |o| to_ostruct(o) }\n          else\n            obj\n          end\n        end\n      end\n    end\n  RUBY\nend\n"