Class: HaveAPI::GoClient::Generator
- Inherits:
-
Object
- Object
- HaveAPI::GoClient::Generator
- Defined in:
- lib/haveapi/go_client/generator.rb
Instance Attribute Summary collapse
-
#dst ⇒ String
readonly
Destination directory.
-
#module ⇒ String
readonly
Go module name.
-
#package ⇒ String
readonly
Go package name.
Instance Method Summary collapse
- #generate ⇒ Object
- #go_fmt ⇒ Object
-
#initialize(url, dst, opts) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(url, dst, opts) ⇒ Generator
Returns a new instance of Generator.
24 25 26 27 28 29 30 31 |
# File 'lib/haveapi/go_client/generator.rb', line 24 def initialize(url, dst, opts) @dst = dst @module = opts[:module] @package = opts[:package] conn = HaveAPI::Client::Communicator.new(url) @api = ApiVersion.new(conn.describe_api(opts[:version])) end |
Instance Attribute Details
#dst ⇒ String (readonly)
Destination directory
8 9 10 |
# File 'lib/haveapi/go_client/generator.rb', line 8 def dst @dst end |
#module ⇒ String (readonly)
Go module name
12 13 14 |
# File 'lib/haveapi/go_client/generator.rb', line 12 def module @module end |
#package ⇒ String (readonly)
Go package name
16 17 18 |
# File 'lib/haveapi/go_client/generator.rb', line 16 def package @package end |
Instance Method Details
#generate ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/haveapi/go_client/generator.rb', line 33 def generate FileUtils.mkpath(dst) if self.module ErbTemplate.render_to_if_changed( 'go.mod', { mod: self.module }, File.join(dst, 'go.mod') ) @dst = File.join(dst, package) FileUtils.mkpath(dst) end %w[client authentication request response types].each do |v| ErbTemplate.render_to_if_changed( "#{v}.go", { package:, api: }, File.join(dst, "#{v}.go") ) end api.resources.each { |r| r.generate(self) } api.auth_methods.each { |v| v.generate(self) } end |
#go_fmt ⇒ Object
62 63 64 65 66 |
# File 'lib/haveapi/go_client/generator.rb', line 62 def go_fmt return if system('go', 'fmt', chdir: dst) raise 'go fmt failed' end |