Class: Wrappix::Templates::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wrappix/templates/client.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
# File 'lib/wrappix/templates/client.rb', line 6

def self.render(module_name, config)
  template = "    # frozen_string_literal: true\n\n    module \#{module_name}\n      class Client\n        def initialize(configuration = \#{module_name}.configuration)\n          @configuration = configuration\n        end\n\n        \#{resource_methods(module_name, config)}\n      end\n    end\n  RUBY\n  template.gsub(/^ +/, \"\")\nend\n"

.resource_methods(_module_name, config) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wrappix/templates/client.rb', line 23

def self.resource_methods(_module_name, config)
  resources = config["resources"] || {}

  resources.map do |name, _config|
    template = "      def \#{name}\n        @\#{name} ||= Resources::\#{name.capitalize}.new(self)\n      end\n    RUBY\n    template.gsub(/^ +/, \"\")\n  end.join(\"\\n\\n\")\nend\n".strip