Class: Lhj::ErbFormatter::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/lhj/command/yapi/formatters/service.rb

Overview

service

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Lhj::ErbFormatter::Base

Instance Method Details

#render(name = 'yapi') ⇒ Object

Parameters:

  • name (String) (defaults to: 'yapi')


10
11
12
13
# File 'lib/lhj/command/yapi/formatters/service.rb', line 10

def render(name = 'yapi')
  temp_str = template_str(name)
  render_template(temp_str)
end

#render_template(temp_str) ⇒ Object



15
16
17
# File 'lib/lhj/command/yapi/formatters/service.rb', line 15

def render_template(temp_str)
  template(temp_str).result(Context.new(@runner).fetch_binding)
end

#template(template_str) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/lhj/command/yapi/formatters/service.rb', line 23

def template(template_str)
  if RUBY_VERSION < '2.6'
    ERB.new(template_str, nil, '-')
  else
    ERB.new(template_str, trim_mode: '-')
  end
end

#template_str(name) ⇒ Object



19
20
21
# File 'lib/lhj/command/yapi/formatters/service.rb', line 19

def template_str(name)
  File.read(File.join(File.dirname(__FILE__), 'template', "#{name}.erb"))
end